Don't use 2 characters for surrogates in identifiers because there is
support for the \u{} syntax when escaped identifiers were introduced.
Also catch eof errors while reading identifier names
Introduce ascii_identifiers:
By setting ascii_identifiers to undefined (default value),
ascii_identifiers will print identifiers using the same setting as
ascii_only within the limits of the ecmascript 6 grammar.
ascii_identifiers accept true and false, allowing identifiers to be
printed under different settings than strings with the ascii_only setting.
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
var assert = require("assert");
|
|
var uglify = require("../../");
|
|
|
|
describe("EOF", function() {
|
|
it("Should test code for at least throwing syntax error when incomplete", function() {
|
|
var error = function(e) {
|
|
return e instanceof uglify.JS_Parse_Error &&
|
|
/^SyntaxError: /.test(e.message);
|
|
}
|
|
var parse = function(test) {
|
|
return function() {
|
|
uglify.parse(test);
|
|
}
|
|
}
|
|
// Chops off 1 char at a time until limit or start of string is reached
|
|
// The passed code must still be valid when unchopped
|
|
var test_eol = function(input, chopLimit) {
|
|
if (chopLimit === undefined) {
|
|
chopLimit = input.length - 1;
|
|
}
|
|
|
|
assert.doesNotThrow(parse(input), "Expected valid code for \n" + input);
|
|
|
|
for (var i = input.length - 1; chopLimit > 0; chopLimit--, i--) {
|
|
var code = input.substr(0, i);
|
|
assert.throws(parse(code), error, code);
|
|
}
|
|
}
|
|
|
|
test_eol("var \\u1234", 7); // Incomplete identifier
|
|
test_eol("'Incomplete string'");
|
|
test_eol("/Unterminated regex/");
|
|
test_eol("` Unterminated template string`");
|
|
test_eol("/* Unfinishing multiline comment */");
|
|
});
|
|
});
|