[Pkg-javascript-commits] [uglifyjs] 215/228: fix a couple of bugs in `global_defs` (#1802)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:31 UTC 2017


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

js pushed a commit to branch master
in repository uglifyjs.

commit 0479ff0c54e8eea90ff5471bd9f77cb7f2e355c3
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Apr 8 16:46:25 2017 +0800

    fix a couple of bugs in `global_defs` (#1802)
    
    - `optimize()` substituted expression
    - compute nested property string correctly
    
    fixes #1801
    
    Miscellaneous
    - reset optimisation flags on all node types
---
 lib/compress.js              | 12 +++++-------
 test/compress/global_defs.js | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index de0ff38..5b405ec 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -260,10 +260,8 @@ merge(Compressor.prototype, {
             }
         });
         var tw = new TreeWalker(function(node, descend){
-            if (!(node instanceof AST_Directive || node instanceof AST_Constant)) {
-                node._squeezed = false;
-                node._optimized = false;
-            }
+            node._squeezed = false;
+            node._optimized = false;
             if (reduce_vars) {
                 if (node instanceof AST_Toplevel) node.globals.each(reset_def);
                 if (node instanceof AST_Scope) node.variables.each(reset_def);
@@ -1346,7 +1344,7 @@ merge(Compressor.prototype, {
         }
         def(AST_Node, noop);
         def(AST_Dot, function(compressor, suffix){
-            return this.expression._find_defs(compressor, suffix + "." + this.property);
+            return this.expression._find_defs(compressor, "." + this.property + suffix);
         });
         def(AST_SymbolRef, function(compressor, suffix){
             if (!this.global()) return;
@@ -3582,7 +3580,7 @@ merge(Compressor.prototype, {
     OPT(AST_SymbolRef, function(self, compressor){
         var def = self.resolve_defines(compressor);
         if (def) {
-            return def;
+            return def.optimize(compressor);
         }
         // testing against !self.scope.uses_with first is an optimization
         if (compressor.option("screw_ie8")
@@ -3932,7 +3930,7 @@ merge(Compressor.prototype, {
     OPT(AST_Dot, function(self, compressor){
         var def = self.resolve_defines(compressor);
         if (def) {
-            return def;
+            return def.optimize(compressor);
         }
         var prop = self.property;
         if (RESERVED_WORDS(prop) && !compressor.option("screw_ie8")) {
diff --git a/test/compress/global_defs.js b/test/compress/global_defs.js
index a69d031..f1ba8f3 100644
--- a/test/compress/global_defs.js
+++ b/test/compress/global_defs.js
@@ -145,3 +145,18 @@ mixed: {
         'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:129,8]',
     ]
 }
+
+issue_1801: {
+    options = {
+        booleans: true,
+        global_defs: {
+            "CONFIG.FOO.BAR": true,
+        },
+    }
+    input: {
+        console.log(CONFIG.FOO.BAR);
+    }
+    expect: {
+        console.log(!0);
+    }
+}

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