use better scope

This commit is contained in:
Martin Probst 2018-06-26 15:51:37 +02:00
parent 55c3ec3e94
commit f1fe0b8116

View File

@ -61,7 +61,7 @@ namespace ts {
let currentSourceFile: SourceFile;
let currentNamespace: ModuleDeclaration;
let currentNamespaceContainerName: Identifier;
let currentScope: SourceFile | Block | ModuleBlock | CaseBlock;
let currentScope: SourceFile | Block | ModuleBlock | CaseBlock | ClassDeclaration;
let currentScopeFirstDeclarationsOfName: UnderscoreEscapedMap<Node> | undefined;
/**
@ -166,6 +166,9 @@ namespace ts {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.FunctionDeclaration:
if (isClassDeclaration(node)) {
currentScope = node;
}
if (hasModifier(node, ModifierFlags.Ambient)) {
break;
}
@ -1971,13 +1974,13 @@ namespace ts {
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 = node;
while (scope.parent && scope !== currentScope) {
scope = scope.parent;
if (isClassDeclaration(scope)) {
break;
}
}
let scope: Node = currentScope;
// while (scope.parent && scope !== currentScope) {
// scope = scope.parent;
// if (isClassDeclaration(scope)) {
// break;
// }
// }
const kind = resolver.getTypeReferenceSerializationKind(node.typeName, scope);
switch (kind) {
case TypeReferenceSerializationKind.Unknown: