fix unused patching of AST_For.init blocks (#2289)

fixes #2288
This commit is contained in:
Alex Lam S.L
2017-08-29 01:10:04 +08:00
committed by GitHub
parent f81ff10a9b
commit e5cf7972ea
2 changed files with 27 additions and 4 deletions

View File

@@ -2423,17 +2423,18 @@ merge(Compressor.prototype, {
// We fix it at this stage by moving the `var` outside the `for`.
if (node instanceof AST_For) {
descend(node, this);
var block;
if (node.init instanceof AST_BlockStatement) {
var block = node.init;
block = node.init;
node.init = block.body.pop();
block.body.push(node);
return in_list ? MAP.splice(block.body) : block;
} else if (node.init instanceof AST_SimpleStatement) {
}
if (node.init instanceof AST_SimpleStatement) {
node.init = node.init.body;
} else if (is_empty(node.init)) {
node.init = null;
}
return node;
return !block ? node : in_list ? MAP.splice(block.body) : block;
}
if (node instanceof AST_LabeledStatement && node.body instanceof AST_For) {
descend(node, this);