@@ -10,6 +10,7 @@ namespace ts {
1010 NoNodeConverters = 1 << 1 ,
1111 // Ensures new `PropertyAccessExpression` nodes are created with the `NoIndentation` emit flag set.
1212 NoIndentationOnFreshPropertyAccess = 1 << 2 ,
13+ NoOriginalNode = 1 << 3 ,
1314 }
1415
1516 /**
@@ -22,6 +23,7 @@ namespace ts {
2223 // Lazily load the parenthesizer, node converters, and some factory methods until they are used.
2324 const parenthesizerRules = memoize ( ( ) => flags & NodeFactoryFlags . NoParenthesizerRules ? nullParenthesizerRules : createParenthesizerRules ( factory ) ) ;
2425 const converters = memoize ( ( ) => flags & NodeFactoryFlags . NoNodeConverters ? nullNodeConverters : createNodeConverters ( factory ) ) ;
26+ const update = flags & NodeFactoryFlags . NoOriginalNode ? updateWithoutOriginal : updateWithOriginal ;
2527
2628 // lazy initializaton of common operator factories
2729 const getBinaryCreateFunction = memoizeOne ( ( operator : BinaryOperator ) => ( left : Expression , right : Expression ) => createBinaryExpression ( left , operator , right ) ) ;
@@ -553,7 +555,13 @@ namespace ts {
553555 modifiers
554556 ) ;
555557 node . name = asName ( name ) ;
556- node . transformFlags |= propagateChildFlags ( node . name ) ;
558+ node . transformFlags |=
559+ kind === SyntaxKind . MethodDeclaration ||
560+ kind === SyntaxKind . GetAccessor ||
561+ kind === SyntaxKind . SetAccessor ||
562+ kind === SyntaxKind . PropertyDeclaration ?
563+ propagatePropertyNameFlags ( node . name ) :
564+ propagateChildFlags ( node . name ) ;
557565 return node ;
558566 }
559567
@@ -820,6 +828,9 @@ namespace ts {
820828 // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations
821829 node . typeArguments = createNodeArray ( typeArguments ) ;
822830 }
831+ if ( node . originalKeywordKind === SyntaxKind . AwaitKeyword ) {
832+ node . transformFlags |= TransformFlags . ContainsPossibleTopLevelAwait ;
833+ }
823834 return node ;
824835 }
825836
@@ -2090,7 +2101,7 @@ namespace ts {
20902101 node . name = asName ( name ) ;
20912102 node . transformFlags =
20922103 propagateChildFlags ( node . expression ) |
2093- propagateChildFlags ( node . name ) ;
2104+ propagatePropertyNameFlags ( node . name ) ;
20942105 if ( isSuperKeyword ( expression ) ) {
20952106 // super method calls require a lexical 'this'
20962107 // super method calls require 'super' hoisting in ES2017 and ES2018 async functions and async generators
@@ -4754,7 +4765,7 @@ namespace ts {
47544765 hasNoDefaultLib : boolean ,
47554766 libReferences : readonly FileReference [ ]
47564767 ) {
4757- const node = createBaseNode < SourceFile > ( SyntaxKind . SourceFile ) ;
4768+ const node = baseFactory . createBaseSourceFileNode ( SyntaxKind . SourceFile ) as Mutable < SourceFile > ;
47584769 for ( const p in source ) {
47594770 if ( p === "emitNode" || hasProperty ( node , p ) || ! hasProperty ( source , p ) ) continue ;
47604771 ( node as any ) [ p ] = ( source as any ) [ p ] ;
@@ -5681,7 +5692,15 @@ namespace ts {
56815692 }
56825693 }
56835694
5684- function update < T extends Node > ( updated : T , original : T ) : T {
5695+ function updateWithoutOriginal < T extends Node > ( updated : T , original : T ) : T {
5696+ if ( updated !== original ) {
5697+ setOriginalNode ( updated , original ) ;
5698+ setTextRange ( updated , original ) ;
5699+ }
5700+ return updated ;
5701+ }
5702+
5703+ function updateWithOriginal < T extends Node > ( updated : T , original : T ) : T {
56855704 if ( updated !== original ) {
56865705 setOriginalNode ( updated , original ) ;
56875706 setTextRange ( updated , original ) ;
@@ -5766,14 +5785,23 @@ namespace ts {
57665785 return tokenValue ;
57675786 }
57685787
5769- function propagatePropertyNameFlags ( node : PropertyName , transformFlags : TransformFlags ) {
5788+ function propagatePropertyNameFlags ( node : Node | undefined ) {
5789+ if ( ! node ) return TransformFlags . None ;
5790+ // `await` in a property name should not be considered a possible top-level await keyword
5791+ const transformFlags = propagateChildFlags ( node ) ;
5792+ return isIdentifier ( node ) ?
5793+ transformFlags & ~ TransformFlags . ContainsPossibleTopLevelAwait :
5794+ transformFlags ;
5795+ }
5796+
5797+ function propagatePropertyNameFlagsOfChild ( node : PropertyName , transformFlags : TransformFlags ) {
57705798 return transformFlags | ( node . transformFlags & TransformFlags . PropertyNamePropagatingFlags ) ;
57715799 }
57725800
57735801 function propagateChildFlags ( child : Node | undefined ) : TransformFlags {
57745802 if ( ! child ) return TransformFlags . None ;
57755803 const childFlags = child . transformFlags & ~ getTransformFlagsSubtreeExclusions ( child . kind ) ;
5776- return isNamedDeclaration ( child ) && isPropertyName ( child . name ) ? propagatePropertyNameFlags ( child . name , childFlags ) : childFlags ;
5804+ return isNamedDeclaration ( child ) && isPropertyName ( child . name ) ? propagatePropertyNameFlagsOfChild ( child . name , childFlags ) : childFlags ;
57775805 }
57785806
57795807 function propagateChildrenFlags ( children : NodeArray < Node > | undefined ) : TransformFlags {
0 commit comments