parent
87a7426598
commit
aa6eb0d5be
|
|
@ -12831,7 +12831,36 @@ Compressor.prototype.compress = function(node) {
|
||||||
def(AST_Node, noop);
|
def(AST_Node, noop);
|
||||||
def(AST_Assign, noop);
|
def(AST_Assign, noop);
|
||||||
def(AST_Await, function(compressor, scope, no_return, in_loop) {
|
def(AST_Await, function(compressor, scope, no_return, in_loop) {
|
||||||
return this.expression.try_inline(compressor, scope, no_return, in_loop);
|
var self = this;
|
||||||
|
var inlined = sync(self.expression).try_inline(compressor, scope, no_return, in_loop);
|
||||||
|
if (!inlined) return;
|
||||||
|
return aborts(inlined) ? inlined : make_node(AST_BlockStatement, self, {
|
||||||
|
body: [ inlined, make_node(AST_SimpleStatement, self, {
|
||||||
|
body: make_node(AST_Await, self, { expression: make_node(AST_Number, self, { value: 0 })}),
|
||||||
|
}) ],
|
||||||
|
});
|
||||||
|
|
||||||
|
function sync(node) {
|
||||||
|
if (!no_return) return node;
|
||||||
|
if (node.TYPE != "Call") return node;
|
||||||
|
var fn = node.expression;
|
||||||
|
switch (fn.CTOR) {
|
||||||
|
case AST_AsyncArrow:
|
||||||
|
fn = make_node(AST_Arrow, fn, fn);
|
||||||
|
break;
|
||||||
|
case AST_AsyncFunction:
|
||||||
|
fn = make_node(AST_Function, fn, fn);
|
||||||
|
break;
|
||||||
|
case AST_AsyncGeneratorFunction:
|
||||||
|
fn = make_node(AST_GeneratorFunction, fn, fn);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
node = node.clone();
|
||||||
|
node.expression = fn;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
def(AST_Binary, function(compressor, scope, no_return, in_loop) {
|
def(AST_Binary, function(compressor, scope, no_return, in_loop) {
|
||||||
if (no_return === undefined) return;
|
if (no_return === undefined) return;
|
||||||
|
|
@ -12843,7 +12872,7 @@ Compressor.prototype.compress = function(node) {
|
||||||
return make_node(AST_If, self, {
|
return make_node(AST_If, self, {
|
||||||
condition: make_condition(self.left),
|
condition: make_condition(self.left),
|
||||||
body: inlined,
|
body: inlined,
|
||||||
alternative: null,
|
alternative: no_return ? null : make_node(AST_Return, self, { value: null }),
|
||||||
});
|
});
|
||||||
|
|
||||||
function make_condition(cond) {
|
function make_condition(cond) {
|
||||||
|
|
|
||||||
|
|
@ -512,6 +512,42 @@ inline_block_await: {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline_block_await_async: {
|
inline_block_await_async: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(async function() {
|
||||||
|
console.log("foo");
|
||||||
|
await (async function() {
|
||||||
|
while (await console.log("bar"));
|
||||||
|
console.log("baz");
|
||||||
|
})();
|
||||||
|
console.log("moo");
|
||||||
|
})().then(console.log);
|
||||||
|
console.log("moz");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(async function() {
|
||||||
|
console.log("foo");
|
||||||
|
while (await console.log("bar"));
|
||||||
|
console.log("baz");
|
||||||
|
await 0;
|
||||||
|
console.log("moo");
|
||||||
|
})().then(console.log);
|
||||||
|
console.log("moz");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
"moz",
|
||||||
|
"baz",
|
||||||
|
"moo",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=8"
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_block_await_async_return: {
|
||||||
options = {
|
options = {
|
||||||
awaits: true,
|
awaits: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
|
|
@ -2540,3 +2576,32 @@ issue_5177: {
|
||||||
expect_stdout: "function"
|
expect_stdout: "function"
|
||||||
node_version: ">=8"
|
node_version: ">=8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5250: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(async function() {
|
||||||
|
await function() {
|
||||||
|
while (console.log("foo"));
|
||||||
|
}();
|
||||||
|
console.log("bar");
|
||||||
|
})();
|
||||||
|
console.log("baz");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(async function() {
|
||||||
|
while (console.log("foo"));
|
||||||
|
await 0;
|
||||||
|
console.log("bar");
|
||||||
|
})();
|
||||||
|
console.log("baz");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"baz",
|
||||||
|
"bar",
|
||||||
|
]
|
||||||
|
node_version: ">=8"
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -628,7 +628,8 @@ inline_binary_and: {
|
||||||
while (console.log("baz"));
|
while (console.log("baz"));
|
||||||
return void "moo";
|
return void "moo";
|
||||||
return;
|
return;
|
||||||
}
|
} else
|
||||||
|
return;
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
|
|
@ -7686,3 +7687,66 @@ issue_5240_2: {
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5249_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
if (!console)
|
||||||
|
var a = "FAIL 1";
|
||||||
|
else
|
||||||
|
return void (a && function() {
|
||||||
|
while (console.log("FAIL 2"));
|
||||||
|
}());
|
||||||
|
throw "FAIL 3";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
if (!console)
|
||||||
|
var a = "FAIL 1";
|
||||||
|
else if (a) {
|
||||||
|
while (console.log("FAIL 2"));
|
||||||
|
return;
|
||||||
|
} else
|
||||||
|
return;
|
||||||
|
throw "FAIL 3";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5249_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
if (!console)
|
||||||
|
var a = "FAIL 1";
|
||||||
|
else
|
||||||
|
return void (a && function() {
|
||||||
|
while (console.log("FAIL 2"));
|
||||||
|
}());
|
||||||
|
throw "FAIL 3";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
if (!console)
|
||||||
|
throw "FAIL 3";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user