[Pkg-javascript-commits] [uglifyjs] 165/491: parse `@global_defs` as expressions (#2169)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:32 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 1e4de2e6d31a50dafee4a4e4d020f22691d22292
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Jun 27 10:31:19 2017 +0800

    parse `@global_defs` as expressions (#2169)
    
    - let parser rejects non-conformant input
    - eliminate need for extraneous parenthesis
---
 lib/compress.js              |  9 +++------
 test/compress/global_defs.js | 21 +++++++++++++++++++++
 test/mocha/minify.js         |  2 +-
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index dc82db0..0f00d09 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -92,12 +92,9 @@ function Compressor(options, false_by_default) {
     var global_defs = this.options["global_defs"];
     if (typeof global_defs == "object") for (var key in global_defs) {
         if (/^@/.test(key) && HOP(global_defs, key)) {
-            var ast = parse(global_defs[key]);
-            if (ast.body.length == 1 && ast.body[0] instanceof AST_SimpleStatement) {
-                global_defs[key.slice(1)] = ast.body[0].body;
-            } else throw new Error(string_template("Can't handle expression: {value}", {
-                value: global_defs[key]
-            }));
+            global_defs[key.slice(1)] = parse(global_defs[key], {
+                expression: true
+            });
         }
     }
     var pure_funcs = this.options["pure_funcs"];
diff --git a/test/compress/global_defs.js b/test/compress/global_defs.js
index d784d33..74147de 100644
--- a/test/compress/global_defs.js
+++ b/test/compress/global_defs.js
@@ -174,3 +174,24 @@ issue_1986: {
         console.log(42);
     }
 }
+
+issue_2167: {
+    options = {
+        conditionals: true,
+        dead_code: true,
+        evaluate: true,
+        global_defs: {
+            "@isDevMode": "function(){}",
+        },
+        side_effects: true,
+    }
+    input: {
+        if (isDevMode()) {
+            greetOverlord();
+        }
+        doWork();
+    }
+    expect: {
+        doWork();
+    }
+}
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index 638e79f..b4722ce 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -212,7 +212,7 @@ describe("minify", function() {
             });
             var err = result.error;
             assert.ok(err instanceof Error);
-            assert.strictEqual(err.stack.split(/\n/)[0], "Error: Can't handle expression: debugger");
+            assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: keyword (debugger)");
         });
         it("should skip inherited properties", function() {
             var foo = Object.create({ skip: this });

-- 
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