} else if (node instanceof AST_ForIn) {
if (!drop_vars || !compressor.option("loops")) return;
if (!is_empty(node.body)) return;
- var sym = node.init;
- if (sym instanceof AST_Definitions) {
- sym = sym.definitions[0].name;
- } else while (sym instanceof AST_PropAccess) {
- sym = sym.expression.tail_node();
- }
- if (sym instanceof AST_Destructured) return;
+ var sym = get_init_symbol(node);
+ if (!sym) return;
var def = sym.definition();
- if (!def) return;
if (def.id in in_use_ids) return;
- if (def.scope !== self) {
- var d = self.find_variable(sym);
- if ((d && d.redefined() || d) === def) return;
- }
log(sym, "Dropping unused loop variable {name}");
if (for_ins[def.id] === node) delete for_ins[def.id];
var body = [];
return rhs.right;
}
+ function get_init_symbol(for_in) {
+ var init = for_in.init;
+ if (init instanceof AST_Definitions) {
+ init = init.definitions[0].name;
+ return init instanceof AST_SymbolDeclaration && init;
+ }
+ while (init instanceof AST_PropAccess) init = init.expression.tail_node();
+ if (init instanceof AST_SymbolRef) return init;
+ }
+
function scan_ref_scoped(node, descend, init) {
if (node instanceof AST_Assign && node.left instanceof AST_SymbolRef) {
var def = node.left.definition();
}
if (!drop_vars || !compressor.option("loops")) return;
if (!is_empty(node.body)) return;
- if (node.init instanceof AST_Destructured) return;
if (node.init.has_side_effects(compressor)) return;
+ var sym = get_init_symbol(node);
+ if (!sym) return;
+ var def = sym.definition();
+ if (def.scope !== self) {
+ var d = self.find_variable(sym);
+ if ((d && d.redefined() || d) === def) return;
+ }
node.object.walk(tw);
return true;
}
});
// always shallow clone to ensure stripping of negated IIFEs
self = self.clone();
+ self.expression = exp.clone();
}
if (self instanceof AST_New) {
var fn = exp;