Skip to content

Commit 78b1c53

Browse files
author
Andy
authored
Revert "Handle indexed access types in getSymbolAtLocation and findAllReferences (#17787)"
This reverts commit 30b3cb0.
1 parent 30b3cb0 commit 78b1c53

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
@@ -22905,7 +22905,7 @@ namespace ts {
2290522905
return undefined;
2290622906
}
2290722907

22908-
function getSymbolAtLocation(node: Node): Symbol | undefined {
22908+
function getSymbolAtLocation(node: Node) {
2290922909
if (node.kind === SyntaxKind.SourceFile) {
2291022910
return isExternalModule(<SourceFile>node) ? getMergedSymbol(node.symbol) : undefined;
2291122911
}
@@ -22983,21 +22983,9 @@ namespace ts {
2298322983

2298422984
case SyntaxKind.NumericLiteral:
2298522985
// index access
22986-
switch (node.parent.kind) {
22987-
case SyntaxKind.ElementAccessExpression: {
22988-
if ((<ElementAccessExpression>node.parent).argumentExpression !== node) {
22989-
return undefined;
22990-
}
22991-
const objectType = getTypeOfExpression((<ElementAccessExpression>node.parent).expression);
22992-
return getPropertyOfType(objectType, (<NumericLiteral>node).text as __String);
22993-
}
22994-
case SyntaxKind.LiteralType: {
22995-
if (!isIndexedAccessTypeNode(node.parent.parent)) {
22996-
return undefined;
22997-
}
22998-
const objectType = getTypeFromTypeNode(node.parent.parent.objectType);
22999-
return getPropertyOfType(objectType, escapeLeadingUnderscores((node as StringLiteral | NumericLiteral).text));
23000-
}
22986+
if (node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).argumentExpression === node) {
22987+
const objectType = getTypeOfExpression((<ElementAccessExpression>node.parent).expression);
22988+
return getPropertyOfType(objectType, (<NumericLiteral>node).text as __String);
2300122989
}
2300222990
break;
2300322991
}

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)