This commit is contained in:
Anthony Van de Gejuchte 2016-06-29 10:46:12 +00:00 committed by GitHub
commit 080e9b42a2
2 changed files with 28 additions and 1 deletions

View File

@ -261,7 +261,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
var text = S.text; var text = S.text;
for (var i = S.pos, n = S.text.length; i < n; ++i) { for (var i = S.pos, n = S.text.length; i < n; ++i) {
var ch = text[i]; var ch = text[i];
if (ch == '\n' || ch == '\r') if ("\n\r\u2028\u2029".indexOf(ch) >= 0)
return i; return i;
} }
return -1; return -1;

27
test/mocha/comment.js Normal file
View File

@ -0,0 +1,27 @@
var assert = require("assert");
var uglify = require("../../");
describe("Comment", function() {
it("Should recognize eol of single line comments", function() {
var tests = [
"//Some comment\n>",
"//Some comment\r>",
"//Some comment\r\n>",
"//Some comment\u2028>",
"//Some comment\u2029>"
];
var fail = function(e) {
return e instanceof uglify.JS_Parse_Error &&
e.message === "SyntaxError: Unexpected token: operator (>)" &&
e.line === 2 &&
e.col === 0;
}
for (var i = 0; i < tests.length; i++) {
assert.throws(function() {
uglify.parse(tests[i], {fromString: true})
}, fail, tests[i]);
}
});
});