Skip to content

Commit 51deeff

Browse files
authored
enhance inline (#5535)
1 parent 4c227cc commit 51deeff

File tree

10 files changed

+84
-31
lines changed

10 files changed

+84
-31
lines changed

lib/compress.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13553,7 +13553,6 @@ Compressor.prototype.compress = function(node) {
1355313553
if (fn.body[0] instanceof AST_Directive) return;
1355413554
if (fn.contains_this()) return;
1355513555
if (!scope) scope = find_scope(compressor);
13556-
if (in_async_generator(scope)) return;
1355713556
var defined = new Dictionary();
1355813557
defined.set("NaN", true);
1355913558
while (!(scope instanceof AST_Scope)) {
@@ -13624,7 +13623,7 @@ Compressor.prototype.compress = function(node) {
1362413623
}));
1362513624
return !abort;
1362613625
};
13627-
} else if (in_await && !is_async(fn)) {
13626+
} else if (in_await && !is_async(fn) || in_async_generator(scope)) {
1362813627
verify_body = function(stat) {
1362913628
var abort = false;
1363013629
var find_return = new TreeWalker(function(node) {
@@ -13735,7 +13734,7 @@ Compressor.prototype.compress = function(node) {
1373513734
node.value = make_node(AST_Await, call, { expression: value });
1373613735
});
1373713736
body.push(make_node(AST_Return, call, {
13738-
value: make_node(AST_Undefined, call).transform(compressor),
13737+
value: in_async_generator(scope) ? make_node(AST_Undefined, call).transform(compressor) : null,
1373913738
}));
1374013739
}
1374113740
return inlined;

test/compress/arrows.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ issue_5414_1: {
10241024
arrows: true,
10251025
if_return: true,
10261026
inline: true,
1027-
side_effects: true,
10281027
toplevel: true,
10291028
}
10301029
input: {

test/compress/awaits.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ inline_block: {
415415
awaits: true,
416416
if_return: true,
417417
inline: true,
418-
side_effects: true,
419418
}
420419
input: {
421420
console.log("foo");
@@ -451,7 +450,6 @@ inline_block_async: {
451450
awaits: true,
452451
if_return: true,
453452
inline: true,
454-
side_effects: true,
455453
}
456454
input: {
457455
console.log("foo");

test/compress/classes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,6 @@ issue_4725_2: {
18151815
options = {
18161816
if_return: true,
18171817
inline: true,
1818-
side_effects: true,
18191818
}
18201819
input: {
18211820
"use strict";

test/compress/collapse_vars.js

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

test/compress/const.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,6 @@ issue_4261_2: {
12871287
inline: true,
12881288
reduce_funcs: true,
12891289
reduce_vars: true,
1290-
side_effects: true,
12911290
toplevel: true,
12921291
unused: true,
12931292
}

test/compress/default-values.js

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

test/compress/functions.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ empty_body: {
607607
inline_binary_and: {
608608
options = {
609609
inline: true,
610-
side_effects: true,
611610
}
612611
input: {
613612
console.log(function() {
@@ -627,9 +626,10 @@ inline_binary_and: {
627626
return "bar";
628627
}()) {
629628
while (console.log("baz"));
629+
return void "moo";
630630
return;
631631
} else
632-
return;
632+
return void 0;
633633
}());
634634
}
635635
expect_stdout: [
@@ -1121,7 +1121,6 @@ inline_return_binary: {
11211121
inline_return_conditional: {
11221122
options = {
11231123
inline: true,
1124-
side_effects: true,
11251124
}
11261125
input: {
11271126
console.log(function() {
@@ -2296,7 +2295,6 @@ duplicate_argnames_4: {
22962295
options = {
22972296
if_return: true,
22982297
inline: true,
2299-
side_effects: true,
23002298
}
23012299
input: {
23022300
(function() {
@@ -5547,7 +5545,6 @@ issue_3833_2: {
55475545
inline: true,
55485546
keep_fargs: false,
55495547
reduce_vars: true,
5550-
side_effects: true,
55515548
toplevel: true,
55525549
unused: true,
55535550
}
@@ -5613,7 +5610,6 @@ issue_3836_2: {
56135610
options = {
56145611
if_return: true,
56155612
inline: true,
5616-
side_effects: true,
56175613
}
56185614
input: {
56195615
(function() {
@@ -5871,7 +5867,6 @@ statement_var_inline: {
58715867
options = {
58725868
inline: true,
58735869
join_vars: true,
5874-
side_effects: true,
58755870
unused: true,
58765871
}
58775872
input: {
@@ -6162,7 +6157,6 @@ issue_4261: {
61626157
inline: true,
61636158
reduce_funcs: true,
61646159
reduce_vars: true,
6165-
side_effects: true,
61666160
toplevel: true,
61676161
unused: true,
61686162
}
@@ -6455,7 +6449,6 @@ issue_4659_1: {
64556449
if_return: true,
64566450
inline: true,
64576451
reduce_vars: true,
6458-
side_effects: true,
64596452
}
64606453
input: {
64616454
var a = 0;
@@ -6493,7 +6486,6 @@ issue_4659_2: {
64936486
if_return: true,
64946487
inline: true,
64956488
reduce_vars: true,
6496-
side_effects: true,
64976489
}
64986490
input: {
64996491
var a = 0;
@@ -6518,7 +6510,7 @@ issue_4659_2: {
65186510
function f() {
65196511
return a++;
65206512
}
6521-
f && a++;
6513+
void (f && a++);
65226514
(function() {
65236515
var a = console && a;
65246516
})();
@@ -6533,7 +6525,6 @@ issue_4659_3: {
65336525
if_return: true,
65346526
inline: true,
65356527
reduce_vars: true,
6536-
side_effects: true,
65376528
unused: true,
65386529
}
65396530
input: {
@@ -6740,7 +6731,6 @@ issue_4725_2: {
67406731
options = {
67416732
if_return: true,
67426733
inline: true,
6743-
side_effects: true,
67446734
}
67456735
input: {
67466736
var o = {
@@ -7725,7 +7715,6 @@ issue_5239: {
77257715
functions: true,
77267716
inline: true,
77277717
reduce_vars: true,
7728-
side_effects: true,
77297718
unused: true,
77307719
}
77317720
input: {
@@ -7741,6 +7730,7 @@ issue_5239: {
77417730
var f = void 0;
77427731
var a = 42, f = function() {};
77437732
while (console.log(f.p || a++));
7733+
return;
77447734
})();
77457735
}
77467736
expect_stdout: "42"
@@ -7843,7 +7833,7 @@ issue_5249_1: {
78437833
var a = "FAIL 1";
78447834
else if (a) {
78457835
while (console.log("FAIL 2"));
7846-
return void 0;
7836+
return;
78477837
} else
78487838
return void 0;
78497839
throw "FAIL 3";
@@ -8006,7 +7996,6 @@ issue_5264_1: {
80067996
(function(arguments) {
80077997
console.log(arguments);
80087998
while (console.log("foo"));
8009-
0;
80107999
})("bar");
80118000
return arguments;
80128001
}("baz")[0]);
@@ -8125,7 +8114,6 @@ issue_5290: {
81258114
issue_5296: {
81268115
options = {
81278116
inline: true,
8128-
side_effects: true,
81298117
}
81308118
input: {
81318119
var a = "PASS";
@@ -8388,7 +8376,6 @@ issue_5409: {
83888376
inline: true,
83898377
merge_vars: true,
83908378
reduce_vars: true,
8391-
side_effects: true,
83928379
unused: true,
83938380
}
83948381
input: {
@@ -8406,6 +8393,7 @@ issue_5409: {
84068393
a = void 0;
84078394
console.log(a && a);
84088395
while (!console);
8396+
return;
84098397
})();
84108398
}
84118399
expect_stdout: "undefined"

test/compress/spreads.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ do_inline_3: {
188188
options = {
189189
if_return: true,
190190
inline: true,
191-
side_effects: true,
192191
}
193192
input: {
194193
(function() {

test/compress/yields.js

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,8 @@ inline_nested_async: {
836836

837837
inline_nested_block: {
838838
options = {
839-
dead_code: true,
840839
if_return: true,
841840
inline: true,
842-
side_effects: true,
843841
yields: true,
844842
}
845843
input: {
@@ -859,6 +857,7 @@ inline_nested_block: {
859857
var a = function*() {
860858
for (var a of [ "foo", "bar" ])
861859
yield a;
860+
"FAIL";
862861
}(), b;
863862
do {
864863
b = a.next();
@@ -1468,6 +1467,80 @@ issue_5385_2: {
14681467
node_version: ">=10"
14691468
}
14701469

1470+
issue_5385_3: {
1471+
options = {
1472+
inline: true,
1473+
}
1474+
input: {
1475+
(async function*() {
1476+
return function() {
1477+
try {
1478+
throw console.log("foo");
1479+
} catch (e) {
1480+
return console.log("bar");
1481+
}
1482+
}();
1483+
})().next();
1484+
console.log("moo");
1485+
}
1486+
expect: {
1487+
(async function*() {
1488+
try {
1489+
throw console.log("foo");
1490+
} catch (e) {
1491+
return console.log("bar");
1492+
}
1493+
return void 0;
1494+
})().next();
1495+
console.log("moo");
1496+
}
1497+
expect_stdout: [
1498+
"foo",
1499+
"bar",
1500+
"moo",
1501+
]
1502+
node_version: ">=10"
1503+
}
1504+
1505+
issue_5385_4: {
1506+
options = {
1507+
awaits: true,
1508+
inline: true,
1509+
}
1510+
input: {
1511+
(async function*() {
1512+
return async function() {
1513+
try {
1514+
return {
1515+
then(resolve) {
1516+
resolve(console.log("FAIL"));
1517+
},
1518+
};
1519+
} finally {
1520+
return "PASS";
1521+
}
1522+
}();
1523+
})().next().then(o => console.log(o.value, o.done));
1524+
}
1525+
expect: {
1526+
(async function*() {
1527+
return async function() {
1528+
try {
1529+
return {
1530+
then(resolve) {
1531+
resolve(console.log("FAIL"));
1532+
},
1533+
};
1534+
} finally {
1535+
return "PASS";
1536+
}
1537+
}();
1538+
})().next().then(o => console.log(o.value, o.done));
1539+
}
1540+
expect_stdout: "PASS true"
1541+
node_version: ">=10"
1542+
}
1543+
14711544
issue_5425: {
14721545
options = {
14731546
assignments: true,

0 commit comments

Comments
 (0)