fix corner case in `collapse_vars` (#4332)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 6 Dec 2020 10:30:50 +0000 (10:30 +0000)
committerGitHub <noreply@github.com>
Sun, 6 Dec 2020 10:30:50 +0000 (18:30 +0800)
fixes #4331

lib/compress.js
test/compress/spread.js

index 82474b5..e84465f 100644 (file)
@@ -2047,6 +2047,7 @@ merge(Compressor.prototype, {
                     return (parent.tail_node() === node ? find_stop_value : find_stop_unused)(parent, level + 1);
                 }
                 if (parent instanceof AST_SimpleStatement) return find_stop_unused(parent, level + 1);
+                if (parent instanceof AST_Spread) return find_stop_value(parent, level + 1);
                 if (parent instanceof AST_Switch) {
                     if (parent.expression !== node) return node;
                     return find_stop_value(parent, level + 1);
index 01818dc..21ccbe6 100644 (file)
@@ -399,3 +399,29 @@ issue_4329: {
     expect_stdout: "PASS"
     node_version: ">=8"
 }
+
+issue_4331: {
+    options = {
+        collapse_vars: true,
+        toplevel: true,
+    }
+    input: {
+        var a = "PASS", b;
+        console,
+        b = a;
+        (function() {
+            a++;
+        })(...a);
+        console.log(b);
+    }
+    expect: {
+        var a = "PASS", b;
+        console;
+        (function() {
+            a++;
+        })(...b = a);
+        console.log(b);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=8"
+}