aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-07-14 16:02:45 +0100
committerGitHub <noreply@github.com>2021-07-14 23:02:45 +0800
commitf18804fa068515f7142715a245c47094c9e348e7 (patch)
treeaee0b40994f595db192c76824e926a03f960d4e4
parent8e2dff632e2c6e696b8bd874f61ec1685306da41 (diff)
downloadtracifyjs-f18804fa068515f7142715a245c47094c9e348e7.tar.gz
tracifyjs-f18804fa068515f7142715a245c47094c9e348e7.zip
fix corner case in `unused` (#5080)
fixes #5079
-rw-r--r--lib/compress.js6
-rw-r--r--test/compress/drop-unused.js23
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f602af9c..84392f7c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6366,7 +6366,10 @@ merge(Compressor.prototype, {
if (value) {
if (props.assign) {
var assign = props.assign.drop_side_effect_free(compressor);
- if (assign) props.unshift(assign);
+ if (assign) {
+ assign.write_only = true;
+ props.unshift(assign);
+ }
}
if (!(parent instanceof AST_Sequence)
|| parent.tail_node() === node
@@ -6942,7 +6945,6 @@ merge(Compressor.prototype, {
if (assign) {
assign.write_only = true;
assign.walk(tw);
- assign.write_only = "p";
}
props.forEach(function(prop) {
prop.walk(tw);
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index ed821c29..cb2cb33a 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -3469,3 +3469,26 @@ issue_4912_3: {
}
expect_stdout: "PASS"
}
+
+issue_5079: {
+ options = {
+ collapse_vars: true,
+ pure_getters: "strict",
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a;
+ do {
+ (a = 123456).p = a;
+ a.q = null;
+ } while (console.log("PASS"));
+ }
+ expect: {
+ do {
+ 0, 0, null;
+ } while (console.log("PASS"));
+ }
+ expect_stdout: "PASS"
+}