fix corner case in `collapse_vars` (#3563)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 1 Nov 2019 14:38:19 +0000 (22:38 +0800)
committerGitHub <noreply@github.com>
Fri, 1 Nov 2019 14:38:19 +0000 (22:38 +0800)
fixes #3562

lib/compress.js
test/compress/collapse_vars.js

index 0321a53..e3532fe 100644 (file)
@@ -1671,7 +1671,7 @@ merge(Compressor.prototype, {
             function symbol_in_lvalues(sym, parent) {
                 var lvalue = lvalues[sym.name];
                 if (!lvalue) return;
-                if (lvalue !== lhs) return !(parent instanceof AST_Call && parent.expression === sym);
+                if (lvalue !== lhs) return true;
                 scan_rhs = false;
             }
 
index 858d3d4..31978c2 100644 (file)
@@ -6348,3 +6348,42 @@ issue_3526_2: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3562: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        sequences: true,
+    }
+    input: {
+        function f(a) {
+            console.log("PASS", a);
+        }
+        function g(b) {
+            console.log("FAIL", b);
+        }
+        var h;
+        var c;
+        if (console) {
+            h = f;
+            c = "PASS";
+        } else {
+            h = g;
+            c = "FAIL";
+        }
+        h(c);
+    }
+    expect: {
+        function f(a) {
+            console.log("PASS", a);
+        }
+        function g(b) {
+            console.log("FAIL", b);
+        }
+        var h;
+        var c;
+        c = console ? (h = f, "PASS") : (h = g, "FAIL"),
+        h(c);
+    }
+    expect_stdout: "PASS PASS"
+}