diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-11-18 15:43:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-18 23:43:55 +0800 |
commit | f6a83f794456c65ba927c0ccf55ff88c5c003a66 (patch) | |
tree | aab67c440c0011df3bfc21392c82bea5ab61cc1c | |
parent | 35283e5dd18bb2b3be46a25786e2e73e8a24a863 (diff) | |
download | tracifyjs-f6a83f794456c65ba927c0ccf55ff88c5c003a66.tar.gz tracifyjs-f6a83f794456c65ba927c0ccf55ff88c5c003a66.zip |
fix corner case in `merge_vars` (#4299)
fixes #4298
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | 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" +} |