@@ -3854,9 +3854,9 @@ Compressor.prototype.compress = function(node) {
|
||||
return j;
|
||||
}
|
||||
|
||||
function eliminate_returns(stat, in_block) {
|
||||
function eliminate_returns(stat, keep_throws, in_block) {
|
||||
if (stat instanceof AST_Exit) {
|
||||
var mode = match_return(stat, true);
|
||||
var mode = !(keep_throws && stat instanceof AST_Throw) && match_return(stat, true);
|
||||
if (mode) {
|
||||
changed = true;
|
||||
var value = trim_return(stat.value, mode);
|
||||
@@ -3864,18 +3864,18 @@ Compressor.prototype.compress = function(node) {
|
||||
return in_block ? null : make_node(AST_EmptyStatement, stat);
|
||||
}
|
||||
} else if (stat instanceof AST_If) {
|
||||
stat.body = eliminate_returns(stat.body);
|
||||
if (stat.alternative) stat.alternative = eliminate_returns(stat.alternative);
|
||||
stat.body = eliminate_returns(stat.body, keep_throws);
|
||||
if (stat.alternative) stat.alternative = eliminate_returns(stat.alternative, keep_throws);
|
||||
} else if (stat instanceof AST_LabeledStatement) {
|
||||
stat.body = eliminate_returns(stat.body);
|
||||
stat.body = eliminate_returns(stat.body, keep_throws);
|
||||
} else if (stat instanceof AST_Try) {
|
||||
if (!stat.bfinally || !jump.value || jump.value.is_constant()) {
|
||||
if (stat.bcatch) eliminate_returns(stat.bcatch);
|
||||
var trimmed = eliminate_returns(stat.body.pop(), true);
|
||||
if (stat.bcatch) eliminate_returns(stat.bcatch, keep_throws);
|
||||
var trimmed = eliminate_returns(stat.body.pop(), true, true);
|
||||
if (trimmed) stat.body.push(trimmed);
|
||||
}
|
||||
} else if (stat instanceof AST_Block && !(stat instanceof AST_Scope || stat instanceof AST_Switch)) {
|
||||
var trimmed = eliminate_returns(stat.body.pop(), true);
|
||||
var trimmed = eliminate_returns(stat.body.pop(), keep_throws, true);
|
||||
if (trimmed) stat.body.push(trimmed);
|
||||
}
|
||||
return stat;
|
||||
|
||||
@@ -2385,3 +2385,30 @@ issue_5619_2: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5649: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
try {
|
||||
throw new Error("FAIL");
|
||||
} catch (e) {
|
||||
return "PASS";
|
||||
}
|
||||
throw new Error("FAIL");
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
try {
|
||||
throw new Error("FAIL");
|
||||
} catch (e) {
|
||||
return "PASS";
|
||||
}
|
||||
throw new Error("FAIL");
|
||||
}());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user