Skip to content

Commit f1b3e9d

Browse files
authored
fix corner case in inline (#5527)
fixes #5526
1 parent fcc87ed commit f1b3e9d

File tree

11 files changed

+72
-11
lines changed

11 files changed

+72
-11
lines changed

lib/compress.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13523,7 +13523,9 @@ Compressor.prototype.compress = function(node) {
1352313523
return make_node(AST_If, self, {
1352413524
condition: make_condition(self.left),
1352513525
body: inlined,
13526-
alternative: no_return ? null : make_node(AST_Return, self, { value: null }),
13526+
alternative: no_return ? null : make_node(AST_Return, self, {
13527+
value: make_node(AST_Undefined, self).transform(compressor),
13528+
}),
1352713529
});
1352813530

1352913531
function make_condition(cond) {
@@ -13723,7 +13725,9 @@ Compressor.prototype.compress = function(node) {
1372313725
if (is_undefined(value)) return;
1372413726
node.value = make_node(AST_Await, call, { expression: value });
1372513727
});
13726-
body.push(make_node(AST_Return, call, { value: null }));
13728+
body.push(make_node(AST_Return, call, {
13729+
value: make_node(AST_Undefined, call).transform(compressor),
13730+
}));
1372713731
}
1372813732
return inlined;
1372913733

test/compress/arrows.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ issue_5414_1: {
10241024
arrows: true,
10251025
if_return: true,
10261026
inline: true,
1027+
side_effects: true,
10271028
toplevel: true,
10281029
}
10291030
input: {

test/compress/awaits.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ inline_block: {
415415
awaits: true,
416416
if_return: true,
417417
inline: true,
418+
side_effects: true,
418419
}
419420
input: {
420421
console.log("foo");
@@ -450,6 +451,7 @@ inline_block_async: {
450451
awaits: true,
451452
if_return: true,
452453
inline: true,
454+
side_effects: true,
453455
}
454456
input: {
455457
console.log("foo");

test/compress/classes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@ issue_4725_2: {
18151815
options = {
18161816
if_return: true,
18171817
inline: true,
1818+
side_effects: true,
18181819
}
18191820
input: {
18201821
"use strict";

test/compress/collapse_vars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9611,6 +9611,7 @@ inline_throw: {
96119611
collapse_vars: true,
96129612
inline: true,
96139613
keep_fargs: false,
9614+
side_effects: true,
96149615
unused: true,
96159616
}
96169617
input: {
@@ -9630,7 +9631,6 @@ inline_throw: {
96309631
try {
96319632
(function(a) {
96329633
throw a;
9633-
return;
96349634
})("PASS");
96359635
} catch (e) {
96369636
console.log(e);

test/compress/const.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ issue_4261_2: {
12871287
inline: true,
12881288
reduce_funcs: true,
12891289
reduce_vars: true,
1290+
side_effects: true,
12901291
toplevel: true,
12911292
unused: true,
12921293
}

test/compress/default-values.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,7 @@ issue_5057_4: {
19301930
var b = "FAIL 2";
19311931
(function(a = console.log("FAIL 1")) {})(b);
19321932
console.log(a);
1933+
0;
19331934
})("PASS");
19341935
}
19351936
expect_stdout: "PASS"

test/compress/functions.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ empty_body: {
607607
inline_binary_and: {
608608
options = {
609609
inline: true,
610+
side_effects: true,
610611
}
611612
input: {
612613
console.log(function() {
@@ -626,7 +627,6 @@ inline_binary_and: {
626627
return "bar";
627628
}()) {
628629
while (console.log("baz"));
629-
return void "moo";
630630
return;
631631
} else
632632
return;
@@ -1121,6 +1121,7 @@ inline_return_binary: {
11211121
inline_return_conditional: {
11221122
options = {
11231123
inline: true,
1124+
side_effects: true,
11241125
}
11251126
input: {
11261127
console.log(function() {
@@ -2295,6 +2296,7 @@ duplicate_argnames_4: {
22952296
options = {
22962297
if_return: true,
22972298
inline: true,
2299+
side_effects: true,
22982300
}
22992301
input: {
23002302
(function() {
@@ -5545,6 +5547,7 @@ issue_3833_2: {
55455547
inline: true,
55465548
keep_fargs: false,
55475549
reduce_vars: true,
5550+
side_effects: true,
55485551
toplevel: true,
55495552
unused: true,
55505553
}
@@ -5582,7 +5585,7 @@ issue_3835: {
55825585
return f();
55835586
})();
55845587
}
5585-
expect_stdout: true
5588+
expect_stdout: RangeError("Maximum call stack size exceeded")
55865589
}
55875590

55885591
issue_3836_1: {
@@ -5610,6 +5613,7 @@ issue_3836_2: {
56105613
options = {
56115614
if_return: true,
56125615
inline: true,
5616+
side_effects: true,
56135617
}
56145618
input: {
56155619
(function() {
@@ -5867,6 +5871,7 @@ statement_var_inline: {
58675871
options = {
58685872
inline: true,
58695873
join_vars: true,
5874+
side_effects: true,
58705875
unused: true,
58715876
}
58725877
input: {
@@ -6157,6 +6162,7 @@ issue_4261: {
61576162
inline: true,
61586163
reduce_funcs: true,
61596164
reduce_vars: true,
6165+
side_effects: true,
61606166
toplevel: true,
61616167
unused: true,
61626168
}
@@ -6449,6 +6455,7 @@ issue_4659_1: {
64496455
if_return: true,
64506456
inline: true,
64516457
reduce_vars: true,
6458+
side_effects: true,
64526459
}
64536460
input: {
64546461
var a = 0;
@@ -6486,6 +6493,7 @@ issue_4659_2: {
64866493
if_return: true,
64876494
inline: true,
64886495
reduce_vars: true,
6496+
side_effects: true,
64896497
}
64906498
input: {
64916499
var a = 0;
@@ -6510,7 +6518,7 @@ issue_4659_2: {
65106518
function f() {
65116519
return a++;
65126520
}
6513-
void (f && a++);
6521+
f && a++;
65146522
(function() {
65156523
var a = console && a;
65166524
})();
@@ -6525,6 +6533,7 @@ issue_4659_3: {
65256533
if_return: true,
65266534
inline: true,
65276535
reduce_vars: true,
6536+
side_effects: true,
65286537
unused: true,
65296538
}
65306539
input: {
@@ -6731,6 +6740,7 @@ issue_4725_2: {
67316740
options = {
67326741
if_return: true,
67336742
inline: true,
6743+
side_effects: true,
67346744
}
67356745
input: {
67366746
var o = {
@@ -7715,6 +7725,7 @@ issue_5239: {
77157725
functions: true,
77167726
inline: true,
77177727
reduce_vars: true,
7728+
side_effects: true,
77187729
unused: true,
77197730
}
77207731
input: {
@@ -7730,7 +7741,6 @@ issue_5239: {
77307741
var f = void 0;
77317742
var a = 42, f = function() {};
77327743
while (console.log(f.p || a++));
7733-
return;
77347744
})();
77357745
}
77367746
expect_stdout: "42"
@@ -7833,9 +7843,9 @@ issue_5249_1: {
78337843
var a = "FAIL 1";
78347844
else if (a) {
78357845
while (console.log("FAIL 2"));
7836-
return;
7846+
return void 0;
78377847
} else
7838-
return;
7848+
return void 0;
78397849
throw "FAIL 3";
78407850
}());
78417851
}
@@ -7996,6 +8006,7 @@ issue_5264_1: {
79968006
(function(arguments) {
79978007
console.log(arguments);
79988008
while (console.log("foo"));
8009+
0;
79998010
})("bar");
80008011
return arguments;
80018012
}("baz")[0]);
@@ -8114,6 +8125,7 @@ issue_5290: {
81148125
issue_5296: {
81158126
options = {
81168127
inline: true,
8128+
side_effects: true,
81178129
}
81188130
input: {
81198131
var a = "PASS";
@@ -8376,6 +8388,7 @@ issue_5409: {
83768388
inline: true,
83778389
merge_vars: true,
83788390
reduce_vars: true,
8391+
side_effects: true,
83798392
unused: true,
83808393
}
83818394
input: {
@@ -8393,7 +8406,6 @@ issue_5409: {
83938406
a = void 0;
83948407
console.log(a && a);
83958408
while (!console);
8396-
return;
83978409
})();
83988410
}
83998411
expect_stdout: "undefined"

test/compress/nullish.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ issue_4679: {
308308
issue_5266: {
309309
options = {
310310
inline: true,
311+
side_effects: true,
311312
}
312313
input: {
313314
[

test/compress/spreads.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ do_inline_3: {
188188
options = {
189189
if_return: true,
190190
inline: true,
191+
side_effects: true,
191192
}
192193
input: {
193194
(function() {

0 commit comments

Comments
 (0)