Skip to content

Commit 9daa70c

Browse files
author
Andy
authored
Revert "Handle indexed access types in getSymbolAtLocation and findAllReferences (#17787)" (#18111)
This reverts commit 30b3cb0.
1 parent 7306b13 commit 9daa70c

File tree

5 files changed

+30
-60
lines changed

5 files changed

+30
-60
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22931,7 +22931,7 @@ namespace ts {
2293122931
return undefined;
2293222932
}
2293322933

22934-
function getSymbolAtLocation(node: Node): Symbol | undefined {
22934+
function getSymbolAtLocation(node: Node) {
2293522935
if (node.kind === SyntaxKind.SourceFile) {
2293622936
return isExternalModule(<SourceFile>node) ? getMergedSymbol(node.symbol) : undefined;
2293722937
}
@@ -23009,21 +23009,9 @@ namespace ts {
2300923009

2301023010
case SyntaxKind.NumericLiteral:
2301123011
// index access
23012-
switch (node.parent.kind) {
23013-
case SyntaxKind.ElementAccessExpression: {
23014-
if ((<ElementAccessExpression>node.parent).argumentExpression !== node) {
23015-
return undefined;
23016-
}
23017-
const objectType = getTypeOfExpression((<ElementAccessExpression>node.parent).expression);
23018-
return getPropertyOfType(objectType, (<NumericLiteral>node).text as __String);
23019-
}
23020-
case SyntaxKind.LiteralType: {
23021-
if (!isIndexedAccessTypeNode(node.parent.parent)) {
23022-
return undefined;
23023-
}
23024-
const objectType = getTypeFromTypeNode(node.parent.parent.objectType);
23025-
return getPropertyOfType(objectType, escapeLeadingUnderscores((node as StringLiteral | NumericLiteral).text));
23026-
}
23012+
if (node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).argumentExpression === node) {
23013+
const objectType = getTypeOfExpression((<ElementAccessExpression>node.parent).expression);
23014+
return getPropertyOfType(objectType, (<NumericLiteral>node).text as __String);
2302723015
}
2302823016
break;
2302923017
}

src/services/findAllReferences.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,11 @@ namespace ts.FindAllReferences.Core {
748748
return (node as Identifier).text.length === searchSymbolName.length;
749749

750750
case SyntaxKind.StringLiteral:
751-
return (isLiteralNameOfPropertyDeclarationOrIndexAccess(node as StringLiteral) || isNameOfExternalModuleImportOrDeclaration(node)) &&
751+
return (isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) &&
752752
(node as StringLiteral).text.length === searchSymbolName.length;
753753

754754
case SyntaxKind.NumericLiteral:
755-
return isLiteralNameOfPropertyDeclarationOrIndexAccess(node as NumericLiteral) && (node as NumericLiteral).text.length === searchSymbolName.length;
755+
return isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && (node as NumericLiteral).text.length === searchSymbolName.length;
756756

757757
default:
758758
return false;

src/services/rename.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,9 @@ namespace ts.Rename {
8989
}
9090

9191
function nodeIsEligibleForRename(node: Node): boolean {
92-
switch (node.kind) {
93-
case SyntaxKind.Identifier:
94-
case SyntaxKind.StringLiteral:
95-
case SyntaxKind.ThisKeyword:
96-
return true;
97-
case SyntaxKind.NumericLiteral:
98-
return isLiteralNameOfPropertyDeclarationOrIndexAccess(node as NumericLiteral);
99-
default:
100-
return false;
101-
}
92+
return node.kind === ts.SyntaxKind.Identifier ||
93+
node.kind === SyntaxKind.StringLiteral ||
94+
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) ||
95+
isThis(node);
10296
}
10397
}

src/services/utilities.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,25 +244,27 @@ namespace ts {
244244
isFunctionLike(node.parent) && (<FunctionLikeDeclaration>node.parent).name === node;
245245
}
246246

247-
export function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: StringLiteral | NumericLiteral): boolean {
248-
switch (node.parent.kind) {
249-
case SyntaxKind.PropertyDeclaration:
250-
case SyntaxKind.PropertySignature:
251-
case SyntaxKind.PropertyAssignment:
252-
case SyntaxKind.EnumMember:
253-
case SyntaxKind.MethodDeclaration:
254-
case SyntaxKind.MethodSignature:
255-
case SyntaxKind.GetAccessor:
256-
case SyntaxKind.SetAccessor:
257-
case SyntaxKind.ModuleDeclaration:
258-
return getNameOfDeclaration(<Declaration>node.parent) === node;
259-
case SyntaxKind.ElementAccessExpression:
260-
return (<ElementAccessExpression>node.parent).argumentExpression === node;
261-
case SyntaxKind.ComputedPropertyName:
262-
return true;
263-
case SyntaxKind.LiteralType:
264-
return node.parent.parent.kind === SyntaxKind.IndexedAccessType;
247+
export function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean {
248+
if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) {
249+
switch (node.parent.kind) {
250+
case SyntaxKind.PropertyDeclaration:
251+
case SyntaxKind.PropertySignature:
252+
case SyntaxKind.PropertyAssignment:
253+
case SyntaxKind.EnumMember:
254+
case SyntaxKind.MethodDeclaration:
255+
case SyntaxKind.MethodSignature:
256+
case SyntaxKind.GetAccessor:
257+
case SyntaxKind.SetAccessor:
258+
case SyntaxKind.ModuleDeclaration:
259+
return getNameOfDeclaration(<Declaration>node.parent) === node;
260+
case SyntaxKind.ElementAccessExpression:
261+
return (<ElementAccessExpression>node.parent).argumentExpression === node;
262+
case SyntaxKind.ComputedPropertyName:
263+
return true;
264+
}
265265
}
266+
267+
return false;
266268
}
267269

268270
export function isExpressionOfExternalModuleImportEqualsDeclaration(node: Node) {

tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)