diff options
-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" +} |