fix corner case in `unused` (#4557)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 15 Jan 2021 04:33:17 +0000 (04:33 +0000)
committerGitHub <noreply@github.com>
Fri, 15 Jan 2021 04:33:17 +0000 (12:33 +0800)
fixes #4556

lib/compress.js
test/compress/spreads.js

index fadd741..01ec7e6 100644 (file)
@@ -5766,6 +5766,9 @@ merge(Compressor.prototype, {
                             var write_only = def.value.write_only;
                             var value = def.value.drop_side_effect_free(compressor);
                             if (def.value !== value) {
+                                sym.references.forEach(function(node) {
+                                    if (node.fixed === sym.fixed) node.fixed = def.value;
+                                });
                                 def.value = null;
                                 if (value) {
                                     AST_Node.warn("Side effects in last use of variable {name} [{file}:{line},{col}]", template(def.name));
index 1e4dcbf..7c98fdc 100644 (file)
@@ -826,3 +826,23 @@ issue_4363: {
     expect_stdout: "PASS"
     node_version: ">=8"
 }
+
+issue_4556: {
+    options = {
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function() {
+            var a = "" + [ a++ ];
+            var b = [ ...a ];
+        }());
+    }
+    expect: {
+        console.log(function() {
+            var a;
+        }());
+    }
+    expect_stdout: "undefined"
+    node_version: ">=6"
+}