fix corner cases in inline (#5252)

fixes #5249
fixes #5250
This commit is contained in:
Alex Lam S.L
2022-01-02 06:59:32 +00:00
committed by GitHub
parent 87a7426598
commit aa6eb0d5be
3 changed files with 161 additions and 3 deletions

View File

@@ -12831,7 +12831,36 @@ Compressor.prototype.compress = function(node) {
def(AST_Node, noop);
def(AST_Assign, noop);
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) {
if (no_return === undefined) return;
@@ -12843,7 +12872,7 @@ Compressor.prototype.compress = function(node) {
return make_node(AST_If, self, {
condition: make_condition(self.left),
body: inlined,
alternative: null,
alternative: no_return ? null : make_node(AST_Return, self, { value: null }),
});
function make_condition(cond) {