Skip to content

Commit

Permalink
fix corner case in if_return (#5689)
Browse files Browse the repository at this point in the history
fixes #5688
  • Loading branch information
alexlamsl committed Sep 29, 2022
1 parent e1e3516 commit 6cdc035
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/compress.js
Expand Up @@ -3745,14 +3745,17 @@ Compressor.prototype.compress = function(node) {
return true;
}
if (!(ab instanceof AST_LoopControl)) return false;
if (jump && self instanceof AST_SwitchBranch) {
if (self instanceof AST_SwitchBranch) {
if (jump instanceof AST_Exit) {
if (!in_lambda) return false;
if (jump.value) return false;
} else if (compressor.loopcontrol_target(jump) !== parent) {
merge_jump = true;
} else if (jump) {
if (compressor.loopcontrol_target(jump) !== parent) return false;
merge_jump = true;
} else if (jump === false) {
return false;
}
merge_jump = true;
}
var lct = compressor.loopcontrol_target(ab);
if (ab instanceof AST_Continue) return match_target(loop_body(lct));
Expand Down Expand Up @@ -3789,7 +3792,7 @@ Compressor.prototype.compress = function(node) {
end = statements.lastIndexOf(stop);
} else {
stop = statements[end];
if (stop !== jump) jump = null;
if (stop !== jump) jump = false;
}
var tail = statements.splice(start, end - start).filter(function(stat) {
if (stat instanceof AST_LambdaDefinition) {
Expand Down
11 changes: 11 additions & 0 deletions test/compress.js
Expand Up @@ -126,6 +126,17 @@ function parse_test(file) {
croak(node);
}
var name = node.left.name;
assert.ok([
"beautify",
"expression",
"mangle",
"options",
"rename",
].indexOf(name) >= 0, tmpl("Unsupported setting {name} [{line},{col}]", {
name: name,
line: node.start.line,
col: node.start.col,
}));
test[name] = evaluate(node.right);
return true;
}
Expand Down
38 changes: 38 additions & 0 deletions test/compress/if_return.js
Expand Up @@ -2442,3 +2442,41 @@ issue_5649: {
}
expect_stdout: "PASS"
}

issue_5688: {
options = {
conditionals: true,
if_return: true,
}
input: {
L: do {
switch (console) {
default:
if (console)
break;
if (FAIL_1)
;
else
break L;
break;
case 42:
FAIL_2;
}
} while (console.log("PASS"));
}
expect: {
L: do {
switch (console) {
default:
if (console)
break;
if (FAIL_1)
break;
break L;
case 42:
FAIL_2;
}
} while (console.log("PASS"));
}
expect_stdout: "PASS"
}

0 comments on commit 6cdc035

Please sign in to comment.