From ec7f071272384db82dff0f8fb6629f4f6fee43a5 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 30 Oct 2019 14:21:22 +0800 Subject: [PATCH] fix corner case in `dead_code` (#3553) fixes #3552 --- lib/compress.js | 20 +++++++++++--------- test/compress/dead-code.js | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 33943ff0bf8..a28c7a6c11b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6433,15 +6433,17 @@ merge(Compressor.prototype, { OPT(AST_Assign, function(self, compressor) { if (compressor.option("dead_code")) { if (self.left instanceof AST_PropAccess) { - var exp = self.left.expression; - if (exp instanceof AST_Lambda - || !compressor.has_directive("use strict") - && exp instanceof AST_Constant - && !exp.may_throw_on_access(compressor)) { - return self.left instanceof AST_Dot ? self.right : make_sequence(self, [ - self.left.property, - self.right - ]).optimize(compressor); + if (self.operator == "=") { + var exp = self.left.expression; + if (exp instanceof AST_Lambda + || !compressor.has_directive("use strict") + && exp instanceof AST_Constant + && !exp.may_throw_on_access(compressor)) { + return self.left instanceof AST_Dot ? self.right : make_sequence(self, [ + self.left.property, + self.right + ]).optimize(compressor); + } } } else if (self.left instanceof AST_SymbolRef) { var def = self.left.definition(); diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index 501d55ecc18..93fc9f41df5 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -1042,3 +1042,25 @@ function_assign: { } expect_stdout: "PASS" } + +issue_3552: { + options = { + dead_code: true, + pure_getters: "strict", + } + input: { + var a = "PASS"; + (function() { + (1..p += 42) && (a = "FAIL"); + })(); + console.log(a); + } + expect: { + var a = "PASS"; + (function() { + (1..p += 42) && (a = "FAIL"); + })(); + console.log(a); + } + expect_stdout: "PASS" +}