diff options
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 9400b864..a4a53f5a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -919,7 +919,7 @@ merge(Compressor.prototype, { } // pass 3: we should drop declarations not in_use var tt = new TreeTransformer( - function before(node, descend) { + function before(node, descend, in_list) { if (node instanceof AST_Lambda) { for (var a = node.argnames, i = a.length; --i >= 0;) { var sym = a[i]; @@ -1010,6 +1010,19 @@ merge(Compressor.prototype, { } return node; } + if (node instanceof AST_For && node.init instanceof AST_BlockStatement) { + descend(node, this); + // certain combination of unused name + side effect leads to: + // https://github.com/mishoo/UglifyJS2/issues/44 + // that's an invalid AST. + // We fix it at this stage by moving the `var` outside the `for`. + var body = node.init.body.slice(0, -1); + node.init = node.init.body.slice(-1)[0].body; + body.push(node); + return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, { + body: body + }); + } if (node instanceof AST_Scope && node !== self) return node; } |