fix corner cases in dead_code & if_return (#5525)
fixes #5521 fixes #5522 fixes #5523 fixes #5524
This commit is contained in:
@@ -1953,7 +1953,7 @@ Compressor.prototype.compress = function(node) {
|
||||
function last_of(compressor, predicate) {
|
||||
var block = compressor.self(), level = 0;
|
||||
do {
|
||||
if (block instanceof AST_Catch || block instanceof AST_Finally) {
|
||||
if (block instanceof AST_Catch) {
|
||||
block = compressor.parent(level++);
|
||||
} else if (block instanceof AST_LabeledStatement) {
|
||||
block = block.body;
|
||||
@@ -1968,7 +1968,6 @@ Compressor.prototype.compress = function(node) {
|
||||
} while (stat
|
||||
&& (block instanceof AST_BlockStatement
|
||||
|| block instanceof AST_Catch
|
||||
|| block instanceof AST_Finally
|
||||
|| block instanceof AST_Scope
|
||||
|| block instanceof AST_Try)
|
||||
&& is_last_statement(block.body, stat));
|
||||
@@ -3690,7 +3689,7 @@ Compressor.prototype.compress = function(node) {
|
||||
function eliminate_dead_code(statements, compressor) {
|
||||
var has_quit;
|
||||
var self = compressor.self();
|
||||
if (self instanceof AST_Catch || self instanceof AST_Finally) {
|
||||
if (self instanceof AST_Catch) {
|
||||
self = compressor.parent();
|
||||
} else if (self instanceof AST_LabeledStatement) {
|
||||
self = self.body;
|
||||
|
||||
@@ -963,3 +963,57 @@ issue_4374: {
|
||||
}
|
||||
expect_stdout: "0"
|
||||
}
|
||||
|
||||
issue_5521: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_5523: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
FAIL;
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
FAIL;
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
@@ -230,7 +230,6 @@ labels_12: {
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
if_return: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
L: try {
|
||||
@@ -246,13 +245,14 @@ labels_12: {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
L: try {
|
||||
if (!console.log("foo"))
|
||||
throw "bar";
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
console.log("baz")
|
||||
if (console.log("baz"))
|
||||
break L;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
@@ -381,3 +381,53 @@ issue_4466_2_toplevel_v8: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5522: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
L: try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
return "PASS";
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
L: try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
return "PASS";
|
||||
}());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5524: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
L: try {
|
||||
FAIL;
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
L: try {
|
||||
FAIL;
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user