fix corner case in if_return (#5650)

fixes #5649
This commit is contained in:
Alex Lam S.L
2022-09-08 03:49:05 +01:00
committed by GitHub
parent 32bd65a87f
commit 4e4a2f8ed3
2 changed files with 35 additions and 8 deletions

View File

@@ -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;