From e305de140318f245d91edc1d31bb5587afa1ed35 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 16 Jun 2015 06:54:10 -0700 Subject: [PATCH] Workaround to match previous type writer output --- src/compiler/checker.ts | 10 ++++++---- src/harness/typeWriter.ts | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8395fc04626..8ad4061ddf7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12002,10 +12002,6 @@ module ts { return unknownType; } - if (isClassExtendsExpressionWithTypeArguments(node)) { - return getBaseTypes(getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0]; - } - if (isTypeNode(node)) { return getTypeFromTypeNode(node); } @@ -12014,6 +12010,12 @@ module ts { return getTypeOfExpression(node); } + if (isClassExtendsExpressionWithTypeArguments(node)) { + // A SyntaxKind.ExpressionWithTypeArguments is considered a type node, except when it occurs in the + // extends clause of a class. We handle that case here. + return getBaseTypes(getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0]; + } + if (isTypeDeclaration(node)) { // In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration let symbol = getSymbolOfNode(node); diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index 533f90a2d83..ac695fc23a4 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -41,7 +41,10 @@ class TypeWriterWalker { var lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos); var sourceText = ts.getTextOfNodeFromSourceText(this.currentSourceFile.text, node); - var type = this.checker.getTypeAtLocation(node); + // Workaround to ensure we output 'C' instead of 'typeof C' for base class expressions + // var type = this.checker.getTypeAtLocation(node); + var type = node.parent && ts.isClassExtendsExpressionWithTypeArguments(node.parent) && this.checker.getTypeAtLocation(node.parent) || this.checker.getTypeAtLocation(node); + ts.Debug.assert(type !== undefined, "type doesn't exist"); var symbol = this.checker.getSymbolAtLocation(node);