fix corner case with top-level singular reference
This commit is contained in:
parent
6c40202625
commit
475f551f2f
|
|
@ -711,7 +711,8 @@ merge(Compressor.prototype, {
|
|||
return make_node(AST_UnaryPrefix, candidate, candidate);
|
||||
}
|
||||
if (candidate instanceof AST_VarDef) {
|
||||
if (candidate.name.definition().references.length == 1) {
|
||||
var def = candidate.name.definition();
|
||||
if (def.references.length == 1 && (!def.global || compressor.toplevel(def))) {
|
||||
return maintain_this_binding(parent, node, candidate.value);
|
||||
}
|
||||
return make_node(AST_Assign, candidate, {
|
||||
|
|
@ -779,9 +780,7 @@ merge(Compressor.prototype, {
|
|||
expr.expressions.forEach(extract_candidates);
|
||||
} else if (expr instanceof AST_Definitions) {
|
||||
expr.definitions.forEach(function(var_def) {
|
||||
if (var_def.value) {
|
||||
candidates.push(var_def);
|
||||
}
|
||||
if (var_def.value) candidates.push(var_def);
|
||||
});
|
||||
} else if (expr instanceof AST_SimpleStatement) {
|
||||
extract_candidates(expr.body);
|
||||
|
|
|
|||
|
|
@ -2059,3 +2059,21 @@ double_def: {
|
|||
(a = a && y)();
|
||||
}
|
||||
}
|
||||
|
||||
toplevel_single_reference: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
for (var b in x) {
|
||||
var a = b;
|
||||
b(a);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
for (var b in x)
|
||||
b(a = b);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user