stop at symbol redefinition

This commit is contained in:
alexlamsl 2017-05-04 12:35:50 +08:00
parent 2539db09e8
commit eb570c4661
2 changed files with 27 additions and 1 deletions

View File

@ -750,7 +750,7 @@ merge(Compressor.prototype, {
|| node instanceof AST_SymbolRef || node instanceof AST_SymbolRef
&& (lvalues && lvalues[node.name] && (lvalues && lvalues[node.name]
|| side_effects && !references_in_scope(node.definition())) || side_effects && !references_in_scope(node.definition()))
|| lvalues && (sym = is_lhs(node.left, node)) && get_symbol(sym).name in lvalues || lvalues && (sym = lhs_or_def(node)) && get_symbol(sym).name in lvalues
|| parent instanceof AST_Binary || parent instanceof AST_Binary
&& (parent.operator == "&&" || parent.operator == "||") && (parent.operator == "&&" || parent.operator == "||")
|| parent instanceof AST_Case || parent instanceof AST_Case
@ -828,6 +828,11 @@ merge(Compressor.prototype, {
return lvalues; return lvalues;
} }
function lhs_or_def(node) {
if (node instanceof AST_VarDef) return node.value && node.name;
return is_lhs(node.left, node);
}
function remove_candidate(expr) { function remove_candidate(expr) {
var found = false; var found = false;
return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) { return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {

View File

@ -2146,3 +2146,24 @@ issue_315: {
} }
expect_stdout: true expect_stdout: true
} }
lvalues_def: {
options = {
collapse_vars: true,
side_effects: true,
unused: true,
}
input: {
var a = 0, b = 1;
var a = b++, b = +function() {}();
a && a[a++];
console.log(a, b);
}
expect: {
var a = 0, b = 1;
var a = b++, b = +void 0;
a && a[a++];
console.log(a, b);
}
expect_stdout: true
}