fix corner case in `collapse_vars` (#3745)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 6 Mar 2020 18:27:06 +0000 (18:27 +0000)
committerGitHub <noreply@github.com>
Fri, 6 Mar 2020 18:27:06 +0000 (18:27 +0000)
fixes #3744

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

index ab89e92..763aabd 100644 (file)
@@ -1384,7 +1384,10 @@ merge(Compressor.prototype, {
             function is_last_node(node, parent) {
                 if (node instanceof AST_Call) {
                     var fn = node.expression;
-                    if (fn instanceof AST_SymbolRef) fn = fn.fixed_value();
+                    if (fn instanceof AST_SymbolRef) {
+                        if (fn.definition().recursive_refs > 0) return true;
+                        fn = fn.fixed_value();
+                    }
                     if (!(fn instanceof AST_Lambda)) return true;
                     if (fn.collapse_scanning) return false;
                     fn.collapse_scanning = true;
index 58ae5c6..99e57b3 100644 (file)
@@ -7765,3 +7765,44 @@ issue_3700: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3744: {
+    options = {
+        collapse_vars: true,
+        inline: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function f(a) {
+            ({
+                get p() {
+                    switch (1) {
+                      case 0:
+                        f((a = 2, 3));
+                      case 1:
+                        console.log(function g(b) {
+                            return b || "PASS";
+                        }());
+                    }
+                }
+            }).p;
+        })();
+    }
+    expect: {
+        (function f(a) {
+            ({
+                get p() {
+                    switch (1) {
+                      case 0:
+                        f();
+                      case 1:
+                        console.log(b || "PASS");
+                    }
+                    var b;
+                }
+            }).p;
+        })();
+    }
+    expect_stdout: "PASS"
+}