@@ -240,11 +240,14 @@ namespace ts {
240
240
// ES6 export and default modifiers are elided when inside a namespace.
241
241
return currentNamespace ? undefined : node ;
242
242
243
+ case SyntaxKind . AsyncKeyword :
244
+ // Async keyword is not elided for target ES8
245
+ return languageVersion < ScriptTarget . ES8 ? undefined : node ;
246
+
243
247
case SyntaxKind . PublicKeyword :
244
248
case SyntaxKind . PrivateKeyword :
245
249
case SyntaxKind . ProtectedKeyword :
246
250
case SyntaxKind . AbstractKeyword :
247
- case SyntaxKind . AsyncKeyword :
248
251
case SyntaxKind . ConstKeyword :
249
252
case SyntaxKind . DeclareKeyword :
250
253
case SyntaxKind . ReadonlyKeyword :
@@ -2223,6 +2226,14 @@ namespace ts {
2223
2226
/*location*/ node
2224
2227
) ;
2225
2228
2229
+ // Add ES8 async function expression modifier
2230
+ // Not sure this is the right place? Might be better to move this
2231
+ // into createFunctionExpression itself.
2232
+ if ( ( languageVersion >= ScriptTarget . ES8 ) && isAsyncFunctionLike ( node ) ) {
2233
+ const funcModifiers = visitNodes ( node . modifiers , visitor , isModifier ) ;
2234
+ func . modifiers = createNodeArray ( funcModifiers ) ;
2235
+ }
2236
+
2226
2237
setOriginalNode ( func , node ) ;
2227
2238
2228
2239
return func ;
@@ -2235,7 +2246,7 @@ namespace ts {
2235
2246
*/
2236
2247
function visitArrowFunction ( node : ArrowFunction ) {
2237
2248
const func = createArrowFunction (
2238
- /* modifiers*/ undefined ,
2249
+ visitNodes ( node . modifiers , visitor , isModifier ) ,
2239
2250
/*typeParameters*/ undefined ,
2240
2251
visitNodes ( node . parameters , visitor , isParameter ) ,
2241
2252
/*type*/ undefined ,
@@ -2250,7 +2261,7 @@ namespace ts {
2250
2261
}
2251
2262
2252
2263
function transformFunctionBody ( node : MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression ) : FunctionBody {
2253
- if ( isAsyncFunctionLike ( node ) ) {
2264
+ if ( isAsyncFunctionLike ( node ) && languageVersion < ScriptTarget . ES8 ) {
2254
2265
return < FunctionBody > transformAsyncFunctionBody ( node ) ;
2255
2266
}
2256
2267
@@ -2270,7 +2281,7 @@ namespace ts {
2270
2281
}
2271
2282
2272
2283
function transformConciseBody ( node : ArrowFunction ) : ConciseBody {
2273
- if ( isAsyncFunctionLike ( node ) ) {
2284
+ if ( isAsyncFunctionLike ( node ) && languageVersion < ScriptTarget . ES8 ) {
2274
2285
return transformAsyncFunctionBody ( node ) ;
2275
2286
}
2276
2287
@@ -2453,14 +2464,28 @@ namespace ts {
2453
2464
* @param node The await expression node.
2454
2465
*/
2455
2466
function visitAwaitExpression ( node : AwaitExpression ) : Expression {
2467
+ const targetAtLeastES8 = languageVersion >= ScriptTarget . ES8 ;
2456
2468
return setOriginalNode (
2457
- createYield (
2469
+ targetAtLeastES8 ? createAwaitExpression ( ) : createYieldExpression ( ) ,
2470
+ node
2471
+ ) ;
2472
+
2473
+ function createAwaitExpression ( ) {
2474
+ const awaitExpression = createAwait (
2475
+ visitNode ( node . expression , visitor , isExpression ) ,
2476
+ /*location*/ node
2477
+ ) ;
2478
+ return awaitExpression ;
2479
+ }
2480
+
2481
+ function createYieldExpression ( ) {
2482
+ const yieldExpression = createYield (
2458
2483
/*asteriskToken*/ undefined ,
2459
2484
visitNode ( node . expression , visitor , isExpression ) ,
2460
2485
/*location*/ node
2461
- ) ,
2462
- node
2463
- ) ;
2486
+ ) ;
2487
+ return yieldExpression ;
2488
+ }
2464
2489
}
2465
2490
2466
2491
/**
0 commit comments