collapse_vars: do not replace a constant in loop condition or init (#1562)

This commit is contained in:
kzc
2017-03-06 12:42:33 -05:00
committed by Alex Lam S.L
parent a9fc9ddc33
commit 3ac2421932
2 changed files with 48 additions and 11 deletions

View File

@@ -535,10 +535,13 @@ merge(Compressor.prototype, {
// Constant single use vars can be replaced in any scope.
if (var_decl.value.is_constant()) {
var ctt = new TreeTransformer(function(node) {
if (node === ref
&& !ctt.find_parent(AST_ForIn)) {
return replace_var(node, ctt.parent(), true);
var parent = ctt.parent();
if (parent instanceof AST_IterationStatement
&& (parent.condition === node || parent.init === node)) {
return node;
}
if (node === ref)
return replace_var(node, parent, true);
});
stat.transform(ctt);
continue;