From f6a83f794456c65ba927c0ccf55ff88c5c003a66 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 18 Nov 2020 15:43:55 +0000 Subject: [PATCH] fix corner case in `merge_vars` (#4299) fixes #4298 --- lib/compress.js | 4 ++++ test/compress/destructured.js | 44 ++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 2a8ba8a0..49c1572d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4749,9 +4749,13 @@ merge(Compressor.prototype, { var def = ref.definition(); var ldef = node.variables.get(ref.name); if (ldef && (ldef === def || def.undeclared || node.parent_scope.find_variable(ref) === def)) { + references[def.id] = false; references[ldef.id] = false; } else { + var save = segment; + pop(); mark(ref, true, false); + segment = save; } return true; }); diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 4ef28864..cebb70ae 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1490,10 +1490,10 @@ issue_4294: { expect: { A = "PASS"; (function() { - var a = function({ - [a]: {}, + var b = function({ + [b]: {}, }) {}({ - [a]: 0, + [b]: 0, }); var b = A; console.log(b); @@ -1502,3 +1502,41 @@ issue_4294: { expect_stdout: "PASS" node_version: ">=6" } + +issue_4298: { + options = { + merge_vars: true, + } + input: { + (function() { + var a = { + object: "PASS", + }; + function f({ + [typeof a]: b, + }) { + var a = b; + return a; + } + var c = f(a); + console.log(c); + })(); + } + expect: { + (function() { + var a = { + object: "PASS", + }; + function f({ + [typeof a]: b, + }) { + var a = b; + return a; + } + var c = f(a); + console.log(c); + })(); + } + expect_stdout: "PASS" + node_version: ">=6" +} -- 2.34.1