fix corner case
add tests
This commit is contained in:
parent
30ea1a2006
commit
a296df2dec
|
|
@ -3418,7 +3418,7 @@ merge(Compressor.prototype, {
|
||||||
|
|
||||||
function if_break_in_loop(self, compressor) {
|
function if_break_in_loop(self, compressor) {
|
||||||
var first = self.body instanceof AST_BlockStatement ? self.body.body[0] : self.body;
|
var first = self.body instanceof AST_BlockStatement ? self.body.body[0] : self.body;
|
||||||
if (is_break(first)) {
|
if (compressor.option("dead_code") && is_break(first)) {
|
||||||
var body = [];
|
var body = [];
|
||||||
if (self.init instanceof AST_Statement) {
|
if (self.init instanceof AST_Statement) {
|
||||||
body.push(self.init);
|
body.push(self.init);
|
||||||
|
|
@ -3432,6 +3432,7 @@ merge(Compressor.prototype, {
|
||||||
body: self.condition
|
body: self.condition
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
extract_declarations_from_unreachable_code(compressor, self.body, body);
|
||||||
return make_node(AST_BlockStatement, self, {
|
return make_node(AST_BlockStatement, self, {
|
||||||
body: body
|
body: body
|
||||||
});
|
});
|
||||||
|
|
@ -3481,7 +3482,7 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
self = if_break_in_loop(self, compressor);
|
self = if_break_in_loop(self, compressor);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
OPT(AST_For, function(self, compressor){
|
OPT(AST_For, function(self, compressor){
|
||||||
if (!compressor.option("loops")) return self;
|
if (!compressor.option("loops")) return self;
|
||||||
|
|
|
||||||
|
|
@ -495,6 +495,7 @@ dead_code_condition: {
|
||||||
|
|
||||||
issue_2740_1: {
|
issue_2740_1: {
|
||||||
options = {
|
options = {
|
||||||
|
dead_code: true,
|
||||||
loops: true,
|
loops: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|
@ -521,6 +522,7 @@ issue_2740_1: {
|
||||||
|
|
||||||
issue_2740_2: {
|
issue_2740_2: {
|
||||||
options = {
|
options = {
|
||||||
|
dead_code: true,
|
||||||
loops: true,
|
loops: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
}
|
}
|
||||||
|
|
@ -533,3 +535,73 @@ issue_2740_2: {
|
||||||
x();
|
x();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2740_3: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
|
L2: for (var y = 0; y < 2; y++) {
|
||||||
|
break L1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
L1: for (var x = 0; x < 3; x++)
|
||||||
|
for (var y = 0; y < 2; y++)
|
||||||
|
break L1;
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect_stdout: "0 0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_4: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
|
L2: for (var y = 0; y < 2; y++) {
|
||||||
|
break L2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (var x = 0; x < 3; x++) {
|
||||||
|
var y = 0;
|
||||||
|
y < 2;
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect_stdout: "3 0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_5: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
|
break L1;
|
||||||
|
L2: for (var y = 0; y < 2; y++) {
|
||||||
|
break L2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = 0;
|
||||||
|
x < 3;
|
||||||
|
var y;
|
||||||
|
console.log(x,y);
|
||||||
|
}
|
||||||
|
expect_stdout: "0 undefined"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user