Skip to content

Commit

Permalink
fix corner cases in if_return
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Jul 29, 2022
1 parent 08c386f commit 115b2cd
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3647,14 +3647,14 @@ Compressor.prototype.compress = function(node) {
if (!(ab instanceof AST_Return)) return false;
var value = ab.value;
if (value && !is_undefined(value.tail_node())) return false;
if (self instanceof AST_SwitchBranch) merge_jump = 4;
if (jump instanceof AST_Break && self instanceof AST_SwitchBranch) merge_jump = 4;
return true;
}
if (!(ab instanceof AST_LoopControl)) return false;
if (jump && self instanceof AST_SwitchBranch) merge_jump = true;
var lct = compressor.loopcontrol_target(ab);
if (ab instanceof AST_Continue) return match_target(loop_body(lct));
if (lct instanceof AST_IterationStatement) return false;
if (jump) merge_jump = jump.equals(ab);
return match_target(lct);
}

Expand Down
65 changes: 65 additions & 0 deletions test/compress/if_return.js
Original file line number Diff line number Diff line change
Expand Up @@ -1588,3 +1588,68 @@ switch_return_4: {
"bar",
]
}

issue_5583: {
options = {
conditionals: true,
if_return: true,
side_effects: true,
}
input: {
do {
switch (console) {
default:
if (!console.log("foo"))
continue;
break;
case console.log("bar"):
FAIL;
}
} while (console.log("baz"));
}
expect: {
do {
switch (console) {
default:
console.log("foo");
break;
case console.log("bar"):
FAIL;
}
} while (console.log("baz"));
}
expect_stdout: [
"bar",
"foo",
"baz",
]
}

issue_5584: {
options = {
conditionals: true,
if_return: true,
}
input: {
function f(a) {
switch (a) {
case 42:
if (!console.log("PASS"))
return;
return FAIL;
}
}
f(42);
}
expect: {
function f(a) {
switch (a) {
case 42:
if (console.log("PASS"))
return FAIL;
}
}
f(42);
}
expect_stdout: "PASS"
}

0 comments on commit 115b2cd

Please sign in to comment.