From a53ab9937835f795c4714e981d10249e7829d2d4 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 23 Oct 2019 01:04:00 +0800 Subject: [PATCH] fix corner case in `side_effects` (#3514) fixes #3512 --- lib/compress.js | 2 +- test/compress/functions.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 2b61e91c..a8bf0d9d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4196,7 +4196,7 @@ merge(Compressor.prototype, { var left = this.left; if (left instanceof AST_PropAccess) { var expr = left.expression; - if (expr instanceof AST_Assign && !expr.may_throw_on_access(compressor)) { + if (expr instanceof AST_Assign && expr.operator == "=" && !expr.may_throw_on_access(compressor)) { expr.write_only = "p"; } if (compressor.has_directive("use strict") && expr.is_constant()) return this; diff --git a/test/compress/functions.js b/test/compress/functions.js index 5c8533de..0607e85c 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -3340,3 +3340,33 @@ issue_3506_3: { } expect_stdout: "PASS" } + +issue_3512: { + options = { + collapse_vars: true, + pure_getters: "strict", + sequences: true, + side_effects: true, + unused: true, + } + input: { + var a = "PASS"; + (function(b) { + (function() { + b <<= this || 1; + b.a = "FAIL"; + })(); + })(); + console.log(a); + } + expect: { + var a = "PASS"; + (function(b) { + (function() { + (b <<= this || 1).a = "FAIL"; + })(); + })(), + console.log(a); + } + expect_stdout: "PASS" +} -- 2.34.1