From d37caf1c0d838323c55c97b3e24929d119c9bcd2 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 29 Aug 2018 17:43:22 -0700 Subject: [PATCH] Remove unnecessary `getContainingClass` calls (#26753) --- src/compiler/checker.ts | 13 +++++++------ src/compiler/utilities.ts | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7b7fea4efb..afd9b6d5b3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27344,12 +27344,10 @@ namespace ts { } if (isPartOfTypeNode(node)) { - let typeFromTypeNode = getTypeFromTypeNode(node); + const typeFromTypeNode = getTypeFromTypeNode(node); if (isExpressionWithTypeArgumentsInClassImplementsClause(node)) { - const containingClass = getContainingClass(node)!; - const classType = getTypeOfNode(containingClass) as InterfaceType; - typeFromTypeNode = getTypeWithThisArgument(typeFromTypeNode, classType.thisType); + return getTypeWithThisArgument(typeFromTypeNode, getTypeOfClassContainingHeritageClause(node).thisType); } return typeFromTypeNode; @@ -27362,8 +27360,7 @@ namespace ts { if (isExpressionWithTypeArgumentsInClassExtendsClause(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. - const classNode = getContainingClass(node)!; - const classType = getDeclaredTypeOfSymbol(getSymbolOfNode(classNode)) as InterfaceType; + const classType = getTypeOfClassContainingHeritageClause(node); const baseType = firstOrUndefined(getBaseTypes(classType)); return baseType ? getTypeWithThisArgument(baseType, classType.thisType) : errorType; } @@ -27405,6 +27402,10 @@ namespace ts { return errorType; } + function getTypeOfClassContainingHeritageClause(node: ExpressionWithTypeArguments): InterfaceType { + return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(node.parent.parent)); + } + // Gets the type of object literal or array literal of destructuring assignment. // { a } from // for ( { a } of elems) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 0e92bad7f5..6ecc80aaa3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3743,7 +3743,7 @@ namespace ts { return false; } - export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean { + export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): node is ExpressionWithTypeArguments { return tryGetClassExtendingExpressionWithTypeArguments(node) !== undefined; }