// 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)
- return replace_var(node, ctt.parent(), true);
+ if (node === ref) {
+ var parent = ctt.parent();
+ if (!(parent instanceof AST_ForIn && parent.init === node)) {
+ return replace_var(node, parent, true);
+ }
+ }
});
stat.transform(ctt);
continue;
// Further optimize statement after substitution.
stat.reset_opt_flags(compressor);
- compressor.warn("Replacing " + (is_constant ? "constant" : "variable") +
+ compressor.warn("Collapsing " + (is_constant ? "constant" : "variable") +
" " + var_name + " [{file}:{line},{col}]", node.start);
CHANGED = true;
return value;