Fix #280
The `init` of the `ForStatement` is not a `BlockStatement` before it was descended. The descend has to happen first, and *then* the actual checks.
This commit is contained in:
@@ -86,13 +86,14 @@ merge(Compressor.prototype, {
|
|||||||
before: function(node, descend, in_list) {
|
before: function(node, descend, in_list) {
|
||||||
if (node._squeezed) return node;
|
if (node._squeezed) return node;
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.drop_unused(this);
|
//node.drop_unused(this);
|
||||||
node = node.hoist_declarations(this);
|
node = node.hoist_declarations(this);
|
||||||
}
|
}
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
node = node.optimize(this);
|
node = node.optimize(this);
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.drop_unused(this);
|
node.drop_unused(this);
|
||||||
|
descend(node, this);
|
||||||
}
|
}
|
||||||
node._squeezed = true;
|
node._squeezed = true;
|
||||||
return node;
|
return node;
|
||||||
@@ -1082,19 +1083,24 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_For && node.init instanceof AST_BlockStatement) {
|
if (node instanceof AST_For) {
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
|
|
||||||
|
if (node.init instanceof AST_BlockStatement) {
|
||||||
// certain combination of unused name + side effect leads to:
|
// certain combination of unused name + side effect leads to:
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/44
|
// https://github.com/mishoo/UglifyJS2/issues/44
|
||||||
// that's an invalid AST.
|
// that's an invalid AST.
|
||||||
// We fix it at this stage by moving the `var` outside the `for`.
|
// We fix it at this stage by moving the `var` outside the `for`.
|
||||||
|
|
||||||
var body = node.init.body.slice(0, -1);
|
var body = node.init.body.slice(0, -1);
|
||||||
node.init = node.init.body.slice(-1)[0].body;
|
node.init = node.init.body.slice(-1)[0].body;
|
||||||
body.push(node);
|
body.push(node);
|
||||||
|
|
||||||
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
|
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
|
||||||
body: body
|
body: body
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (node instanceof AST_Scope && node !== self)
|
if (node instanceof AST_Scope && node !== self)
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user