diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3f8406f3770..74c830ac7a6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22931,7 +22931,7 @@ namespace ts { return undefined; } - function getSymbolAtLocation(node: Node): Symbol | undefined { + function getSymbolAtLocation(node: Node) { if (node.kind === SyntaxKind.SourceFile) { return isExternalModule(node) ? getMergedSymbol(node.symbol) : undefined; } @@ -23009,21 +23009,9 @@ namespace ts { case SyntaxKind.NumericLiteral: // index access - switch (node.parent.kind) { - case SyntaxKind.ElementAccessExpression: { - if ((node.parent).argumentExpression !== node) { - return undefined; - } - const objectType = getTypeOfExpression((node.parent).expression); - return getPropertyOfType(objectType, (node).text as __String); - } - case SyntaxKind.LiteralType: { - if (!isIndexedAccessTypeNode(node.parent.parent)) { - return undefined; - } - const objectType = getTypeFromTypeNode(node.parent.parent.objectType); - return getPropertyOfType(objectType, escapeLeadingUnderscores((node as StringLiteral | NumericLiteral).text)); - } + if (node.parent.kind === SyntaxKind.ElementAccessExpression && (node.parent).argumentExpression === node) { + const objectType = getTypeOfExpression((node.parent).expression); + return getPropertyOfType(objectType, (node).text as __String); } break; } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 04d383748c8..4c8563b1b94 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -748,11 +748,11 @@ namespace ts.FindAllReferences.Core { return (node as Identifier).text.length === searchSymbolName.length; case SyntaxKind.StringLiteral: - return (isLiteralNameOfPropertyDeclarationOrIndexAccess(node as StringLiteral) || isNameOfExternalModuleImportOrDeclaration(node)) && + return (isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) && (node as StringLiteral).text.length === searchSymbolName.length; case SyntaxKind.NumericLiteral: - return isLiteralNameOfPropertyDeclarationOrIndexAccess(node as NumericLiteral) && (node as NumericLiteral).text.length === searchSymbolName.length; + return isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && (node as NumericLiteral).text.length === searchSymbolName.length; default: return false; diff --git a/src/services/rename.ts b/src/services/rename.ts index 8411e8200a3..6091c0b2d03 100644 --- a/src/services/rename.ts +++ b/src/services/rename.ts @@ -89,15 +89,9 @@ namespace ts.Rename { } function nodeIsEligibleForRename(node: Node): boolean { - switch (node.kind) { - case SyntaxKind.Identifier: - case SyntaxKind.StringLiteral: - case SyntaxKind.ThisKeyword: - return true; - case SyntaxKind.NumericLiteral: - return isLiteralNameOfPropertyDeclarationOrIndexAccess(node as NumericLiteral); - default: - return false; - } + return node.kind === ts.SyntaxKind.Identifier || + node.kind === SyntaxKind.StringLiteral || + isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || + isThis(node); } } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index c7f5b5909f0..e8f01bb0785 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -244,25 +244,27 @@ namespace ts { isFunctionLike(node.parent) && (node.parent).name === node; } - export function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: StringLiteral | NumericLiteral): boolean { - switch (node.parent.kind) { - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - case SyntaxKind.PropertyAssignment: - case SyntaxKind.EnumMember: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.ModuleDeclaration: - return getNameOfDeclaration(node.parent) === node; - case SyntaxKind.ElementAccessExpression: - return (node.parent).argumentExpression === node; - case SyntaxKind.ComputedPropertyName: - return true; - case SyntaxKind.LiteralType: - return node.parent.parent.kind === SyntaxKind.IndexedAccessType; + export function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean { + if (node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) { + switch (node.parent.kind) { + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.EnumMember: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.ModuleDeclaration: + return getNameOfDeclaration(node.parent) === node; + case SyntaxKind.ElementAccessExpression: + return (node.parent).argumentExpression === node; + case SyntaxKind.ComputedPropertyName: + return true; + } } + + return false; } export function isExpressionOfExternalModuleImportEqualsDeclaration(node: Node) { diff --git a/tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts b/tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts deleted file mode 100644 index 32f8207f27e..00000000000 --- a/tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts +++ /dev/null @@ -1,14 +0,0 @@ -/// - -////interface I { -//// [|{| "isDefinition": true, "isWriteAccess": true |}0|]: number; -//// [|{| "isDefinition": true, "isWriteAccess": true |}s|]: string; -////} -////interface J { -//// a: I[[|0|]], -//// b: I["[|s|]"], -////} - -const [n0, s0, n1, s1] = test.ranges(); -verify.singleReferenceGroup("(property) I[0]: number", [n0, n1]); -verify.singleReferenceGroup("(property) I.s: string", [s0, s1]);