diff options
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/compress.js b/lib/compress.js index 273c5a75..7355ff53 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4642,16 +4642,7 @@ merge(Compressor.prototype, { body: make_sequence(node, side_effects) })); } - switch (body.length) { - case 0: - return in_list ? List.skip : make_node(AST_EmptyStatement, node); - case 1: - return body[0]; - default: - return in_list ? List.splice(body) : make_node(AST_BlockStatement, node, { - body: body - }); - } + return insert_statements(body, node, in_list); } if (node instanceof AST_LabeledStatement && node.body instanceof AST_For) { // Certain combination of unused name + side effect leads to invalid AST: @@ -4714,12 +4705,19 @@ merge(Compressor.prototype, { if (def.id in in_use_ids) return; if (def.scope !== self && member(def, self.enclosed)) return; log(sym, "Dropping unused loop variable {name}"); + if (for_ins[def.id] === node) delete for_ins[def.id]; + var body = []; var value = node.object.drop_side_effect_free(compressor); - if (!value) return in_list ? List.skip : make_node(AST_EmptyStatement, node); - AST_Node.warn("Side effects in object of for-in loop [{file}:{line},{col}]", value.start); - return make_node(AST_SimpleStatement, node, { - body: value - }); + if (value) { + AST_Node.warn("Side effects in object of for-in loop [{file}:{line},{col}]", value.start); + body.push(make_node(AST_SimpleStatement, node, { + body: value + })); + } + if (node.init instanceof AST_Definitions && def.orig[0] instanceof AST_SymbolCatch) { + body.push(node.init); + } + return insert_statements(body, node, in_list); } else if (node instanceof AST_Sequence) { if (node.expressions.length == 1) return node.expressions[0]; } @@ -4752,6 +4750,19 @@ merge(Compressor.prototype, { }; } + function insert_statements(body, orig, in_list) { + switch (body.length) { + case 0: + return in_list ? List.skip : make_node(AST_EmptyStatement, orig); + case 1: + return body[0]; + default: + return in_list ? List.splice(body) : make_node(AST_BlockStatement, orig, { + body: body + }); + } + } + function track_assigns(def, node) { if (def.scope !== self) return false; if (!def.fixed || !node.fixed) assign_in_use[def.id] = false; |