Skip to content

Commit

Permalink
fix corner case in if_return (#5603)
Browse files Browse the repository at this point in the history
fixes #5602
  • Loading branch information
alexlamsl committed Aug 5, 2022
1 parent 8a07f12 commit a9d9af5
Show file tree
Hide file tree
Showing 2 changed files with 52 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 @@ -3595,8 +3595,8 @@ Compressor.prototype.compress = function(node) {
stat = stat.clone();
exprs.push(stat.condition);
stat.condition = make_sequence(stat, exprs);
stat.alternative = make_node(AST_BlockStatement, next, {
body: extract_functions().concat(make_node(AST_Return, next, { value: null })),
stat.alternative = make_node(AST_BlockStatement, self, {
body: extract_functions().concat(make_node(AST_Return, self, { value: null })),
});
statements[i] = stat.transform(compressor);
i = prev + 1;
Expand Down
50 changes: 50 additions & 0 deletions test/compress/spreads.js
Original file line number Diff line number Diff line change
Expand Up @@ -1203,3 +1203,53 @@ issue_5382: {
expect_stdout: "PASS"
node_version: ">=8.3.0"
}

issue_5602: {
options = {
collapse_vars: true,
conditionals: true,
evaluate: true,
if_return: true,
inline: true,
passes: 2,
sequences: true,
spreads: true,
unused: true,
}
input: {
(function() {
try {
var b = function(c) {
if (c)
return FAIL;
var d = 42;
}(...[ null, A = 0 ]);
} catch (e) {
b();
}
})();
console.log(A);
}
expect: {
(function() {
try {
var b = void (A = 0);
} catch (e) {
b();
}
})(),
console.log(A);
}
expect_stdout: "0"
expect_warnings: [
"INFO: Dropping unused variable d [test/compress/spreads.js:6,24]",
"INFO: Collapsing c [test/compress/spreads.js:4,24]",
"INFO: Dropping unused variable c [test/compress/spreads.js:3,33]",
"INFO: pass 0: last_count: Infinity, count: 27",
"WARN: Condition always false [test/compress/spreads.js:4,20]",
"INFO: Collapsing null [test/compress/spreads.js:7,23]",
"INFO: Collapsing 0 [test/compress/spreads.js:3,24]",
"INFO: pass 1: last_count: 27, count: 22",
]
node_version: ">=6"
}

0 comments on commit a9d9af5

Please sign in to comment.