@@ -968,37 +968,34 @@ namespace ts {
968
968
969
969
970
970
function checkAndReportErrorForExtendingInterface(errorLocation: Node): boolean {
971
- const parentExpression = climbToSupportedExpressionWithTypeArguments(errorLocation);
972
- if (!parentExpression) {
973
- return false;
974
- }
975
- const expression = parentExpression.expression;
976
-
977
- if (resolveEntityName(expression, SymbolFlags.Interface, /*ignoreErrors*/ true)) {
971
+ const expression = climbToEntityNameOfExpressionWithTypeArguments(errorLocation);
972
+ const isError = !!(expression && resolveEntityName(expression, SymbolFlags.Interface, /*ignoreErrors*/ true));
973
+ if (isError) {
978
974
error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, getTextOfNode(expression));
979
- return true;
980
975
}
981
- return false ;
976
+ return isError ;
982
977
}
983
978
/**
984
- * Climbs up parents to a SupportedExpressionWIthTypeArguments.
985
- * Does *not* just climb to an ExpressionWithTypeArguments; instead, ensures that this really is supported .
979
+ * Climbs up parents to an ExpressionWithTypeArguments, and returns its expression,
980
+ * but returns undefined if that expression is not an EntityNameExpression .
986
981
*/
987
- function climbToSupportedExpressionWithTypeArguments (node: Node): SupportedExpressionWithTypeArguments | undefined {
988
- while (node) {
989
- switch (node.kind) {
990
- case SyntaxKind.Identifier :
991
- case SyntaxKind.PropertyAccessExpression:
982
+ function climbToEntityNameOfExpressionWithTypeArguments (node: Node): EntityNameExpression | undefined {
983
+ switch (node.kind ) {
984
+ case SyntaxKind.Identifier:
985
+ case SyntaxKind.PropertyAccessExpression :
986
+ if (node.parent) {
992
987
node = node.parent;
993
- break;
994
- case SyntaxKind.ExpressionWithTypeArguments:
995
- Debug.assert(isSupportedExpressionWithTypeArguments(<ExpressionWithTypeArguments>node));
996
- return <SupportedExpressionWithTypeArguments>node;
997
- default:
988
+ }
989
+ else {
998
990
return undefined;
999
- }
991
+ }
992
+ break;
993
+ case SyntaxKind.ExpressionWithTypeArguments:
994
+ Debug.assert(isEntityNameExpression((<ExpressionWithTypeArguments>node).expression));
995
+ return <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression;
996
+ default:
997
+ return undefined;
1000
998
}
1001
- return undefined;
1002
999
}
1003
1000
1004
1001
@@ -3686,7 +3683,7 @@ namespace ts {
3686
3683
const baseTypeNodes = getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration);
3687
3684
if (baseTypeNodes) {
3688
3685
for (const node of baseTypeNodes) {
3689
- if (isSupportedExpressionWithTypeArguments (node)) {
3686
+ if (isEntityNameExpression (node.expression )) {
3690
3687
const baseSymbol = resolveEntityName(node.expression, SymbolFlags.Type, /*ignoreErrors*/ true);
3691
3688
if (!baseSymbol || !(baseSymbol.flags & SymbolFlags.Interface) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) {
3692
3689
return false;
@@ -5042,9 +5039,9 @@ namespace ts {
5042
5039
case SyntaxKind.ExpressionWithTypeArguments:
5043
5040
// We only support expressions that are simple qualified names. For other
5044
5041
// expressions this produces undefined.
5045
- const expr = <ExpressionWithTypeArguments>node;
5046
- if (isSupportedExpressionWithTypeArguments (expr)) {
5047
- return expr.expression ;
5042
+ const expr = ( <ExpressionWithTypeArguments>node).expression ;
5043
+ if (isEntityNameExpression (expr)) {
5044
+ return expr;
5048
5045
}
5049
5046
5050
5047
// fall through;
@@ -5101,8 +5098,8 @@ namespace ts {
5101
5098
// We only support expressions that are simple qualified names. For other expressions this produces undefined.
5102
5099
const typeNameOrExpression: EntityNameOrEntityNameExpression = node.kind === SyntaxKind.TypeReference
5103
5100
? (<TypeReferenceNode>node).typeName
5104
- : isSupportedExpressionWithTypeArguments( <ExpressionWithTypeArguments>node)
5105
- ? (<SupportedExpressionWithTypeArguments >node).expression
5101
+ : isEntityNameExpression(( <ExpressionWithTypeArguments>node).expression )
5102
+ ? <EntityNameExpression>(<ExpressionWithTypeArguments >node).expression
5106
5103
: undefined;
5107
5104
symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
5108
5105
type = symbol === unknownSymbol ? unknownType :
@@ -16255,7 +16252,7 @@ namespace ts {
16255
16252
const implementedTypeNodes = getClassImplementsHeritageClauseElements(node);
16256
16253
if (implementedTypeNodes) {
16257
16254
for (const typeRefNode of implementedTypeNodes) {
16258
- if (!isSupportedExpressionWithTypeArguments (typeRefNode)) {
16255
+ if (!isEntityNameExpression (typeRefNode.expression )) {
16259
16256
error(typeRefNode.expression, Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
16260
16257
}
16261
16258
checkTypeReferenceNode(typeRefNode);
@@ -16497,7 +16494,7 @@ namespace ts {
16497
16494
checkObjectTypeForDuplicateDeclarations(node);
16498
16495
}
16499
16496
forEach(getInterfaceBaseTypeNodes(node), heritageElement => {
16500
- if (!isSupportedExpressionWithTypeArguments (heritageElement)) {
16497
+ if (!isEntityNameExpression (heritageElement.expression )) {
16501
16498
error(heritageElement.expression, Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
16502
16499
}
16503
16500
checkTypeReferenceNode(heritageElement);
0 commit comments