@@ -866,7 +866,9 @@ impl Actual {
866866///
867867/// `_asyncToGenerator(function*() {})` from `async function() {}`;
868868fn make_fn_ref ( mut expr : FnExpr , should_not_bind_this : bool ) -> Expr {
869- expr. function . body = expr. function . body . fold_with ( & mut AsyncFnBodyHandler ) ;
869+ expr. function . body = expr. function . body . fold_with ( & mut AsyncFnBodyHandler {
870+ is_async_generator : expr. function . is_generator ,
871+ } ) ;
870872
871873 assert ! ( expr. function. is_async) ;
872874 expr. function . is_async = false ;
@@ -901,7 +903,9 @@ fn make_fn_ref(mut expr: FnExpr, should_not_bind_this: bool) -> Expr {
901903 } )
902904}
903905
904- struct AsyncFnBodyHandler ;
906+ struct AsyncFnBodyHandler {
907+ is_async_generator : bool ,
908+ }
905909
906910macro_rules! noop {
907911 ( $name: ident, $T: path) => {
@@ -924,11 +928,28 @@ impl Fold for AsyncFnBodyHandler {
924928 let expr = expr. fold_children_with ( self ) ;
925929
926930 match expr {
927- Expr :: Await ( AwaitExpr { span, arg } ) => Expr :: Yield ( YieldExpr {
928- span,
929- delegate : false ,
930- arg : Some ( arg) ,
931- } ) ,
931+ Expr :: Await ( AwaitExpr { span, arg } ) => {
932+ if self . is_async_generator {
933+ let callee = helper ! ( await_async_generator, "awaitAsyncGenerator" ) ;
934+ let arg = Box :: new ( Expr :: Call ( CallExpr {
935+ span,
936+ callee,
937+ args : vec ! [ arg. as_arg( ) ] ,
938+ type_args : Default :: default ( ) ,
939+ } ) ) ;
940+ Expr :: Yield ( YieldExpr {
941+ span,
942+ delegate : false ,
943+ arg : Some ( arg) ,
944+ } )
945+ } else {
946+ Expr :: Yield ( YieldExpr {
947+ span,
948+ delegate : false ,
949+ arg : Some ( arg) ,
950+ } )
951+ }
952+ }
932953 _ => expr,
933954 }
934955 }
0 commit comments