diff --git a/lib/compress.js b/lib/compress.js index ba4d6fe7..1b6ffcb7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6044,31 +6044,7 @@ Compressor.prototype.compress = function(node) { var rhs = node.right; if (lhs instanceof AST_Destructured) { rhs.walk(tw); - var marker = new TreeWalker(function(node) { - if (node instanceof AST_Destructured) return; - if (node instanceof AST_DefaultValue) { - push(); - node.value.walk(tw); - pop(); - node.name.walk(marker); - } else if (node instanceof AST_DestructuredKeyVal) { - if (node.key instanceof AST_Node) { - push(); - segment.block = node; - node.key.walk(tw); - node.value.walk(marker); - pop(); - } else { - node.value.walk(marker); - } - } else if (node instanceof AST_SymbolRef) { - mark(node); - } else { - node.walk(tw); - } - return true; - }); - lhs.walk(marker); + walk_destructured(AST_SymbolRef, mark, lhs); return true; } if (lazy_op[node.operator.slice(0, -1)]) { @@ -6196,15 +6172,15 @@ Compressor.prototype.compress = function(node) { if (node instanceof AST_Lambda) { if (node.name) references[node.name.definition().id] = false; var marker = node.uses_arguments && !tw.has_directive("use strict") ? function(node) { - if (node instanceof AST_SymbolFunarg) references[node.definition().id] = false; + references[node.definition().id] = false; } : function(node) { - if (node instanceof AST_SymbolFunarg) mark(node); + mark(node); }; in_arg.push(node); node.argnames.forEach(function(argname) { - argname.mark_symbol(marker, tw); + walk_destructured(AST_SymbolFunarg, marker, argname); }); - if (node.rest) node.rest.mark_symbol(marker, tw); + if (node.rest) walk_destructured(AST_SymbolFunarg, marker, node.rest); in_arg.pop(); } walk_lambda(node, tw); @@ -6419,6 +6395,34 @@ Compressor.prototype.compress = function(node) { segment = Object.getPrototypeOf(segment); } + function walk_destructured(symbol_type, mark, lhs) { + var marker = new TreeWalker(function(node) { + if (node instanceof AST_Destructured) return; + if (node instanceof AST_DefaultValue) { + push(); + node.value.walk(tw); + pop(); + node.name.walk(marker); + } else if (node instanceof AST_DestructuredKeyVal) { + if (node.key instanceof AST_Node) { + push(); + segment.block = node; + node.key.walk(tw); + node.value.walk(marker); + pop(); + } else { + node.value.walk(marker); + } + } else if (node instanceof symbol_type) { + mark(node); + } else { + node.walk(tw); + } + return true; + }); + lhs.walk(marker); + } + function mark(sym, read) { var def = sym.definition(), ldef; if (read && !all(in_arg, function(fn) { diff --git a/test/compress/default-values.js b/test/compress/default-values.js index 129aaee1..941a3415 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -2421,3 +2421,30 @@ issue_5463: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5465: { + options = { + inline: true, + merge_vars: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function f(a, b) { + (function(c = b = "FAIL 2") { + this && console.log(b || "PASS"); + })(42 - a && a); + } + f("FAIL 1"); + } + expect: { + a = "FAIL 1", + void function(c = b = "FAIL 2") { + this && console.log(b || "PASS"); + }(42 - a && a); + var a, b; + } + expect_stdout: "PASS" + node_version: ">=6" +} diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 6914d1f4..e88152e6 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1815,8 +1815,8 @@ issue_4288: { console.log(typeof b); }()]: a, }) { - var a = a; - a++; + var b = a; + b++; } f(0); } @@ -1848,8 +1848,8 @@ issue_4294: { }) {}({ [a]: 0, }); - var a = A; - console.log(a); + var b = A; + console.log(b); })(); } expect_stdout: "PASS"