From 7fe8c9150ac68fb13716e465872ed9e15d7a5126 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 8 Jan 2021 05:03:21 +0000 Subject: [PATCH] fix corner case in `assignments` (#4522) fixes #4521 --- lib/compress.js | 6 +++--- test/compress/assignments.js | 14 ++++++++++++++ 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" +} -- 2.34.1