@@ -13475,7 +13475,7 @@ Compressor.prototype.compress = function(node) {
13475
13475
def(AST_Assign, noop);
13476
13476
def(AST_Await, function(compressor, scope, no_return, in_loop) {
13477
13477
var self = this;
13478
- var inlined = sync( self.expression) .try_inline(compressor, scope, no_return, in_loop);
13478
+ var inlined = self.expression.try_inline(compressor, scope, no_return, in_loop, true );
13479
13479
if (!inlined) return;
13480
13480
if (!no_return) scan_local_returns(inlined, function(node) {
13481
13481
node.in_bool = false;
@@ -13490,35 +13490,13 @@ Compressor.prototype.compress = function(node) {
13490
13490
body: make_node(AST_Await, self, { expression: make_node(AST_Number, self, { value: 0 })}),
13491
13491
}) ],
13492
13492
});
13493
-
13494
- function sync(node) {
13495
- if (!no_return) return node;
13496
- if (node.TYPE != "Call") return node;
13497
- var fn = node.expression;
13498
- switch (fn.CTOR) {
13499
- case AST_AsyncArrow:
13500
- fn = make_node(AST_Arrow, fn, fn);
13501
- break;
13502
- case AST_AsyncFunction:
13503
- fn = make_node(AST_Function, fn, fn);
13504
- break;
13505
- case AST_AsyncGeneratorFunction:
13506
- fn = make_node(AST_GeneratorFunction, fn, fn);
13507
- break;
13508
- default:
13509
- return node;
13510
- }
13511
- node = node.clone();
13512
- node.expression = fn;
13513
- return node;
13514
- }
13515
13493
});
13516
- def(AST_Binary, function(compressor, scope, no_return, in_loop) {
13494
+ def(AST_Binary, function(compressor, scope, no_return, in_loop, in_await ) {
13517
13495
if (no_return === undefined) return;
13518
13496
var self = this;
13519
13497
var op = self.operator;
13520
13498
if (!lazy_op[op]) return;
13521
- var inlined = self.right.try_inline(compressor, scope, no_return, in_loop);
13499
+ var inlined = self.right.try_inline(compressor, scope, no_return, in_loop, in_await );
13522
13500
if (!inlined) return;
13523
13501
return make_node(AST_If, self, {
13524
13502
condition: make_condition(self.left),
@@ -13554,7 +13532,7 @@ Compressor.prototype.compress = function(node) {
13554
13532
body[last] = inlined;
13555
13533
return this;
13556
13534
});
13557
- def(AST_Call, function(compressor, scope, no_return, in_loop) {
13535
+ def(AST_Call, function(compressor, scope, no_return, in_loop, in_await ) {
13558
13536
if (compressor.option("inline") < 4) return;
13559
13537
var call = this;
13560
13538
if (call.is_expr_pure(compressor)) return;
@@ -13587,7 +13565,7 @@ Compressor.prototype.compress = function(node) {
13587
13565
}
13588
13566
defined.set("arguments", true);
13589
13567
}
13590
- var async = is_async(fn);
13568
+ var async = !in_await && is_async(fn);
13591
13569
if (async) {
13592
13570
if (!compressor.option("awaits")) return;
13593
13571
if (!is_async(scope)) return;
@@ -13629,15 +13607,40 @@ Compressor.prototype.compress = function(node) {
13629
13607
if (has_arg_refs(fn, fn.rest)) return;
13630
13608
simple_argnames = false;
13631
13609
}
13632
- if (no_return && !all(fn.body, function(stat) {
13633
- var abort = false;
13634
- stat.walk(new TreeWalker(function(node) {
13635
- if (abort) return true;
13636
- if (async && node instanceof AST_Await || node instanceof AST_Return) return abort = true;
13637
- if (node instanceof AST_Scope && node !== fn) return true;
13638
- }));
13639
- return !abort;
13640
- })) return;
13610
+ var verify_body;
13611
+ if (no_return) {
13612
+ verify_body = function(stat) {
13613
+ var abort = false;
13614
+ stat.walk(new TreeWalker(function(node) {
13615
+ if (abort) return true;
13616
+ if (async && node instanceof AST_Await || node instanceof AST_Return) return abort = true;
13617
+ if (node instanceof AST_Scope) return true;
13618
+ }));
13619
+ return !abort;
13620
+ };
13621
+ } else if (in_await && !is_async(fn)) {
13622
+ verify_body = function(stat) {
13623
+ var abort = false;
13624
+ var find_return = new TreeWalker(function(node) {
13625
+ if (abort) return true;
13626
+ if (node instanceof AST_Return) return abort = true;
13627
+ if (node instanceof AST_Scope) return true;
13628
+ });
13629
+ stat.walk(new TreeWalker(function(node) {
13630
+ if (abort) return true;
13631
+ if (node instanceof AST_Try) {
13632
+ if (node.bfinally && all(node.body, function(stat) {
13633
+ stat.walk(find_return);
13634
+ return !abort;
13635
+ }) && node.bcatch) node.bcatch.walk(find_return);
13636
+ return true;
13637
+ }
13638
+ if (node instanceof AST_Scope) return true;
13639
+ }));
13640
+ return !abort;
13641
+ };
13642
+ }
13643
+ if (verify_body && !all(fn.body, verify_body)) return;
13641
13644
if (!safe_from_await_yield(fn, avoid_await_yield(compressor, scope))) return;
13642
13645
fn.functions.each(function(def, name) {
13643
13646
scope.functions.set(name, def);
@@ -13737,10 +13740,10 @@ Compressor.prototype.compress = function(node) {
13737
13740
syms.add(def.id, sym);
13738
13741
}
13739
13742
});
13740
- def(AST_Conditional, function(compressor, scope, no_return, in_loop) {
13743
+ def(AST_Conditional, function(compressor, scope, no_return, in_loop, in_await ) {
13741
13744
var self = this;
13742
- var body = self.consequent.try_inline(compressor, scope, no_return, in_loop);
13743
- var alt = self.alternative.try_inline(compressor, scope, no_return, in_loop);
13745
+ var body = self.consequent.try_inline(compressor, scope, no_return, in_loop, in_await );
13746
+ var alt = self.alternative.try_inline(compressor, scope, no_return, in_loop, in_await );
13744
13747
if (!body && !alt) return;
13745
13748
return make_node(AST_If, self, {
13746
13749
condition: self.condition,
@@ -13775,7 +13778,7 @@ Compressor.prototype.compress = function(node) {
13775
13778
if (body) this.body = body;
13776
13779
var obj = this.object;
13777
13780
if (obj instanceof AST_Sequence) {
13778
- var inlined = inline_sequence(compressor, scope, true, in_loop, obj, 1);
13781
+ var inlined = inline_sequence(compressor, scope, true, in_loop, false, obj, 1);
13779
13782
if (inlined) {
13780
13783
this.object = obj.tail_node();
13781
13784
inlined.body.push(this);
@@ -13794,7 +13797,7 @@ Compressor.prototype.compress = function(node) {
13794
13797
}
13795
13798
var cond = this.condition;
13796
13799
if (cond instanceof AST_Sequence) {
13797
- var inlined = inline_sequence(compressor, scope, true, in_loop, cond, 1);
13800
+ var inlined = inline_sequence(compressor, scope, true, in_loop, false, cond, 1);
13798
13801
if (inlined) {
13799
13802
this.condition = cond.tail_node();
13800
13803
inlined.body.push(this);
@@ -13826,10 +13829,10 @@ Compressor.prototype.compress = function(node) {
13826
13829
var value = this.value;
13827
13830
return value && value.try_inline(compressor, scope, undefined, in_loop === "try");
13828
13831
});
13829
- function inline_sequence(compressor, scope, no_return, in_loop, node, skip) {
13832
+ function inline_sequence(compressor, scope, no_return, in_loop, in_await, node, skip) {
13830
13833
var body = [], exprs = node.expressions, no_ret = no_return;
13831
- for (var i = exprs.length - (skip || 0), j = i; --i >= 0; no_ret = true) {
13832
- var inlined = exprs[i].try_inline(compressor, scope, no_ret, in_loop);
13834
+ for (var i = exprs.length - (skip || 0), j = i; --i >= 0; no_ret = true, in_await = false ) {
13835
+ var inlined = exprs[i].try_inline(compressor, scope, no_ret, in_loop, in_await );
13833
13836
if (!inlined) continue;
13834
13837
flush();
13835
13838
body.push(inlined);
@@ -13848,8 +13851,8 @@ Compressor.prototype.compress = function(node) {
13848
13851
j = i;
13849
13852
}
13850
13853
}
13851
- def(AST_Sequence, function(compressor, scope, no_return, in_loop) {
13852
- return inline_sequence(compressor, scope, no_return, in_loop, this);
13854
+ def(AST_Sequence, function(compressor, scope, no_return, in_loop, in_await ) {
13855
+ return inline_sequence(compressor, scope, no_return, in_loop, in_await, this);
13853
13856
});
13854
13857
def(AST_SimpleStatement, function(compressor, scope, no_return, in_loop) {
13855
13858
var body = this.body;
@@ -13865,12 +13868,12 @@ Compressor.prototype.compress = function(node) {
13865
13868
});
13866
13869
return body.try_inline(compressor, scope, no_return || false, in_loop);
13867
13870
});
13868
- def(AST_UnaryPrefix, function(compressor, scope, no_return, in_loop) {
13871
+ def(AST_UnaryPrefix, function(compressor, scope, no_return, in_loop, in_await ) {
13869
13872
var self = this;
13870
13873
var op = self.operator;
13871
13874
if (unary_side_effects[op]) return;
13872
13875
if (!no_return && op == "void") no_return = false;
13873
- var inlined = self.expression.try_inline(compressor, scope, no_return, in_loop);
13876
+ var inlined = self.expression.try_inline(compressor, scope, no_return, in_loop, in_await );
13874
13877
if (!inlined) return;
13875
13878
if (!no_return) scan_local_returns(inlined, function(node) {
13876
13879
node.in_bool = false;
@@ -13888,7 +13891,7 @@ Compressor.prototype.compress = function(node) {
13888
13891
if (body) this.body = body;
13889
13892
var exp = this.expression;
13890
13893
if (exp instanceof AST_Sequence) {
13891
- var inlined = inline_sequence(compressor, scope, true, in_loop, exp, 1);
13894
+ var inlined = inline_sequence(compressor, scope, true, in_loop, false, exp, 1);
13892
13895
if (inlined) {
13893
13896
this.expression = exp.tail_node();
13894
13897
inlined.body.push(this);
0 commit comments