Skip to content

Commit 91c9d76

Browse files
author
Andy Hanson
committed
Remove SupportedExpressionWithTypeArguments type; just check that the expression of each ExpressionWithTypeArguments is an EntityNameExpression.
1 parent c50ccbf commit 91c9d76

File tree

4 files changed

+32
-47
lines changed

4 files changed

+32
-47
lines changed

src/compiler/checker.ts

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -968,37 +968,34 @@ namespace ts {
968968

969969

970970
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) {
978974
error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, getTextOfNode(expression));
979-
return true;
980975
}
981-
return false;
976+
return isError;
982977
}
983978
/**
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.
986981
*/
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) {
992987
node = node.parent;
993-
break;
994-
case SyntaxKind.ExpressionWithTypeArguments:
995-
Debug.assert(isSupportedExpressionWithTypeArguments(<ExpressionWithTypeArguments>node));
996-
return <SupportedExpressionWithTypeArguments>node;
997-
default:
988+
}
989+
else {
998990
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;
1000998
}
1001-
return undefined;
1002999
}
10031000

10041001

@@ -3686,7 +3683,7 @@ namespace ts {
36863683
const baseTypeNodes = getInterfaceBaseTypeNodes(<InterfaceDeclaration>declaration);
36873684
if (baseTypeNodes) {
36883685
for (const node of baseTypeNodes) {
3689-
if (isSupportedExpressionWithTypeArguments(node)) {
3686+
if (isEntityNameExpression(node.expression)) {
36903687
const baseSymbol = resolveEntityName(node.expression, SymbolFlags.Type, /*ignoreErrors*/ true);
36913688
if (!baseSymbol || !(baseSymbol.flags & SymbolFlags.Interface) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) {
36923689
return false;
@@ -5042,9 +5039,9 @@ namespace ts {
50425039
case SyntaxKind.ExpressionWithTypeArguments:
50435040
// We only support expressions that are simple qualified names. For other
50445041
// 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;
50485045
}
50495046

50505047
// fall through;
@@ -5101,8 +5098,8 @@ namespace ts {
51015098
// We only support expressions that are simple qualified names. For other expressions this produces undefined.
51025099
const typeNameOrExpression: EntityNameOrEntityNameExpression = node.kind === SyntaxKind.TypeReference
51035100
? (<TypeReferenceNode>node).typeName
5104-
: isSupportedExpressionWithTypeArguments(<ExpressionWithTypeArguments>node)
5105-
? (<SupportedExpressionWithTypeArguments>node).expression
5101+
: isEntityNameExpression((<ExpressionWithTypeArguments>node).expression)
5102+
? <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression
51065103
: undefined;
51075104
symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol;
51085105
type = symbol === unknownSymbol ? unknownType :
@@ -16255,7 +16252,7 @@ namespace ts {
1625516252
const implementedTypeNodes = getClassImplementsHeritageClauseElements(node);
1625616253
if (implementedTypeNodes) {
1625716254
for (const typeRefNode of implementedTypeNodes) {
16258-
if (!isSupportedExpressionWithTypeArguments(typeRefNode)) {
16255+
if (!isEntityNameExpression(typeRefNode.expression)) {
1625916256
error(typeRefNode.expression, Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
1626016257
}
1626116258
checkTypeReferenceNode(typeRefNode);
@@ -16497,7 +16494,7 @@ namespace ts {
1649716494
checkObjectTypeForDuplicateDeclarations(node);
1649816495
}
1649916496
forEach(getInterfaceBaseTypeNodes(node), heritageElement => {
16500-
if (!isSupportedExpressionWithTypeArguments(heritageElement)) {
16497+
if (!isEntityNameExpression(heritageElement.expression)) {
1650116498
error(heritageElement.expression, Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
1650216499
}
1650316500
checkTypeReferenceNode(heritageElement);

src/compiler/declarationEmitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ namespace ts {
452452
}
453453

454454
function emitExpressionWithTypeArguments(node: ExpressionWithTypeArguments) {
455-
if (isSupportedExpressionWithTypeArguments(node)) {
455+
if (isEntityNameExpression(node.expression)) {
456456
Debug.assert(node.expression.kind === SyntaxKind.Identifier || node.expression.kind === SyntaxKind.PropertyAccessExpression);
457457
emitEntityName(node.expression);
458458
if (node.typeArguments) {
@@ -1019,7 +1019,7 @@ namespace ts {
10191019
}
10201020

10211021
function emitTypeOfTypeReference(node: ExpressionWithTypeArguments) {
1022-
if (isSupportedExpressionWithTypeArguments(node)) {
1022+
if (isEntityNameExpression(node.expression)) {
10231023
emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError);
10241024
}
10251025
else if (!isImplementsList && node.expression.kind === SyntaxKind.NullKeyword) {

src/compiler/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,6 @@ namespace ts {
10141014
expression: LeftHandSideExpression;
10151015
typeArguments?: NodeArray<TypeNode>;
10161016
}
1017-
export interface SupportedExpressionWithTypeArguments extends ExpressionWithTypeArguments {
1018-
_supportedExpressionWithTypeArgumentsBrand?: any;
1019-
expression: EntityNameExpression;
1020-
}
10211017

10221018
// @kind(SyntaxKind.NewExpression)
10231019
export interface NewExpression extends CallExpression, PrimaryExpression { }

src/compiler/utilities.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,8 @@ namespace ts {
10391039
case SyntaxKind.TypeReference:
10401040
return (<TypeReferenceNode>node).typeName;
10411041
case SyntaxKind.ExpressionWithTypeArguments:
1042-
Debug.assert(isSupportedExpressionWithTypeArguments(<ExpressionWithTypeArguments>node));
1043-
return (<SupportedExpressionWithTypeArguments>node).expression;
1042+
Debug.assert(isEntityNameExpression((<ExpressionWithTypeArguments>node).expression));
1043+
return <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression;
10441044
case SyntaxKind.Identifier:
10451045
case SyntaxKind.QualifiedName:
10461046
return (<EntityName><Node>node);
@@ -2684,10 +2684,6 @@ namespace ts {
26842684
isClassLike(node.parent.parent);
26852685
}
26862686

2687-
export function isSupportedExpressionWithTypeArguments(node: ExpressionWithTypeArguments): node is SupportedExpressionWithTypeArguments {
2688-
return isEntityNameExpression(node.expression);
2689-
}
2690-
26912687
export function isEntityNameExpression(node: Expression): node is EntityNameExpression {
26922688
for (; ; ) {
26932689
switch (node.kind) {
@@ -2702,10 +2698,6 @@ namespace ts {
27022698
}
27032699
}
27042700

2705-
export function isPropertyAccessAnEntityNameExpression(node: PropertyAccessExpression): node is PropertyAccessEntityNameExpression {
2706-
return isEntityNameExpression(node.expression);
2707-
}
2708-
27092701
export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
27102702
return (node.parent.kind === SyntaxKind.QualifiedName && (<QualifiedName>node.parent).right === node) ||
27112703
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node);

0 commit comments

Comments
 (0)