@@ -1000,6 +1000,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
10001000 const saveExceptionTarget = currentExceptionTarget ;
10011001 const saveActiveLabelList = activeLabelList ;
10021002 const saveHasExplicitReturn = hasExplicitReturn ;
1003+ const saveSeenThisKeyword = seenThisKeyword ;
10031004 const isImmediatelyInvoked = (
10041005 containerFlags & ContainerFlags . IsFunctionExpression &&
10051006 ! hasSyntacticModifier ( node , ModifierFlags . Async ) &&
@@ -1022,19 +1023,22 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
10221023 currentContinueTarget = undefined ;
10231024 activeLabelList = undefined ;
10241025 hasExplicitReturn = false ;
1026+ seenThisKeyword = false ;
10251027 bindChildren ( node ) ;
1026- // Reset all reachability check related flags on node (for incremental scenarios)
1027- node . flags &= ~ NodeFlags . ReachabilityAndEmitFlags ;
1028+ // Reset flags (for incremental scenarios)
1029+ node . flags &= ~ ( NodeFlags . ReachabilityAndEmitFlags | NodeFlags . ContainsThis ) ;
10281030 if ( ! ( currentFlow . flags & FlowFlags . Unreachable ) && containerFlags & ContainerFlags . IsFunctionLike && nodeIsPresent ( ( node as FunctionLikeDeclaration | ClassStaticBlockDeclaration ) . body ) ) {
10291031 node . flags |= NodeFlags . HasImplicitReturn ;
10301032 if ( hasExplicitReturn ) node . flags |= NodeFlags . HasExplicitReturn ;
10311033 ( node as FunctionLikeDeclaration | ClassStaticBlockDeclaration ) . endFlowNode = currentFlow ;
10321034 }
1035+ if ( seenThisKeyword ) {
1036+ node . flags |= NodeFlags . ContainsThis ;
1037+ }
10331038 if ( node . kind === SyntaxKind . SourceFile ) {
10341039 node . flags |= emitFlags ;
10351040 ( node as SourceFile ) . endFlowNode = currentFlow ;
10361041 }
1037-
10381042 if ( currentReturnTarget ) {
10391043 addAntecedent ( currentReturnTarget , currentFlow ) ;
10401044 currentFlow = finishFlowLabel ( currentReturnTarget ) ;
@@ -1051,12 +1055,15 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
10511055 currentExceptionTarget = saveExceptionTarget ;
10521056 activeLabelList = saveActiveLabelList ;
10531057 hasExplicitReturn = saveHasExplicitReturn ;
1058+ seenThisKeyword = node . kind === SyntaxKind . ArrowFunction ? saveSeenThisKeyword || seenThisKeyword : saveSeenThisKeyword ;
10541059 }
10551060 else if ( containerFlags & ContainerFlags . IsInterface ) {
1061+ const saveSeenThisKeyword = seenThisKeyword ;
10561062 seenThisKeyword = false ;
10571063 bindChildren ( node ) ;
10581064 Debug . assertNotNode ( node , isIdentifier ) ; // ContainsThis cannot overlap with HasExtendedUnicodeEscape on Identifier
10591065 node . flags = seenThisKeyword ? node . flags | NodeFlags . ContainsThis : node . flags & ~ NodeFlags . ContainsThis ;
1066+ seenThisKeyword = saveSeenThisKeyword ;
10601067 }
10611068 else {
10621069 bindChildren ( node ) ;
@@ -2852,6 +2859,9 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
28522859 }
28532860 // falls through
28542861 case SyntaxKind . ThisKeyword :
2862+ if ( node . kind === SyntaxKind . ThisKeyword ) {
2863+ seenThisKeyword = true ;
2864+ }
28552865 // TODO: Why use `isExpression` here? both Identifier and ThisKeyword are expressions.
28562866 if ( currentFlow && ( isExpression ( node ) || parent . kind === SyntaxKind . ShorthandPropertyAssignment ) ) {
28572867 ( node as Identifier | ThisExpression ) . flowNode = currentFlow ;
@@ -3833,28 +3843,27 @@ export function getContainerFlags(node: Node): ContainerFlags {
38333843 // falls through
38343844 case SyntaxKind . Constructor :
38353845 case SyntaxKind . FunctionDeclaration :
3846+ case SyntaxKind . ClassStaticBlockDeclaration :
3847+ return ContainerFlags . IsContainer | ContainerFlags . IsControlFlowContainer | ContainerFlags . HasLocals | ContainerFlags . IsFunctionLike ;
38363848 case SyntaxKind . MethodSignature :
38373849 case SyntaxKind . CallSignature :
38383850 case SyntaxKind . JSDocSignature :
38393851 case SyntaxKind . JSDocFunctionType :
38403852 case SyntaxKind . FunctionType :
38413853 case SyntaxKind . ConstructSignature :
38423854 case SyntaxKind . ConstructorType :
3843- case SyntaxKind . ClassStaticBlockDeclaration :
3844- return ContainerFlags . IsContainer | ContainerFlags . IsControlFlowContainer | ContainerFlags . HasLocals | ContainerFlags . IsFunctionLike ;
3855+ return ContainerFlags . IsContainer | ContainerFlags . HasLocals | ContainerFlags . IsFunctionLike ;
38453856
38463857 case SyntaxKind . JSDocImportTag :
38473858 // treat as a container to prevent using an enclosing effective host, ensuring import bindings are scoped correctly
3848- return ContainerFlags . IsContainer | ContainerFlags . IsControlFlowContainer | ContainerFlags . HasLocals ;
3859+ return ContainerFlags . IsContainer | ContainerFlags . HasLocals ;
38493860
38503861 case SyntaxKind . FunctionExpression :
38513862 case SyntaxKind . ArrowFunction :
38523863 return ContainerFlags . IsContainer | ContainerFlags . IsControlFlowContainer | ContainerFlags . HasLocals | ContainerFlags . IsFunctionLike | ContainerFlags . IsFunctionExpression ;
38533864
38543865 case SyntaxKind . ModuleBlock :
38553866 return ContainerFlags . IsControlFlowContainer ;
3856- case SyntaxKind . PropertyDeclaration :
3857- return ( node as PropertyDeclaration ) . initializer ? ContainerFlags . IsControlFlowContainer : 0 ;
38583867
38593868 case SyntaxKind . CatchClause :
38603869 case SyntaxKind . ForStatement :
0 commit comments