Skip to content

Commit 887e086

Browse files
authored
fix corner case in if_return (#5620)
fixes #5619
1 parent 8602d1b commit 887e086

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

Diff for: lib/compress.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3620,7 +3620,7 @@ Compressor.prototype.compress = function(node) {
36203620
continue;
36213621
}
36223622

3623-
if (jump && jump === next) eliminate_returns(stat);
3623+
if (declare_only && jump && jump === next) eliminate_returns(stat);
36243624
}
36253625
return changed;
36263626

@@ -3787,6 +3787,7 @@ Compressor.prototype.compress = function(node) {
37873787
if (stat instanceof AST_Exit) {
37883788
var mode = match_return(stat, true);
37893789
if (mode) {
3790+
changed = true;
37903791
var value = trim_return(stat.value, mode);
37913792
if (value) return make_node(AST_SimpleStatement, value, { body: value });
37923793
return in_block ? null : make_node(AST_EmptyStatement, stat);

Diff for: test/compress/if_return.js

+53
Original file line numberDiff line numberDiff line change
@@ -2305,3 +2305,56 @@ issue_5597: {
23052305
}
23062306
expect_stdout: "PASS"
23072307
}
2308+
2309+
issue_5619_1: {
2310+
options = {
2311+
if_return: true,
2312+
}
2313+
input: {
2314+
console.log(function() {
2315+
if (console)
2316+
if (console)
2317+
return "PASS";
2318+
var a = FAIL;
2319+
return "PASS";
2320+
}());
2321+
}
2322+
expect: {
2323+
console.log(function() {
2324+
if (console)
2325+
if (console)
2326+
return "PASS";
2327+
var a = FAIL;
2328+
return "PASS";
2329+
}());
2330+
}
2331+
expect_stdout: "PASS"
2332+
}
2333+
2334+
issue_5619_2: {
2335+
options = {
2336+
dead_code: true,
2337+
if_return: true,
2338+
loops: true,
2339+
}
2340+
input: {
2341+
console.log(function() {
2342+
if (console)
2343+
while (console)
2344+
return "PASS";
2345+
var a = FAIL;
2346+
return "PASS";
2347+
}());
2348+
}
2349+
expect: {
2350+
console.log(function() {
2351+
if (console) {
2352+
if (console)
2353+
return "PASS";
2354+
}
2355+
var a = FAIL;
2356+
return "PASS";
2357+
}());
2358+
}
2359+
expect_stdout: "PASS"
2360+
}

0 commit comments

Comments
 (0)