@@ -957,6 +957,9 @@ namespace ts {
957
957
const postLoopLabel = createBranchLabel ( ) ;
958
958
addAntecedent ( preLoopLabel , currentFlow ) ;
959
959
currentFlow = preLoopLabel ;
960
+ if ( node . kind === SyntaxKind . ForOfStatement ) {
961
+ bind ( node . awaitModifier ) ;
962
+ }
960
963
bind ( node . expression ) ;
961
964
addAntecedent ( postLoopLabel , currentFlow ) ;
962
965
bind ( node . initializer ) ;
@@ -2407,7 +2410,7 @@ namespace ts {
2407
2410
2408
2411
function bindFunctionDeclaration ( node : FunctionDeclaration ) {
2409
2412
if ( ! isDeclarationFile ( file ) && ! isInAmbientContext ( node ) ) {
2410
- if ( isAsyncFunctionLike ( node ) ) {
2413
+ if ( isAsyncFunction ( node ) ) {
2411
2414
emitFlags |= NodeFlags . HasAsyncFunctions ;
2412
2415
}
2413
2416
}
@@ -2424,7 +2427,7 @@ namespace ts {
2424
2427
2425
2428
function bindFunctionExpression ( node : FunctionExpression ) {
2426
2429
if ( ! isDeclarationFile ( file ) && ! isInAmbientContext ( node ) ) {
2427
- if ( isAsyncFunctionLike ( node ) ) {
2430
+ if ( isAsyncFunction ( node ) ) {
2428
2431
emitFlags |= NodeFlags . HasAsyncFunctions ;
2429
2432
}
2430
2433
}
@@ -2438,7 +2441,7 @@ namespace ts {
2438
2441
2439
2442
function bindPropertyOrMethodOrAccessor ( node : Declaration , symbolFlags : SymbolFlags , symbolExcludes : SymbolFlags ) {
2440
2443
if ( ! isDeclarationFile ( file ) && ! isInAmbientContext ( node ) ) {
2441
- if ( isAsyncFunctionLike ( node ) ) {
2444
+ if ( isAsyncFunction ( node ) ) {
2442
2445
emitFlags |= NodeFlags . HasAsyncFunctions ;
2443
2446
}
2444
2447
}
@@ -2872,11 +2875,10 @@ namespace ts {
2872
2875
2873
2876
// An async method declaration is ES2017 syntax.
2874
2877
if ( hasModifier ( node , ModifierFlags . Async ) ) {
2875
- transformFlags |= TransformFlags . AssertES2017 ;
2878
+ transformFlags |= node . asteriskToken ? TransformFlags . AssertESNext : TransformFlags . AssertES2017 ;
2876
2879
}
2877
2880
2878
- // Currently, we only support generators that were originally async function bodies.
2879
- if ( node . asteriskToken && getEmitFlags ( node ) & EmitFlags . AsyncFunctionBody ) {
2881
+ if ( node . asteriskToken ) {
2880
2882
transformFlags |= TransformFlags . AssertGenerator ;
2881
2883
}
2882
2884
@@ -2942,7 +2944,7 @@ namespace ts {
2942
2944
2943
2945
// An async function declaration is ES2017 syntax.
2944
2946
if ( modifierFlags & ModifierFlags . Async ) {
2945
- transformFlags |= TransformFlags . AssertES2017 ;
2947
+ transformFlags |= node . asteriskToken ? TransformFlags . AssertESNext : TransformFlags . AssertES2017 ;
2946
2948
}
2947
2949
2948
2950
// function declarations with object rest destructuring are ES Next syntax
@@ -2962,7 +2964,7 @@ namespace ts {
2962
2964
// down-level generator.
2963
2965
// Currently we do not support transforming any other generator fucntions
2964
2966
// down level.
2965
- if ( node . asteriskToken && getEmitFlags ( node ) & EmitFlags . AsyncFunctionBody ) {
2967
+ if ( node . asteriskToken ) {
2966
2968
transformFlags |= TransformFlags . AssertGenerator ;
2967
2969
}
2968
2970
}
@@ -2984,7 +2986,7 @@ namespace ts {
2984
2986
2985
2987
// An async function expression is ES2017 syntax.
2986
2988
if ( hasModifier ( node , ModifierFlags . Async ) ) {
2987
- transformFlags |= TransformFlags . AssertES2017 ;
2989
+ transformFlags |= node . asteriskToken ? TransformFlags . AssertESNext : TransformFlags . AssertES2017 ;
2988
2990
}
2989
2991
2990
2992
// function expressions with object rest destructuring are ES Next syntax
@@ -3003,9 +3005,7 @@ namespace ts {
3003
3005
// If a FunctionExpression is generator function and is the body of a
3004
3006
// transformed async function, then this node can be transformed to a
3005
3007
// down-level generator.
3006
- // Currently we do not support transforming any other generator fucntions
3007
- // down level.
3008
- if ( node . asteriskToken && getEmitFlags ( node ) & EmitFlags . AsyncFunctionBody ) {
3008
+ if ( node . asteriskToken ) {
3009
3009
transformFlags |= TransformFlags . AssertGenerator ;
3010
3010
}
3011
3011
@@ -3173,8 +3173,8 @@ namespace ts {
3173
3173
switch ( kind ) {
3174
3174
case SyntaxKind . AsyncKeyword :
3175
3175
case SyntaxKind . AwaitExpression :
3176
- // async/await is ES2017 syntax
3177
- transformFlags |= TransformFlags . AssertES2017 ;
3176
+ // async/await is ES2017 syntax, but may be ESNext syntax (for async generators)
3177
+ transformFlags |= TransformFlags . AssertESNext | TransformFlags . AssertES2017 ;
3178
3178
break ;
3179
3179
3180
3180
case SyntaxKind . PublicKeyword :
@@ -3206,10 +3206,6 @@ namespace ts {
3206
3206
transformFlags |= TransformFlags . AssertJsx ;
3207
3207
break ;
3208
3208
3209
- case SyntaxKind . ForOfStatement :
3210
- // for-of might be ESNext if it has a rest destructuring
3211
- transformFlags |= TransformFlags . AssertESNext ;
3212
- // FALLTHROUGH
3213
3209
case SyntaxKind . NoSubstitutionTemplateLiteral :
3214
3210
case SyntaxKind . TemplateHead :
3215
3211
case SyntaxKind . TemplateMiddle :
@@ -3223,9 +3219,18 @@ namespace ts {
3223
3219
transformFlags |= TransformFlags . AssertES2015 ;
3224
3220
break ;
3225
3221
3222
+ case SyntaxKind . ForOfStatement :
3223
+ // This node is either ES2015 syntax or ES2017 syntax (if it is a for-await-of).
3224
+ if ( ( < ForOfStatement > node ) . awaitModifier ) {
3225
+ transformFlags |= TransformFlags . AssertESNext ;
3226
+ }
3227
+ transformFlags |= TransformFlags . AssertES2015 ;
3228
+ break ;
3229
+
3226
3230
case SyntaxKind . YieldExpression :
3227
- // This node is ES6 syntax.
3228
- transformFlags |= TransformFlags . AssertES2015 | TransformFlags . ContainsYield ;
3231
+ // This node is either ES2015 syntax (in a generator) or ES2017 syntax (in an async
3232
+ // generator).
3233
+ transformFlags |= TransformFlags . AssertESNext | TransformFlags . AssertES2015 | TransformFlags . ContainsYield ;
3229
3234
break ;
3230
3235
3231
3236
case SyntaxKind . AnyKeyword :
0 commit comments