Reuse code for tryGetClassExtendingIdentifier

This commit is contained in:
Andy Hanson 2016-08-26 10:40:10 -07:00
parent c1a291dffe
commit f90d8ddca5
2 changed files with 14 additions and 22 deletions

View File

@ -2659,10 +2659,17 @@ namespace ts {
return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment;
}
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
return node.kind === SyntaxKind.ExpressionWithTypeArguments &&
/** Get `C` given `N` if `N` is in the position `class C extends N` where `N` is an ExpressionWithTypeArguments. */
export function tryGetClassExtendingExpressionWithTypeArguments(node: Node): ClassLikeDeclaration | undefined {
if (node.kind === SyntaxKind.ExpressionWithTypeArguments &&
(<HeritageClause>node.parent).token === SyntaxKind.ExtendsKeyword &&
isClassLike(node.parent.parent);
isClassLike(node.parent.parent)) {
return node.parent.parent;
}
}
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
return tryGetClassExtendingExpressionWithTypeArguments(node) !== undefined;
}
export function isEntityNameExpression(node: Expression): node is EntityNameExpression {

View File

@ -2805,24 +2805,9 @@ namespace ts {
return target && target.parent && target.parent.kind === kind && (<CallExpression>target.parent).expression === target;
}
/** Get `C` given `N` if `N` is in the position `class C extends N` */
function tryGetClassExtendingNode(node: Node): ClassLikeDeclaration | undefined {
const target = climbPastPropertyAccess(node);
const expr = target.parent;
if (expr.kind !== SyntaxKind.ExpressionWithTypeArguments) {
return;
}
const heritageClause = expr.parent;
if (heritageClause.kind !== SyntaxKind.HeritageClause) {
return;
}
const classNode = <ClassLikeDeclaration>heritageClause.parent;
if (getHeritageClause(classNode.heritageClauses, SyntaxKind.ExtendsKeyword) === heritageClause) {
return classNode;
}
/** 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. */
function tryGetClassExtendingIdentifier(node: Node): ClassLikeDeclaration | undefined {
return tryGetClassExtendingExpressionWithTypeArguments(climbPastPropertyAccess(node).parent);
}
function isNameOfModuleDeclaration(node: Node) {
@ -6487,7 +6472,7 @@ namespace ts {
}
else {
// If this class appears in `extends C`, then the extending class' "super" calls are references.
const classExtending = tryGetClassExtendingNode(referenceLocation);
const classExtending = tryGetClassExtendingIdentifier(referenceLocation);
if (classExtending && isClassLike(classExtending)) {
if (getRelatedSymbol([searchClassSymbol], referenceSymbol, referenceLocation)) {
const supers = superConstructorAccesses(classExtending);