enhance `dead_code` (#3849)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 5 May 2020 21:02:35 +0000 (22:02 +0100)
committerGitHub <noreply@github.com>
Tue, 5 May 2020 21:02:35 +0000 (05:02 +0800)
lib/compress.js
test/compress/dead-code.js

index eb359df..249b551 100644 (file)
@@ -7670,6 +7670,11 @@ merge(Compressor.prototype, {
                         if (is_reachable(scope, [ def ])) break;
                         def.fixed = false;
                         return strip_assignment();
+                    } else if (parent instanceof AST_VarDef) {
+                        if (parent.name.definition() !== def) continue;
+                        if (in_try(level, parent)) break;
+                        def.fixed = false;
+                        return strip_assignment();
                     }
                 } while (parent instanceof AST_Binary && parent.right === node
                     || parent instanceof AST_Sequence && parent.tail_node() === node
index 5a7be3c..a1fb948 100644 (file)
@@ -1151,3 +1151,20 @@ issue_3830_6: {
     }
     expect_stdout: "PASS"
 }
+
+redundant_assignments: {
+    options = {
+        dead_code: true,
+    }
+    input: {
+        var a = a = "PASS", b = "FAIL";
+        b = b = "PASS";
+        console.log(a, b);
+    }
+    expect: {
+        var a = "PASS", b = "FAIL";
+        b = "PASS";
+        console.log(a, b);
+    }
+    expect_stdout: "PASS PASS"
+}