improve collapsible value detection (#1638)
- #1634 bars variables with cross-scope references in between to collapse - but if assigned value is side-effect-free, no states can be modified, so it is safe to move
This commit is contained in:
@@ -592,9 +592,10 @@ merge(Compressor.prototype, {
|
||||
// Restrict var replacement to constants if side effects encountered.
|
||||
if (side_effects_encountered |= lvalues_encountered) continue;
|
||||
|
||||
var value_has_side_effects = var_decl.value.has_side_effects(compressor);
|
||||
// Non-constant single use vars can only be replaced in same scope.
|
||||
if (ref.scope !== self) {
|
||||
side_effects_encountered |= var_decl.value.has_side_effects(compressor);
|
||||
side_effects_encountered |= value_has_side_effects;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -620,6 +621,7 @@ merge(Compressor.prototype, {
|
||||
|| (parent instanceof AST_If && node !== parent.condition)
|
||||
|| (parent instanceof AST_Conditional && node !== parent.condition)
|
||||
|| (node instanceof AST_SymbolRef
|
||||
&& value_has_side_effects
|
||||
&& !are_references_in_scope(node.definition(), self))
|
||||
|| (parent instanceof AST_Binary
|
||||
&& (parent.operator == "&&" || parent.operator == "||")
|
||||
|
||||
Reference in New Issue
Block a user