fix corner case in `collapse_vars` (#3978)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 9 Jun 2020 11:07:20 +0000 (12:07 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2020 11:07:20 +0000 (19:07 +0800)
fixes #3976

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

index 907c9e7..cfbafbe 100644 (file)
@@ -1468,7 +1468,7 @@ merge(Compressor.prototype, {
                 if (node instanceof AST_Call) {
                     var fn = node.expression;
                     if (fn instanceof AST_SymbolRef) {
-                        if (fn.definition().recursive_refs > 0) return true;
+                        if (recursive_ref(compressor, fn.definition())) return true;
                         fn = fn.fixed_value();
                     }
                     if (!(fn instanceof AST_Lambda)) return true;
index 71c3a14..dcc95b2 100644 (file)
@@ -8242,3 +8242,41 @@ issue_3971: {
     }
     expect_stdout: "1"
 }
+
+issue_3976: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        evaluate: true,
+        inline: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        function f() {
+            console.log("FAIL");
+        }
+        (function(a) {
+            function g() {
+                if ((a = 0) || f(0)) {
+                    f();
+                } else {
+                    f();
+                }
+                if (h(a = 0));
+            }
+            function h() {
+                g();
+            }
+        })();
+        console.log("PASS");
+    }
+    expect: {
+        function f() {
+            console.log("FAIL");
+        }
+        void 0;
+        console.log("PASS");
+    }
+    expect_stdout: "PASS"
+}