account for cross-scope modifications in collapse_vars (#1634)
mostly done by @kzc fixes #1631
This commit is contained in:
@@ -619,12 +619,24 @@ merge(Compressor.prototype, {
|
||||
|| node instanceof AST_IterationStatement
|
||||
|| (parent instanceof AST_If && node !== parent.condition)
|
||||
|| (parent instanceof AST_Conditional && node !== parent.condition)
|
||||
|| (node instanceof AST_SymbolRef
|
||||
&& !are_references_in_scope(node.definition(), self))
|
||||
|| (parent instanceof AST_Binary
|
||||
&& (parent.operator == "&&" || parent.operator == "||")
|
||||
&& node === parent.right)
|
||||
|| (parent instanceof AST_Switch && node !== parent.expression)) {
|
||||
return side_effects_encountered = unwind = true, node;
|
||||
}
|
||||
function are_references_in_scope(def, scope) {
|
||||
if (def.orig.length === 1
|
||||
&& def.orig[0] instanceof AST_SymbolDefun) return true;
|
||||
if (def.scope !== scope) return false;
|
||||
var refs = def.references;
|
||||
for (var i = 0, len = refs.length; i < len; i++) {
|
||||
if (refs[i].scope !== scope) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
function postorder(node) {
|
||||
if (unwind) return node;
|
||||
|
||||
Reference in New Issue
Block a user