@@ -2090,26 +2090,32 @@ merge(Compressor.prototype, {
|
|||||||
return maintain_this_binding(tt.parent(), node, node.right.transform(tt));
|
return maintain_this_binding(tt.parent(), node, node.right.transform(tt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// certain combination of unused name + side effect leads to:
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/44
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/1830
|
||||||
|
// that's an invalid AST.
|
||||||
|
// We fix it at this stage by moving the `var` outside the `for`.
|
||||||
if (node instanceof AST_For) {
|
if (node instanceof AST_For) {
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
|
|
||||||
if (node.init instanceof AST_BlockStatement) {
|
if (node.init instanceof AST_BlockStatement) {
|
||||||
// certain combination of unused name + side effect leads to:
|
var block = node.init;
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/44
|
node.init = block.body.pop();
|
||||||
// that's an invalid AST.
|
block.body.push(node);
|
||||||
// We fix it at this stage by moving the `var` outside the `for`.
|
return in_list ? MAP.splice(block.body) : block;
|
||||||
|
|
||||||
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
|
|
||||||
});
|
|
||||||
} else if (is_empty(node.init)) {
|
} else if (is_empty(node.init)) {
|
||||||
node.init = null;
|
node.init = null;
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
if (node instanceof AST_LabeledStatement && node.body instanceof AST_For) {
|
||||||
|
descend(node, this);
|
||||||
|
if (node.body instanceof AST_BlockStatement) {
|
||||||
|
var block = node.body;
|
||||||
|
node.body = block.body.pop();
|
||||||
|
block.body.push(node);
|
||||||
|
return in_list ? MAP.splice(block.body) : block;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope && node !== self)
|
if (node instanceof AST_Scope && node !== self)
|
||||||
return node;
|
return node;
|
||||||
|
|||||||
@@ -1056,3 +1056,38 @@ drop_var: {
|
|||||||
"3 2",
|
"3 2",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1830_1: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function() {
|
||||||
|
L: for (var b = console.log(1); !1;) continue L;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
L: for (console.log(1); !1;) continue L;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1830_2: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function() {
|
||||||
|
L: for (var a = 1, b = console.log(a); --a;) continue L;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
var a = 1;
|
||||||
|
L: for (console.log(a); --a;) continue L;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user