aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-01-08 05:03:21 +0000
committerGitHub <noreply@github.com>2021-01-08 13:03:21 +0800
commit7fe8c9150ac68fb13716e465872ed9e15d7a5126 (patch)
treee43af5ae6f754bdeab9297b1f21b5b05a740fb4d
parent6c419bc083e097337960f1a19d2c352336d75e16 (diff)
downloadtracifyjs-7fe8c9150ac68fb13716e465872ed9e15d7a5126.tar.gz
tracifyjs-7fe8c9150ac68fb13716e465872ed9e15d7a5126.zip
fix corner case in `assignments` (#4522)
fixes #4521
-rw-r--r--lib/compress.js6
-rw-r--r--test/compress/assignments.js14
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index fd0564cb..bcffd8b8 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -9948,9 +9948,9 @@ merge(Compressor.prototype, {
operator: self.right.operator + "=",
left: self.left,
right: self.right.right,
- }).optimize(compressor);
+ });
}
- else if (self.right.right instanceof AST_SymbolRef
+ if (self.right.right instanceof AST_SymbolRef
&& self.right.right.name == self.left.name
&& ASSIGN_OPS_COMMUTATIVE[self.right.operator]
&& !self.right.left.has_side_effects(compressor)) {
@@ -9959,7 +9959,7 @@ merge(Compressor.prototype, {
operator: self.right.operator + "=",
left: self.left,
right: self.right.left,
- }).optimize(compressor);
+ });
}
}
if ((self.operator == "-=" || self.operator == "+="
diff --git a/test/compress/assignments.js b/test/compress/assignments.js
index 0f87f9a0..5bc971a5 100644
--- a/test/compress/assignments.js
+++ b/test/compress/assignments.js
@@ -461,3 +461,17 @@ issue_3949_2: {
}
expect_stdout: "100"
}
+
+issue_4521: {
+ options = {
+ assignments: true,
+ dead_code: true,
+ }
+ input: {
+ var a = (a = 42 | a) ? console.log(a) : 0;
+ }
+ expect: {
+ var a = (a |= 42) ? console.log(a) : 0;
+ }
+ expect_stdout: "42"
+}