From fb0d03e6a3364e9210464f8ac41f978ac4288cf3 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Tue, 2 Jun 2020 21:34:43 +0800 Subject: [PATCH] fix corner case in `hoist_props` 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 3728884f..120ceab1 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, + }; + } + } +}