Skip to content

Commit 6a24eab

Browse files
committed
Set current scope for classes.
1 parent f1fe0b8 commit 6a24eab

File tree

1 file changed

+5
-13
lines changed
  • src/compiler/transformers

1 file changed

+5
-13
lines changed

src/compiler/transformers/ts.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ namespace ts {
166166

167167
case SyntaxKind.ClassDeclaration:
168168
case SyntaxKind.FunctionDeclaration:
169-
if (isClassDeclaration(node)) {
170-
currentScope = node;
171-
}
172169
if (hasModifier(node, ModifierFlags.Ambient)) {
173170
break;
174171
}
@@ -183,6 +180,10 @@ namespace ts {
183180
// programs may also have an undefined name.
184181
Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default));
185182
}
183+
if (isClassDeclaration(node)) {
184+
// XXX: should probably also cover interfaces and type aliases that can have type variables?
185+
currentScope = node;
186+
}
186187

187188
break;
188189
}
@@ -1972,16 +1973,7 @@ namespace ts {
19721973
* @param node The type reference node.
19731974
*/
19741975
function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode {
1975-
// node might be a reference to type variable, which can be scoped to a class declaration, in addition to the regular
1976-
// TypeScript scopes. Walk up the AST to find the next class and use that as the lookup scope.
1977-
let scope: Node = currentScope;
1978-
// while (scope.parent && scope !== currentScope) {
1979-
// scope = scope.parent;
1980-
// if (isClassDeclaration(scope)) {
1981-
// break;
1982-
// }
1983-
// }
1984-
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, scope);
1976+
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentScope);
19851977
switch (kind) {
19861978
case TypeReferenceSerializationKind.Unknown:
19871979
const serialized = serializeEntityNameAsExpression(node.typeName, /*useFallback*/ true);

0 commit comments

Comments
 (0)