aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-05-05 22:02:35 +0100
committerGitHub <noreply@github.com>2020-05-06 05:02:35 +0800
commit34ead0430bf24323495f47751e726dcc6bd8d5e7 (patch)
treec1448c43072dc2989e91580791c1daad9523f257
parent66ab2df97fa3d72e81231902679cca0fd4ff918f (diff)
downloadtracifyjs-34ead0430bf24323495f47751e726dcc6bd8d5e7.tar.gz
tracifyjs-34ead0430bf24323495f47751e726dcc6bd8d5e7.zip
enhance `dead_code` (#3849)
-rw-r--r--lib/compress.js5
-rw-r--r--test/compress/dead-code.js17
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index eb359df9..249b551a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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
diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js
index 5a7be3c7..a1fb9483 100644
--- a/test/compress/dead-code.js
+++ b/test/compress/dead-code.js
@@ -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"
+}