fix corner case in `assignments` (#4522)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 8 Jan 2021 05:03:21 +0000 (05:03 +0000)
committerGitHub <noreply@github.com>
Fri, 8 Jan 2021 05:03:21 +0000 (13:03 +0800)
fixes #4521

lib/compress.js
test/compress/assignments.js

index fd0564c..bcffd8b 100644 (file)
@@ -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 == "+="
index 0f87f9a..5bc971a 100644 (file)
@@ -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"
+}