enhance inline (#5535)
This commit is contained in:
@@ -13553,7 +13553,6 @@ Compressor.prototype.compress = function(node) {
|
|||||||
if (fn.body[0] instanceof AST_Directive) return;
|
if (fn.body[0] instanceof AST_Directive) return;
|
||||||
if (fn.contains_this()) return;
|
if (fn.contains_this()) return;
|
||||||
if (!scope) scope = find_scope(compressor);
|
if (!scope) scope = find_scope(compressor);
|
||||||
if (in_async_generator(scope)) return;
|
|
||||||
var defined = new Dictionary();
|
var defined = new Dictionary();
|
||||||
defined.set("NaN", true);
|
defined.set("NaN", true);
|
||||||
while (!(scope instanceof AST_Scope)) {
|
while (!(scope instanceof AST_Scope)) {
|
||||||
@@ -13624,7 +13623,7 @@ Compressor.prototype.compress = function(node) {
|
|||||||
}));
|
}));
|
||||||
return !abort;
|
return !abort;
|
||||||
};
|
};
|
||||||
} else if (in_await && !is_async(fn)) {
|
} else if (in_await && !is_async(fn) || in_async_generator(scope)) {
|
||||||
verify_body = function(stat) {
|
verify_body = function(stat) {
|
||||||
var abort = false;
|
var abort = false;
|
||||||
var find_return = new TreeWalker(function(node) {
|
var find_return = new TreeWalker(function(node) {
|
||||||
@@ -13735,7 +13734,7 @@ Compressor.prototype.compress = function(node) {
|
|||||||
node.value = make_node(AST_Await, call, { expression: value });
|
node.value = make_node(AST_Await, call, { expression: value });
|
||||||
});
|
});
|
||||||
body.push(make_node(AST_Return, call, {
|
body.push(make_node(AST_Return, call, {
|
||||||
value: make_node(AST_Undefined, call).transform(compressor),
|
value: in_async_generator(scope) ? make_node(AST_Undefined, call).transform(compressor) : null,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return inlined;
|
return inlined;
|
||||||
|
|||||||
@@ -1024,7 +1024,6 @@ issue_5414_1: {
|
|||||||
arrows: true,
|
arrows: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -415,7 +415,6 @@ inline_block: {
|
|||||||
awaits: true,
|
awaits: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log("foo");
|
console.log("foo");
|
||||||
@@ -451,7 +450,6 @@ inline_block_async: {
|
|||||||
awaits: true,
|
awaits: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log("foo");
|
console.log("foo");
|
||||||
|
|||||||
@@ -1815,7 +1815,6 @@ issue_4725_2: {
|
|||||||
options = {
|
options = {
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|||||||
@@ -9611,7 +9611,6 @@ inline_throw: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -9631,6 +9630,7 @@ inline_throw: {
|
|||||||
try {
|
try {
|
||||||
(function(a) {
|
(function(a) {
|
||||||
throw a;
|
throw a;
|
||||||
|
return;
|
||||||
})("PASS");
|
})("PASS");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|||||||
@@ -1287,7 +1287,6 @@ issue_4261_2: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1930,7 +1930,6 @@ issue_5057_4: {
|
|||||||
var b = "FAIL 2";
|
var b = "FAIL 2";
|
||||||
(function(a = console.log("FAIL 1")) {})(b);
|
(function(a = console.log("FAIL 1")) {})(b);
|
||||||
console.log(a);
|
console.log(a);
|
||||||
0;
|
|
||||||
})("PASS");
|
})("PASS");
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
|
|||||||
@@ -607,7 +607,6 @@ empty_body: {
|
|||||||
inline_binary_and: {
|
inline_binary_and: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(function() {
|
console.log(function() {
|
||||||
@@ -627,9 +626,10 @@ inline_binary_and: {
|
|||||||
return "bar";
|
return "bar";
|
||||||
}()) {
|
}()) {
|
||||||
while (console.log("baz"));
|
while (console.log("baz"));
|
||||||
|
return void "moo";
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
return;
|
return void 0;
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
@@ -1121,7 +1121,6 @@ inline_return_binary: {
|
|||||||
inline_return_conditional: {
|
inline_return_conditional: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(function() {
|
console.log(function() {
|
||||||
@@ -2296,7 +2295,6 @@ duplicate_argnames_4: {
|
|||||||
options = {
|
options = {
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
(function() {
|
(function() {
|
||||||
@@ -5547,7 +5545,6 @@ issue_3833_2: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -5613,7 +5610,6 @@ issue_3836_2: {
|
|||||||
options = {
|
options = {
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
(function() {
|
(function() {
|
||||||
@@ -5871,7 +5867,6 @@ statement_var_inline: {
|
|||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -6162,7 +6157,6 @@ issue_4261: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -6455,7 +6449,6 @@ issue_4659_1: {
|
|||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 0;
|
var a = 0;
|
||||||
@@ -6493,7 +6486,6 @@ issue_4659_2: {
|
|||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 0;
|
var a = 0;
|
||||||
@@ -6518,7 +6510,7 @@ issue_4659_2: {
|
|||||||
function f() {
|
function f() {
|
||||||
return a++;
|
return a++;
|
||||||
}
|
}
|
||||||
f && a++;
|
void (f && a++);
|
||||||
(function() {
|
(function() {
|
||||||
var a = console && a;
|
var a = console && a;
|
||||||
})();
|
})();
|
||||||
@@ -6533,7 +6525,6 @@ issue_4659_3: {
|
|||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -6740,7 +6731,6 @@ issue_4725_2: {
|
|||||||
options = {
|
options = {
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = {
|
var o = {
|
||||||
@@ -7725,7 +7715,6 @@ issue_5239: {
|
|||||||
functions: true,
|
functions: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -7741,6 +7730,7 @@ issue_5239: {
|
|||||||
var f = void 0;
|
var f = void 0;
|
||||||
var a = 42, f = function() {};
|
var a = 42, f = function() {};
|
||||||
while (console.log(f.p || a++));
|
while (console.log(f.p || a++));
|
||||||
|
return;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
@@ -7843,7 +7833,7 @@ issue_5249_1: {
|
|||||||
var a = "FAIL 1";
|
var a = "FAIL 1";
|
||||||
else if (a) {
|
else if (a) {
|
||||||
while (console.log("FAIL 2"));
|
while (console.log("FAIL 2"));
|
||||||
return void 0;
|
return;
|
||||||
} else
|
} else
|
||||||
return void 0;
|
return void 0;
|
||||||
throw "FAIL 3";
|
throw "FAIL 3";
|
||||||
@@ -8006,7 +7996,6 @@ issue_5264_1: {
|
|||||||
(function(arguments) {
|
(function(arguments) {
|
||||||
console.log(arguments);
|
console.log(arguments);
|
||||||
while (console.log("foo"));
|
while (console.log("foo"));
|
||||||
0;
|
|
||||||
})("bar");
|
})("bar");
|
||||||
return arguments;
|
return arguments;
|
||||||
}("baz")[0]);
|
}("baz")[0]);
|
||||||
@@ -8125,7 +8114,6 @@ issue_5290: {
|
|||||||
issue_5296: {
|
issue_5296: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = "PASS";
|
var a = "PASS";
|
||||||
@@ -8388,7 +8376,6 @@ issue_5409: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
merge_vars: true,
|
merge_vars: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -8406,6 +8393,7 @@ issue_5409: {
|
|||||||
a = void 0;
|
a = void 0;
|
||||||
console.log(a && a);
|
console.log(a && a);
|
||||||
while (!console);
|
while (!console);
|
||||||
|
return;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ do_inline_3: {
|
|||||||
options = {
|
options = {
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
@@ -836,10 +836,8 @@ inline_nested_async: {
|
|||||||
|
|
||||||
inline_nested_block: {
|
inline_nested_block: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
|
||||||
yields: true,
|
yields: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -859,6 +857,7 @@ inline_nested_block: {
|
|||||||
var a = function*() {
|
var a = function*() {
|
||||||
for (var a of [ "foo", "bar" ])
|
for (var a of [ "foo", "bar" ])
|
||||||
yield a;
|
yield a;
|
||||||
|
"FAIL";
|
||||||
}(), b;
|
}(), b;
|
||||||
do {
|
do {
|
||||||
b = a.next();
|
b = a.next();
|
||||||
@@ -1468,6 +1467,80 @@ issue_5385_2: {
|
|||||||
node_version: ">=10"
|
node_version: ">=10"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5385_3: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(async function*() {
|
||||||
|
return function() {
|
||||||
|
try {
|
||||||
|
throw console.log("foo");
|
||||||
|
} catch (e) {
|
||||||
|
return console.log("bar");
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
})().next();
|
||||||
|
console.log("moo");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(async function*() {
|
||||||
|
try {
|
||||||
|
throw console.log("foo");
|
||||||
|
} catch (e) {
|
||||||
|
return console.log("bar");
|
||||||
|
}
|
||||||
|
return void 0;
|
||||||
|
})().next();
|
||||||
|
console.log("moo");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
"moo",
|
||||||
|
]
|
||||||
|
node_version: ">=10"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5385_4: {
|
||||||
|
options = {
|
||||||
|
awaits: true,
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(async function*() {
|
||||||
|
return async function() {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
then(resolve) {
|
||||||
|
resolve(console.log("FAIL"));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
})().next().then(o => console.log(o.value, o.done));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(async function*() {
|
||||||
|
return async function() {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
then(resolve) {
|
||||||
|
resolve(console.log("FAIL"));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
})().next().then(o => console.log(o.value, o.done));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS true"
|
||||||
|
node_version: ">=10"
|
||||||
|
}
|
||||||
|
|
||||||
issue_5425: {
|
issue_5425: {
|
||||||
options = {
|
options = {
|
||||||
assignments: true,
|
assignments: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user