fix chained assignment with unused (#1540)
When #1450 optimises `a=b=42`, it stops after the first variable even if both are unused. fixes #1539
This commit is contained in:
@@ -1801,14 +1801,17 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
if (drop_vars && assign_as_unused
|
if (drop_vars && assign_as_unused) {
|
||||||
&& node instanceof AST_Assign
|
var n = node;
|
||||||
&& node.operator == "="
|
while (n instanceof AST_Assign
|
||||||
&& node.left instanceof AST_SymbolRef) {
|
&& n.operator == "="
|
||||||
var def = node.left.definition();
|
&& n.left instanceof AST_SymbolRef) {
|
||||||
if (!(def.id in in_use_ids) && self.variables.get(def.name) === def) {
|
var def = n.left.definition();
|
||||||
return node.right;
|
if (def.id in in_use_ids
|
||||||
|
|| self.variables.get(def.name) !== def) break;
|
||||||
|
n = n.right;
|
||||||
}
|
}
|
||||||
|
if (n !== node) return n;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_For) {
|
if (node instanceof AST_For) {
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
|
|||||||
@@ -679,3 +679,24 @@ const_assign: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1539: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var a, b;
|
||||||
|
a = b = 42;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user