From c4c9c6d37de8074bba3e433621bc70f88d7631ae Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 10 May 2020 10:35:24 +0100 Subject: [PATCH] fix corner case in `hoist_props` (#3869) fixes #3868 --- lib/compress.js | 2 +- test/compress/hoist_props.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 6e0d36a7..904295ee 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4927,7 +4927,7 @@ merge(Compressor.prototype, { if (def.single_use) return; if (top_retain(def)) return; if (sym.fixed_value() !== right) return; - return right instanceof AST_Object; + return right instanceof AST_Object && right.properties.length > 0; } }); diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index 563c7aab..cc7ef020 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -912,3 +912,31 @@ issue_3440: { } expect_stdout: "PASS" } + +issue_3868: { + options = { + hoist_props: true, + passes: 2, + reduce_vars: true, + side_effects: true, + } + input: { + (function(t) { + t = {}; + ({ + get p() {}, + q: (console.log("PASS"), +t), + }).r; + })(); + } + expect: { + (function(t) { + t = {}; + ({ + get p() {}, + q: (console.log("PASS"), +t), + }).r; + })(); + } + expect_stdout: "PASS" +} -- 2.34.1