[Pkg-javascript-commits] [uglifyjs] 219/491: trap invalid use of reserved words (#2338)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:37 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 2dcc552ce0404db3cdabb1dd02c8fff5c8dfc4f9
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Oct 1 02:10:41 2017 +0800

    trap invalid use of reserved words (#2338)
    
    fixes #2337
---
 lib/parse.js         | 2 ++
 test/mocha/minify.js | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/lib/parse.js b/lib/parse.js
index e2dd04b..099fc49 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 fc7332f..aed8f91 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};';

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list