improve collapse_vars on side-effect-free replacements

This commit is contained in:
alexlamsl 2017-12-13 01:17:46 +08:00
parent ddf96cfda2
commit 38fd166612
2 changed files with 22 additions and 2 deletions

View File

@ -895,10 +895,11 @@ merge(Compressor.prototype, {
|| node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression) || node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression)
|| node instanceof AST_Debugger || node instanceof AST_Debugger
|| node instanceof AST_IterationStatement && !(node instanceof AST_For) || node instanceof AST_IterationStatement && !(node instanceof AST_For)
|| node instanceof AST_SymbolRef && !node.is_declared(compressor)
|| node instanceof AST_Try || node instanceof AST_Try
|| node instanceof AST_With || node instanceof AST_With
|| parent instanceof AST_For && node !== parent.init) { || parent instanceof AST_For && node !== parent.init
|| (side_effects || !replace_all)
&& (node instanceof AST_SymbolRef && !node.is_declared(compressor))) {
abort = true; abort = true;
return node; return node;
} }

View File

@ -3805,3 +3805,22 @@ may_throw: {
} }
} }
} }
side_effect_free_replacement: {
options = {
collapse_vars: true,
inline: true,
side_effects: true,
unused: true,
}
input: {
var b;
(function(a) {
x(a);
})(b);
}
expect: {
var b;
x(b);
}
}