Skip to content

Commit

Permalink
fix corner case in if_return (#5620)
Browse files Browse the repository at this point in the history
fixes #5619
  • Loading branch information
alexlamsl authored Aug 17, 2022
1 parent 8602d1b commit 887e086
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3620,7 +3620,7 @@ Compressor.prototype.compress = function(node) {
continue;
}

if (jump && jump === next) eliminate_returns(stat);
if (declare_only && jump && jump === next) eliminate_returns(stat);
}
return changed;

Expand Down Expand Up @@ -3787,6 +3787,7 @@ Compressor.prototype.compress = function(node) {
if (stat instanceof AST_Exit) {
var mode = match_return(stat, true);
if (mode) {
changed = true;
var value = trim_return(stat.value, mode);
if (value) return make_node(AST_SimpleStatement, value, { body: value });
return in_block ? null : make_node(AST_EmptyStatement, stat);
Expand Down
53 changes: 53 additions & 0 deletions test/compress/if_return.js
Original file line number Diff line number Diff line change
Expand Up @@ -2305,3 +2305,56 @@ issue_5597: {
}
expect_stdout: "PASS"
}

issue_5619_1: {
options = {
if_return: true,
}
input: {
console.log(function() {
if (console)
if (console)
return "PASS";
var a = FAIL;
return "PASS";
}());
}
expect: {
console.log(function() {
if (console)
if (console)
return "PASS";
var a = FAIL;
return "PASS";
}());
}
expect_stdout: "PASS"
}

issue_5619_2: {
options = {
dead_code: true,
if_return: true,
loops: true,
}
input: {
console.log(function() {
if (console)
while (console)
return "PASS";
var a = FAIL;
return "PASS";
}());
}
expect: {
console.log(function() {
if (console) {
if (console)
return "PASS";
}
var a = FAIL;
return "PASS";
}());
}
expect_stdout: "PASS"
}

0 comments on commit 887e086

Please sign in to comment.