@@ -240,11 +240,14 @@ namespace ts {
240240 // ES6 export and default modifiers are elided when inside a namespace.
241241 return currentNamespace ? undefined : node ;
242242
243+ case SyntaxKind . AsyncKeyword :
244+ // Async keyword is not elided for target ES8
245+ return languageVersion < ScriptTarget . ES8 ? undefined : node ;
246+
243247 case SyntaxKind . PublicKeyword :
244248 case SyntaxKind . PrivateKeyword :
245249 case SyntaxKind . ProtectedKeyword :
246250 case SyntaxKind . AbstractKeyword :
247- case SyntaxKind . AsyncKeyword :
248251 case SyntaxKind . ConstKeyword :
249252 case SyntaxKind . DeclareKeyword :
250253 case SyntaxKind . ReadonlyKeyword :
@@ -2223,6 +2226,14 @@ namespace ts {
22232226 /*location*/ node
22242227 ) ;
22252228
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+
22262237 setOriginalNode ( func , node ) ;
22272238
22282239 return func ;
@@ -2235,7 +2246,7 @@ namespace ts {
22352246 */
22362247 function visitArrowFunction ( node : ArrowFunction ) {
22372248 const func = createArrowFunction (
2238- /* modifiers*/ undefined ,
2249+ visitNodes ( node . modifiers , visitor , isModifier ) ,
22392250 /*typeParameters*/ undefined ,
22402251 visitNodes ( node . parameters , visitor , isParameter ) ,
22412252 /*type*/ undefined ,
@@ -2250,7 +2261,7 @@ namespace ts {
22502261 }
22512262
22522263 function transformFunctionBody ( node : MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression ) : FunctionBody {
2253- if ( isAsyncFunctionLike ( node ) ) {
2264+ if ( isAsyncFunctionLike ( node ) && languageVersion < ScriptTarget . ES8 ) {
22542265 return < FunctionBody > transformAsyncFunctionBody ( node ) ;
22552266 }
22562267
@@ -2270,7 +2281,7 @@ namespace ts {
22702281 }
22712282
22722283 function transformConciseBody ( node : ArrowFunction ) : ConciseBody {
2273- if ( isAsyncFunctionLike ( node ) ) {
2284+ if ( isAsyncFunctionLike ( node ) && languageVersion < ScriptTarget . ES8 ) {
22742285 return transformAsyncFunctionBody ( node ) ;
22752286 }
22762287
@@ -2453,14 +2464,28 @@ namespace ts {
24532464 * @param node The await expression node.
24542465 */
24552466 function visitAwaitExpression ( node : AwaitExpression ) : Expression {
2467+ const targetAtLeastES8 = languageVersion >= ScriptTarget . ES8 ;
24562468 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 (
24582483 /*asteriskToken*/ undefined ,
24592484 visitNode ( node . expression , visitor , isExpression ) ,
24602485 /*location*/ node
2461- ) ,
2462- node
2463- ) ;
2486+ ) ;
2487+ return yieldExpression ;
2488+ }
24642489 }
24652490
24662491 /**
0 commit comments