From e2e4b7fb3779b1719de8562f611c23938ba830b0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 2 Jun 2020 16:51:06 +0100 Subject: [PATCH] fix corner case in `hoist_props` (#3947) fixes #3945 --- lib/compress.js | 3 +++ test/compress/hoist_props.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index cfe37d0b..f3fc5e0e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5074,6 +5074,9 @@ merge(Compressor.prototype, { && right.properties.length > 0 && all(right.properties, function(prop) { return prop instanceof AST_ObjectKeyVal; + }) + && all(def.references, function(ref) { + return ref.fixed_value() === right; }); } }); diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index a73df1f5..4fcbd796 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -972,3 +972,26 @@ issue_3871: { } expect_stdout: "PASS" } + +issue_3945: { + options = { + hoist_props: true, + reduce_vars: true, + } + input: { + function f() { + o.p; + var o = { + q: 0, + }; + } + } + expect: { + function f() { + o.p; + var o = { + q: 0, + }; + } + } +} -- 2.34.1