@@ -161,6 +161,7 @@ impl BlockScoping {
161
161
has_break : false ,
162
162
has_return : false ,
163
163
has_yield : false ,
164
+ has_await : false ,
164
165
label : IndexMap :: new ( ) ,
165
166
inner_label : AHashSet :: default ( ) ,
166
167
mutated,
@@ -222,7 +223,7 @@ impl BlockScoping {
222
223
decorators : Default :: default ( ) ,
223
224
body : Some ( body_stmt) ,
224
225
is_generator : flow_helper. has_yield ,
225
- is_async : false ,
226
+ is_async : flow_helper . has_await ,
226
227
type_params : None ,
227
228
return_type : None ,
228
229
}
@@ -243,6 +244,14 @@ impl BlockScoping {
243
244
}
244
245
. into ( ) ;
245
246
247
+ if flow_helper. has_await {
248
+ call = AwaitExpr {
249
+ span : DUMMY_SP ,
250
+ arg : call. into ( ) ,
251
+ }
252
+ . into ( ) ;
253
+ }
254
+
246
255
if flow_helper. has_yield {
247
256
call = YieldExpr {
248
257
span : DUMMY_SP ,
@@ -616,6 +625,7 @@ struct FlowHelper<'a> {
616
625
has_break : bool ,
617
626
has_return : bool ,
618
627
has_yield : bool ,
628
+ has_await : bool ,
619
629
620
630
// label cannot be shadowed, so it's pretty safe to use JsWord
621
631
label : IndexMap < JsWord , Label > ,
@@ -657,18 +667,6 @@ impl VisitMut for FlowHelper<'_> {
657
667
/// noop
658
668
fn visit_mut_arrow_expr ( & mut self , _n : & mut ArrowExpr ) { }
659
669
660
- fn visit_mut_yield_expr ( & mut self , e : & mut YieldExpr ) {
661
- e. visit_mut_children_with ( self ) ;
662
-
663
- self . has_yield = true ;
664
- }
665
-
666
- fn visit_mut_labeled_stmt ( & mut self , l : & mut LabeledStmt ) {
667
- self . inner_label . insert ( l. label . sym . clone ( ) ) ;
668
-
669
- l. visit_mut_children_with ( self ) ;
670
- }
671
-
672
670
fn visit_mut_assign_expr ( & mut self , n : & mut AssignExpr ) {
673
671
match & n. left {
674
672
PatOrExpr :: Expr ( e) => {
@@ -688,6 +686,12 @@ impl VisitMut for FlowHelper<'_> {
688
686
n. visit_mut_children_with ( self ) ;
689
687
}
690
688
689
+ fn visit_mut_await_expr ( & mut self , e : & mut AwaitExpr ) {
690
+ e. visit_mut_children_with ( self ) ;
691
+
692
+ self . has_await = true ;
693
+ }
694
+
691
695
/// https://github.com/swc-project/swc/pull/2916
692
696
fn visit_mut_do_while_stmt ( & mut self , s : & mut DoWhileStmt ) {
693
697
let old = self . in_nested_loop ;
@@ -723,6 +727,12 @@ impl VisitMut for FlowHelper<'_> {
723
727
/// noop
724
728
fn visit_mut_function ( & mut self , _f : & mut Function ) { }
725
729
730
+ fn visit_mut_labeled_stmt ( & mut self , l : & mut LabeledStmt ) {
731
+ self . inner_label . insert ( l. label . sym . clone ( ) ) ;
732
+
733
+ l. visit_mut_children_with ( self ) ;
734
+ }
735
+
726
736
fn visit_mut_stmt ( & mut self , node : & mut Stmt ) {
727
737
let span = node. span ( ) ;
728
738
@@ -822,6 +832,12 @@ impl VisitMut for FlowHelper<'_> {
822
832
s. visit_mut_children_with ( self ) ;
823
833
self . in_nested_loop = old;
824
834
}
835
+
836
+ fn visit_mut_yield_expr ( & mut self , e : & mut YieldExpr ) {
837
+ e. visit_mut_children_with ( self ) ;
838
+
839
+ self . has_yield = true ;
840
+ }
825
841
}
826
842
827
843
struct MutationHandler < ' a > {
0 commit comments