diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-11-18 01:32:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-18 09:32:53 +0800 |
commit | 7a51c17ff0005ca3725c8afefe2f4086f4316ee2 (patch) | |
tree | cb71282f83f81fbb84f52192c091f3911e820b96 | |
parent | aff842f2f9311295877de7e22c3c6afa4f82214b (diff) | |
download | tracifyjs-7a51c17ff0005ca3725c8afefe2f4086f4316ee2.tar.gz tracifyjs-7a51c17ff0005ca3725c8afefe2f4086f4316ee2.zip |
fix corner case in `merge_vars` (#4295)
fixes #4294
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/destructured.js | 32 | ||||
-rw-r--r-- | test/reduce.js | 2 |
3 files changed, 35 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index c1da6e77..e05b6f28 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4750,6 +4750,8 @@ merge(Compressor.prototype, { var ldef = node.variables.get(ref.name); if (ldef && (ldef === def || def.undeclared || node.parent_scope.find_variable(ref) === def)) { references[ldef.id] = false; + } else { + mark(ref, true, false); } return true; }); diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 7eaad226..4ef28864 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1470,3 +1470,35 @@ issue_4288: { expect_stdout: "undefined" node_version: ">=6" } + +issue_4294: { + options = { + merge_vars: true, + } + input: { + A = "PASS"; + (function() { + var a = function({ + [a]: {}, + }) {}({ + [a]: 0, + }); + var b = A; + console.log(b); + })(); + } + expect: { + A = "PASS"; + (function() { + var a = function({ + [a]: {}, + }) {}({ + [a]: 0, + }); + var b = A; + console.log(b); + })(); + } + expect_stdout: "PASS" + node_version: ">=6" +} diff --git a/test/reduce.js b/test/reduce.js index f126573e..2b1b42e7 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -115,7 +115,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) // ignore lvalues if (parent instanceof U.AST_Assign && parent.left === node) return; - if (parent instanceof U.AST_Destructured) return; + if (parent instanceof U.AST_DestructuredArray) return; if (parent instanceof U.AST_DestructuredKeyVal && parent.value === node) return; if (parent instanceof U.AST_Unary && parent.expression === node) switch (parent.operator) { case "++": |