@@ -61,7 +61,8 @@ namespace ts {
61
61
let currentSourceFile : SourceFile ;
62
62
let currentNamespace : ModuleDeclaration ;
63
63
let currentNamespaceContainerName : Identifier ;
64
- let currentScope : SourceFile | Block | ModuleBlock | CaseBlock | ClassDeclaration ;
64
+ let currentLexicalScope : SourceFile | Block | ModuleBlock | CaseBlock ;
65
+ let currentNameScope : ClassDeclaration | undefined ;
65
66
let currentScopeFirstDeclarationsOfName : UnderscoreEscapedMap < Node > | undefined ;
66
67
67
68
/**
@@ -132,7 +133,8 @@ namespace ts {
132
133
*/
133
134
function saveStateAndInvoke < T > ( node : Node , f : ( node : Node ) => T ) : T {
134
135
// Save state
135
- const savedCurrentScope = currentScope ;
136
+ const savedCurrentScope = currentLexicalScope ;
137
+ const savedCurrentNameScope = currentNameScope ;
136
138
const savedCurrentScopeFirstDeclarationsOfName = currentScopeFirstDeclarationsOfName ;
137
139
138
140
// Handle state changes before visiting a node.
@@ -141,11 +143,12 @@ namespace ts {
141
143
const visited = f ( node ) ;
142
144
143
145
// Restore state
144
- if ( currentScope !== savedCurrentScope ) {
146
+ if ( currentLexicalScope !== savedCurrentScope ) {
145
147
currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName ;
146
148
}
147
149
148
- currentScope = savedCurrentScope ;
150
+ currentLexicalScope = savedCurrentScope ;
151
+ currentNameScope = savedCurrentNameScope ;
149
152
return visited ;
150
153
}
151
154
@@ -160,7 +163,8 @@ namespace ts {
160
163
case SyntaxKind . CaseBlock :
161
164
case SyntaxKind . ModuleBlock :
162
165
case SyntaxKind . Block :
163
- currentScope = < SourceFile | CaseBlock | ModuleBlock | Block > node ;
166
+ currentLexicalScope = < SourceFile | CaseBlock | ModuleBlock | Block > node ;
167
+ currentNameScope = undefined ;
164
168
currentScopeFirstDeclarationsOfName = undefined ;
165
169
break ;
166
170
@@ -182,7 +186,7 @@ namespace ts {
182
186
}
183
187
if ( isClassDeclaration ( node ) ) {
184
188
// XXX: should probably also cover interfaces and type aliases that can have type variables?
185
- currentScope = node ;
189
+ currentNameScope = node ;
186
190
}
187
191
188
192
break ;
@@ -1973,7 +1977,7 @@ namespace ts {
1973
1977
* @param node The type reference node.
1974
1978
*/
1975
1979
function serializeTypeReferenceNode ( node : TypeReferenceNode ) : SerializedTypeNode {
1976
- const kind = resolver . getTypeReferenceSerializationKind ( node . typeName , currentScope ) ;
1980
+ const kind = resolver . getTypeReferenceSerializationKind ( node . typeName , currentNameScope || currentLexicalScope ) ;
1977
1981
switch ( kind ) {
1978
1982
case TypeReferenceSerializationKind . Unknown :
1979
1983
const serialized = serializeEntityNameAsExpression ( node . typeName , /*useFallback*/ true ) ;
@@ -2037,7 +2041,7 @@ namespace ts {
2037
2041
const name = getMutableClone ( node ) ;
2038
2042
name . flags &= ~ NodeFlags . Synthesized ;
2039
2043
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.
2041
2045
if ( useFallback ) {
2042
2046
return createLogicalAnd (
2043
2047
createStrictInequality (
@@ -2624,7 +2628,7 @@ namespace ts {
2624
2628
// enum body.
2625
2629
if ( addVarForEnumOrModuleDeclaration ( statements , node ) ) {
2626
2630
// 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 ) {
2628
2632
emitFlags |= EmitFlags . NoLeadingComments ;
2629
2633
}
2630
2634
}
@@ -2837,7 +2841,7 @@ namespace ts {
2837
2841
createVariableDeclaration (
2838
2842
getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true )
2839
2843
)
2840
- ] , currentScope . kind === SyntaxKind . SourceFile ? NodeFlags . None : NodeFlags . Let )
2844
+ ] , currentLexicalScope . kind === SyntaxKind . SourceFile ? NodeFlags . None : NodeFlags . Let )
2841
2845
) ;
2842
2846
2843
2847
setOriginalNode ( statement , node ) ;
@@ -2913,7 +2917,7 @@ namespace ts {
2913
2917
// module body.
2914
2918
if ( addVarForEnumOrModuleDeclaration ( statements , node ) ) {
2915
2919
// 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 ) {
2917
2921
emitFlags |= EmitFlags . NoLeadingComments ;
2918
2922
}
2919
2923
}
0 commit comments