From 6a24eabd1863d92b572b98097995622e566d0108 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 26 Jun 2018 16:33:36 +0200 Subject: [PATCH] Set current scope for classes. --- src/compiler/transformers/ts.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 6d724750b00..5a60916167f 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -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);