fix corner case in `reduce_vars` (#3151)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 25 May 2018 21:45:44 +0000 (05:45 +0800)
committerGitHub <noreply@github.com>
Fri, 25 May 2018 21:45:44 +0000 (05:45 +0800)
lib/compress.js
test/compress/reduce_vars.js

index ebb2d40..1832f7a 100644 (file)
@@ -388,7 +388,6 @@ merge(Compressor.prototype, {
                         tw.defun_ids[def.id] = false;
                     }
                 });
-                return true;
             };
         }
 
@@ -565,7 +564,7 @@ merge(Compressor.prototype, {
             return true;
         });
         def(AST_Call, function(tw, descend) {
-            if (tw.find_parent(AST_Scope).may_call_this()) return;
+            tw.find_parent(AST_Scope).may_call_this();
             var exp = this.expression;
             if (!(exp instanceof AST_SymbolRef)) return;
             var def = exp.definition();
index 626893f..0af80da 100644 (file)
@@ -6367,3 +6367,39 @@ issue_3140_4: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3140_5: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        var n = 1, c = 0;
+        (function(a) {
+            var b = function() {
+                this;
+                n-- && h();
+            }();
+            function h() {
+                b && c++;
+            }
+            h(b = 1);
+        })();
+        console.log(c);
+    }
+    expect: {
+        var n = 1, c = 0;
+        (function(a) {
+            var b = function() {
+                this;
+                n-- && h();
+            }();
+            function h() {
+                b && c++;
+            }
+            h(b = 1);
+        })();
+        console.log(c);
+    }
+    expect_stdout: "1"
+}