From f0a29902acc24217881529449c7f9b8815896297 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 15 Feb 2020 13:04:44 +0000 Subject: [PATCH] enhance `properties` (#3721) --- lib/compress.js | 8 +++++--- test/compress/properties.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 666f4c4c65..e8a717917a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7615,9 +7615,11 @@ merge(Compressor.prototype, { value = value.fixed_value(); } if (!value) return false; - return !(value instanceof AST_Lambda) - || compressor.parent() instanceof AST_New - || !value.contains_this(); + if (!(value instanceof AST_Lambda)) return true; + var parent = compressor.parent(); + if (parent.TYPE != "Call") return true; + if (parent.expression !== compressor.self()) return true; + return !value.contains_this(); } OPT(AST_Sub, function(self, compressor) { diff --git a/test/compress/properties.js b/test/compress/properties.js index a70ab7d87b..9270f43878 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -817,6 +817,29 @@ issue_2208_5: { expect_stdout: "42" } +issue_2208_6: { + options = { + inline: true, + properties: true, + side_effects: true, + } + input: { + a = 42; + console.log(("FAIL", { + p: function() { + return this.a; + } + }.p)()); + } + expect: { + a = 42; + console.log(function() { + return this.a; + }()); + } + expect_stdout: "42" +} + issue_2256: { options = { side_effects: true,