Skip to content

Commit dc19223

Browse files
author
Andy Hanson
committed
Use recursion, and fix error for undefined node
1 parent db44a71 commit dc19223

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ namespace ts {
664664
// Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and
665665
// the nameNotFoundMessage argument is not undefined. Returns the resolved symbol, or undefined if no symbol with
666666
// the given name can be found.
667-
function resolveName(location: Node, name: string, meaning: SymbolFlags, nameNotFoundMessage: DiagnosticMessage, nameArg: string | Identifier): Symbol {
667+
function resolveName(location: Node | undefined, name: string, meaning: SymbolFlags, nameNotFoundMessage: DiagnosticMessage, nameArg: string | Identifier): Symbol {
668668
let result: Symbol;
669669
let lastLocation: Node;
670670
let propertyWithInvalidInitializer: Node;
@@ -881,7 +881,8 @@ namespace ts {
881881

882882
if (!result) {
883883
if (nameNotFoundMessage) {
884-
if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) &&
884+
if (!errorLocation ||
885+
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) &&
885886
!checkAndReportErrorForExtendingInterface(errorLocation)) {
886887
error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
887888
}
@@ -930,7 +931,7 @@ namespace ts {
930931
}
931932

932933
function checkAndReportErrorForMissingPrefix(errorLocation: Node, name: string, nameArg: string | Identifier): boolean {
933-
if (!errorLocation || (errorLocation.kind === SyntaxKind.Identifier && (isTypeReferenceIdentifier(<Identifier>errorLocation)) || isInTypeQuery(errorLocation))) {
934+
if ((errorLocation.kind === SyntaxKind.Identifier && (isTypeReferenceIdentifier(<Identifier>errorLocation)) || isInTypeQuery(errorLocation))) {
934935
return false;
935936
}
936937

@@ -980,23 +981,15 @@ namespace ts {
980981
* but returns undefined if that expression is not an EntityNameExpression.
981982
*/
982983
function climbToEntityNameOfExpressionWithTypeArguments(node: Node): EntityNameExpression | undefined {
983-
for (; ; ) {
984-
switch (node.kind) {
985-
case SyntaxKind.Identifier:
986-
case SyntaxKind.PropertyAccessExpression:
987-
if (node.parent) {
988-
node = node.parent;
989-
}
990-
else {
991-
return undefined;
992-
}
993-
break;
994-
case SyntaxKind.ExpressionWithTypeArguments:
995-
Debug.assert(isEntityNameExpression((<ExpressionWithTypeArguments>node).expression));
996-
return <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression;
997-
default:
998-
return undefined;
999-
}
984+
switch (node.kind) {
985+
case SyntaxKind.Identifier:
986+
case SyntaxKind.PropertyAccessExpression:
987+
return node.parent ? climbToEntityNameOfExpressionWithTypeArguments(node.parent) : undefined;
988+
case SyntaxKind.ExpressionWithTypeArguments:
989+
Debug.assert(isEntityNameExpression((<ExpressionWithTypeArguments>node).expression));
990+
return <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression
991+
default:
992+
return undefined;
1000993
}
1001994
}
1002995

src/compiler/utilities.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,17 +2685,8 @@ namespace ts {
26852685
}
26862686

26872687
export function isEntityNameExpression(node: Expression): node is EntityNameExpression {
2688-
for (; ; ) {
2689-
switch (node.kind) {
2690-
case SyntaxKind.Identifier:
2691-
return true;
2692-
case SyntaxKind.PropertyAccessExpression:
2693-
node = (<PropertyAccessExpression>node).expression;
2694-
break;
2695-
default:
2696-
return false;
2697-
}
2698-
}
2688+
return node.kind === SyntaxKind.Identifier ||
2689+
node.kind === SyntaxKind.PropertyAccessExpression && isEntityNameExpression((<PropertyAccessExpression>node).expression);
26992690
}
27002691

27012692
export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {

0 commit comments

Comments
 (0)