@@ -61,7 +61,8 @@ namespace ts {
6161 let currentSourceFile : SourceFile ;
6262 let currentNamespace : ModuleDeclaration ;
6363 let currentNamespaceContainerName : Identifier ;
64- let currentScope : SourceFile | Block | ModuleBlock | CaseBlock | ClassDeclaration ;
64+ let currentLexicalScope : SourceFile | Block | ModuleBlock | CaseBlock ;
65+ let currentNameScope : ClassDeclaration | undefined ;
6566 let currentScopeFirstDeclarationsOfName : UnderscoreEscapedMap < Node > | undefined ;
6667
6768 /**
@@ -132,7 +133,8 @@ namespace ts {
132133 */
133134 function saveStateAndInvoke < T > ( node : Node , f : ( node : Node ) => T ) : T {
134135 // Save state
135- const savedCurrentScope = currentScope ;
136+ const savedCurrentScope = currentLexicalScope ;
137+ const savedCurrentNameScope = currentNameScope ;
136138 const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName ;
137139
138140 // Handle state changes before visiting a node.
@@ -141,11 +143,12 @@ namespace ts {
141143 const visited = f ( node ) ;
142144
143145 // Restore state
144- if ( currentScope !== savedCurrentScope ) {
146+ if ( currentLexicalScope !== savedCurrentScope ) {
145147 currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName ;
146148 }
147149
148- currentScope = savedCurrentScope ;
150+ currentLexicalScope = savedCurrentScope ;
151+ currentNameScope = savedCurrentNameScope ;
149152 return visited ;
150153 }
151154
@@ -160,7 +163,8 @@ namespace ts {
160163 case SyntaxKind . CaseBlock :
161164 case SyntaxKind . ModuleBlock :
162165 case SyntaxKind . Block :
163- currentScope = < SourceFile | CaseBlock | ModuleBlock | Block > node ;
166+ currentLexicalScope = < SourceFile | CaseBlock | ModuleBlock | Block > node ;
167+ currentNameScope = undefined ;
164168 currentScopeFirstDeclarationsOfName = undefined ;
165169 break ;
166170
@@ -182,7 +186,7 @@ namespace ts {
182186 }
183187 if ( isClassDeclaration ( node ) ) {
184188 // XXX: should probably also cover interfaces and type aliases that can have type variables?
185- currentScope = node ;
189+ currentNameScope = node ;
186190 }
187191
188192 break ;
@@ -1973,7 +1977,7 @@ namespace ts {
19731977 * @param node The type reference node.
19741978 */
19751979 function serializeTypeReferenceNode ( node : TypeReferenceNode ) : SerializedTypeNode {
1976- const kind = resolver . getTypeReferenceSerializationKind ( node . typeName , currentScope ) ;
1980+ const kind = resolver . getTypeReferenceSerializationKind ( node . typeName , currentNameScope || currentLexicalScope ) ;
19771981 switch ( kind ) {
19781982 case TypeReferenceSerializationKind . Unknown :
19791983 const serialized = serializeEntityNameAsExpression ( node . typeName , /*useFallback*/ true ) ;
@@ -2037,7 +2041,7 @@ namespace ts {
20372041 const name = getMutableClone ( node ) ;
20382042 name . flags &= ~ NodeFlags . Synthesized ;
20392043 name . original = undefined ;
2040- name . parent = getParseTreeNode ( currentScope ) ; // ensure the parent is set to a parse tree node.
2044+ name . parent = getParseTreeNode ( currentLexicalScope ) ; // ensure the parent is set to a parse tree node.
20412045 if ( useFallback ) {
20422046 return createLogicalAnd (
20432047 createStrictInequality (
@@ -2624,7 +2628,7 @@ namespace ts {
26242628 // enum body.
26252629 if ( addVarForEnumOrModuleDeclaration ( statements , node ) ) {
26262630 // We should still emit the comments if we are emitting a system module.
2627- if ( moduleKind !== ModuleKind . System || currentScope !== currentSourceFile ) {
2631+ if ( moduleKind !== ModuleKind . System || currentLexicalScope !== currentSourceFile ) {
26282632 emitFlags |= EmitFlags . NoLeadingComments ;
26292633 }
26302634 }
@@ -2837,7 +2841,7 @@ namespace ts {
28372841 createVariableDeclaration (
28382842 getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true )
28392843 )
2840- ] , currentScope . kind === SyntaxKind . SourceFile ? NodeFlags . None : NodeFlags . Let )
2844+ ] , currentLexicalScope . kind === SyntaxKind . SourceFile ? NodeFlags . None : NodeFlags . Let )
28412845 ) ;
28422846
28432847 setOriginalNode ( statement , node ) ;
@@ -2913,7 +2917,7 @@ namespace ts {
29132917 // module body.
29142918 if ( addVarForEnumOrModuleDeclaration ( statements , node ) ) {
29152919 // We should still emit the comments if we are emitting a system module.
2916- if ( moduleKind !== ModuleKind . System || currentScope !== currentSourceFile ) {
2920+ if ( moduleKind !== ModuleKind . System || currentLexicalScope !== currentSourceFile ) {
29172921 emitFlags |= EmitFlags . NoLeadingComments ;
29182922 }
29192923 }
0 commit comments