fix corner case in `collapse_vars` (#4309)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 19 Nov 2020 22:23:37 +0000 (22:23 +0000)
committerGitHub <noreply@github.com>
Thu, 19 Nov 2020 22:23:37 +0000 (06:23 +0800)
fixes #4308

lib/compress.js
test/compress/destructured.js

index 9048880..601f39f 100644 (file)
@@ -1825,7 +1825,11 @@ merge(Compressor.prototype, {
                             name: sym,
                             value: arg
                         }));
-                        if (sym instanceof AST_Destructured) continue;
+                        if (sym instanceof AST_Destructured) {
+                            if (!sym.match_symbol(return_false)) continue;
+                            candidates.length = 0;
+                            break;
+                        }
                         if (sym.name in names) continue;
                         names[sym.name] = true;
                         if (!arg) {
index bbe62a7..f8e8090 100644 (file)
@@ -1591,3 +1591,28 @@ issue_4301: {
     expect_stdout: true
     node_version: ">=6"
 }
+
+issue_4308: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        console.log(function({
+            [a = "FAIL"]: b
+        }, c) {
+            return c;
+        }(0, a));
+    }
+    expect: {
+        var a = "PASS";
+        console.log(function({
+            [a = "FAIL"]: b
+        }, c) {
+            return c;
+        }(0, a));
+    }
+    expect_stdout: "PASS"
+    node_version: ">=6"
+}