diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-05 06:23:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 14:23:46 +0800 |
commit | fc5aee662d99257f59830ebcd5053ead48c9039b (patch) | |
tree | e8a6ad88390fec0e48916b10a5044ad56d2f54b7 | |
parent | 5fbbb43839d010ec609da3bf15308cb5b6f74dc5 (diff) | |
download | tracifyjs-fc5aee662d99257f59830ebcd5053ead48c9039b.tar.gz tracifyjs-fc5aee662d99257f59830ebcd5053ead48c9039b.zip |
fix corner case in `merge_vars` (#4505)
fixes #4504
-rw-r--r-- | lib/compress.js | 21 | ||||
-rw-r--r-- | test/compress/destructured.js | 26 |
2 files changed, 36 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js index aedbe448..1934ca3d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4944,16 +4944,15 @@ merge(Compressor.prototype, { if (node instanceof AST_DestructuredKeyVal) { if (node.key instanceof AST_Node) { push(); + segment.block = node; node.key.walk(tw); - pop(); - push(); node.value.walk(marker); pop(); } else { node.value.walk(marker); } } else if (node instanceof AST_SymbolRef) { - mark(node, false, true); + mark(node); } else { node.walk(tw); } @@ -4963,9 +4962,9 @@ merge(Compressor.prototype, { return true; } if (lhs instanceof AST_SymbolRef) { - if (node.operator != "=") mark(lhs, true, false); + if (node.operator != "=") mark(lhs, true); node.right.walk(tw); - mark(lhs, false, true); + mark(lhs); return true; } return; @@ -5073,7 +5072,7 @@ merge(Compressor.prototype, { var marker = node.uses_arguments && !tw.has_directive("use strict") ? function(node) { if (node instanceof AST_SymbolFunarg) references[node.definition().id] = false; } : function(node) { - if (node instanceof AST_SymbolFunarg) mark(node, false, true); + if (node instanceof AST_SymbolFunarg) mark(node); }; var scanner = new TreeWalker(function(ref) { if (ref instanceof AST_SymbolDeclaration) references[ref.definition().id] = false; @@ -5088,7 +5087,7 @@ merge(Compressor.prototype, { } else { var save = segment; pop(); - mark(ref, true, false); + mark(ref, true); segment = save; } return true; @@ -5125,7 +5124,7 @@ merge(Compressor.prototype, { return true; } if (node instanceof AST_SymbolRef) { - mark(node, true, false); + mark(node, true); return true; } if (node instanceof AST_Try) { @@ -5153,7 +5152,7 @@ merge(Compressor.prototype, { if (!UNARY_POSTFIX[node.operator]) return; var sym = node.expression; if (!(sym instanceof AST_SymbolRef)) return; - mark(sym, true, true); + mark(sym, true); return true; } if (node instanceof AST_VarDef) { @@ -5161,7 +5160,7 @@ merge(Compressor.prototype, { node.name.mark_symbol(node.value ? function(node) { if (!(node instanceof AST_SymbolDeclaration)) return; if (node instanceof AST_SymbolVar) { - mark(node, false, true); + mark(node, false); } else { references[node.definition().id] = false; } @@ -5246,7 +5245,7 @@ merge(Compressor.prototype, { segment = Object.getPrototypeOf(segment); } - function mark(sym, read, write) { + function mark(sym, read) { var def = sym.definition(), ldef; if (def.id in references) { var refs = references[def.id]; diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 70c4392a..9812b146 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -2326,3 +2326,29 @@ issue_4500: { expect_stdout: "PASS" node_version: ">=6" } + +issue_4504: { + options = { + inline: true, + merge_vars: true, + } + input: { + A = "FAIL"; + (function f(a) { + ({ + [console.log(a)]: 0[(b => console + b)(A)] + } = 0); + })("PASS"); + } + expect: { + A = "FAIL"; + (function f(a) { + ({ + [console.log(a)]: 0[b = A, console + b] + } = 0); + var b; + })("PASS"); + } + expect_stdout: "PASS" + node_version: ">=6" +} |