@@ -5592,20 +5592,10 @@ merge(Compressor.prototype, {
|
||||
} 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 = [];
|
||||
@@ -5705,6 +5695,16 @@ merge(Compressor.prototype, {
|
||||
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();
|
||||
@@ -5748,8 +5748,14 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -6259,6 +6265,7 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
// always shallow clone to ensure stripping of negated IIFEs
|
||||
self = self.clone();
|
||||
self.expression = exp.clone();
|
||||
}
|
||||
if (self instanceof AST_New) {
|
||||
var fn = exp;
|
||||
|
||||
Reference in New Issue
Block a user