[Pkg-javascript-commits] [uglifyjs] 111/228: fix `hoist_vars` on `reduce_vars` (#1607)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:22 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 a80b228d8be37eb6585bca01c6fb5468db5bea42
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Mar 16 12:03:30 2017 +0800

    fix `hoist_vars` on `reduce_vars` (#1607)
    
    `hoist_vars` converts variable declarations into plain assignments, which then confuses `reduce_vars`
    
    fixes #1606
---
 lib/compress.js              |  6 ++++--
 test/compress/reduce_vars.js | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index b3004fb..49b618e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1986,7 +1986,7 @@ merge(Compressor.prototype, {
                                 vars.set(def.name.name, def);
                                 ++vars_found;
                             });
-                            var seq = node.to_assignments();
+                            var seq = node.to_assignments(compressor);
                             var p = tt.parent();
                             if (p instanceof AST_ForIn && p.init === node) {
                                 if (seq == null) {
@@ -2579,7 +2579,8 @@ merge(Compressor.prototype, {
         this.definitions.forEach(function(def){ def.value = null });
     });
 
-    AST_Definitions.DEFMETHOD("to_assignments", function(){
+    AST_Definitions.DEFMETHOD("to_assignments", function(compressor){
+        var reduce_vars = compressor.option("reduce_vars");
         var assignments = this.definitions.reduce(function(a, def){
             if (def.value) {
                 var name = make_node(AST_SymbolRef, def.name, def.name);
@@ -2588,6 +2589,7 @@ merge(Compressor.prototype, {
                     left     : name,
                     right    : def.value
                 }));
+                if (reduce_vars) name.definition().fixed = false;
             }
             return a;
         }, []);
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index a5ab59f..bc6c72d 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1327,3 +1327,27 @@ issue_1595_4: {
         })(3, 4, 5);
     }
 }
+
+issue_1606: {
+    options = {
+        evaluate: true,
+        hoist_vars: true,
+        reduce_vars: true,
+    }
+    input: {
+        function f() {
+            var a;
+            function g(){};
+            var b = 2;
+            x(b);
+        }
+    }
+    expect: {
+        function f() {
+            var a, b;
+            function g(){};
+            b = 2;
+            x(b);
+        }
+    }
+}

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