Skip to content

Commit f90d8dd

Browse files
author
Andy Hanson
committed
Reuse code for tryGetClassExtendingIdentifier
1 parent c1a291d commit f90d8dd

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

src/compiler/utilities.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,10 +2659,17 @@ namespace ts {
26592659
return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment;
26602660
}
26612661

2662-
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
2663-
return node.kind === SyntaxKind.ExpressionWithTypeArguments &&
2662+
/** Get `C` given `N` if `N` is in the position `class C extends N` where `N` is an ExpressionWithTypeArguments. */
2663+
export function tryGetClassExtendingExpressionWithTypeArguments(node: Node): ClassLikeDeclaration | undefined {
2664+
if (node.kind === SyntaxKind.ExpressionWithTypeArguments &&
26642665
(<HeritageClause>node.parent).token === SyntaxKind.ExtendsKeyword &&
2665-
isClassLike(node.parent.parent);
2666+
isClassLike(node.parent.parent)) {
2667+
return node.parent.parent;
2668+
}
2669+
}
2670+
2671+
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
2672+
return tryGetClassExtendingExpressionWithTypeArguments(node) !== undefined;
26662673
}
26672674

26682675
export function isEntityNameExpression(node: Expression): node is EntityNameExpression {

src/services/services.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,24 +2805,9 @@ namespace ts {
28052805
return target && target.parent && target.parent.kind === kind && (<CallExpression>target.parent).expression === target;
28062806
}
28072807

2808-
/** Get `C` given `N` if `N` is in the position `class C extends N` */
2809-
function tryGetClassExtendingNode(node: Node): ClassLikeDeclaration | undefined {
2810-
const target = climbPastPropertyAccess(node);
2811-
2812-
const expr = target.parent;
2813-
if (expr.kind !== SyntaxKind.ExpressionWithTypeArguments) {
2814-
return;
2815-
}
2816-
2817-
const heritageClause = expr.parent;
2818-
if (heritageClause.kind !== SyntaxKind.HeritageClause) {
2819-
return;
2820-
}
2821-
2822-
const classNode = <ClassLikeDeclaration>heritageClause.parent;
2823-
if (getHeritageClause(classNode.heritageClauses, SyntaxKind.ExtendsKeyword) === heritageClause) {
2824-
return classNode;
2825-
}
2808+
/** Get `C` given `N` if `N` is in the position `class C extends N` or `class C extends foo.N` where `N` is an identifier. */
2809+
function tryGetClassExtendingIdentifier(node: Node): ClassLikeDeclaration | undefined {
2810+
return tryGetClassExtendingExpressionWithTypeArguments(climbPastPropertyAccess(node).parent);
28262811
}
28272812

28282813
function isNameOfModuleDeclaration(node: Node) {
@@ -6487,7 +6472,7 @@ namespace ts {
64876472
}
64886473
else {
64896474
// If this class appears in `extends C`, then the extending class' "super" calls are references.
6490-
const classExtending = tryGetClassExtendingNode(referenceLocation);
6475+
const classExtending = tryGetClassExtendingIdentifier(referenceLocation);
64916476
if (classExtending && isClassLike(classExtending)) {
64926477
if (getRelatedSymbol([searchClassSymbol], referenceSymbol, referenceLocation)) {
64936478
const supers = superConstructorAccesses(classExtending);

0 commit comments

Comments
 (0)