diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-10-01 02:10:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-01 02:10:41 +0800 |
commit | 2dcc552ce0404db3cdabb1dd02c8fff5c8dfc4f9 (patch) | |
tree | 28b686ffbbfa0b47f257b1457a84203684dbec49 | |
parent | 55387e8fd022a64b349487ca3a66c3d9c5de1907 (diff) | |
download | tracifyjs-2dcc552ce0404db3cdabb1dd02c8fff5c8dfc4f9.tar.gz tracifyjs-2dcc552ce0404db3cdabb1dd02c8fff5c8dfc4f9.zip |
trap invalid use of reserved words (#2338)
fixes #2337
-rw-r--r-- | lib/parse.js | 2 | ||||
-rw-r--r-- | test/mocha/minify.js | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/parse.js b/lib/parse.js index e2dd04b6..099fc49a 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1054,6 +1054,8 @@ function parse($TEXT, options) { var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null; if (in_statement && !name) unexpected(); + if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration)) + unexpected(prev()); expect("("); var argnames = []; for (var first = true; !is("punc", ")");) { diff --git a/test/mocha/minify.js b/test/mocha/minify.js index fc7332fb..aed8f915 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -73,6 +73,12 @@ describe("minify", function() { assert.strictEqual(run_code(compressed), run_code(original)); }); + it("should not parse invalid use of reserved words", function() { + assert.strictEqual(Uglify.minify("function enum(){}").error, undefined); + assert.strictEqual(Uglify.minify("function static(){}").error, undefined); + assert.strictEqual(Uglify.minify("function this(){}").error.message, "Unexpected token: name (this)"); + }); + describe("keep_quoted_props", function() { it("Should preserve quotes in object literals", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; |