Set current scope for classes.

This commit is contained in:
Martin Probst
2018-06-26 16:33:36 +02:00
parent f1fe0b8116
commit 6a24eabd18
+5 -13
View File
@@ -166,9 +166,6 @@ namespace ts {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.FunctionDeclaration:
if (isClassDeclaration(node)) {
currentScope = node;
}
if (hasModifier(node, ModifierFlags.Ambient)) {
break;
}
@@ -183,6 +180,10 @@ namespace ts {
// programs may also have an undefined name.
Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default));
}
if (isClassDeclaration(node)) {
// XXX: should probably also cover interfaces and type aliases that can have type variables?
currentScope = node;
}
break;
}
@@ -1972,16 +1973,7 @@ namespace ts {
* @param node The type reference node.
*/
function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode {
// node might be a reference to type variable, which can be scoped to a class declaration, in addition to the regular
// TypeScript scopes. Walk up the AST to find the next class and use that as the lookup scope.
let scope: Node = currentScope;
// while (scope.parent && scope !== currentScope) {
// scope = scope.parent;
// if (isClassDeclaration(scope)) {
// break;
// }
// }
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, scope);
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, currentScope);
switch (kind) {
case TypeReferenceSerializationKind.Unknown:
const serialized = serializeEntityNameAsExpression(node.typeName, /*useFallback*/ true);