diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index c3a8cc15b08..8ef72440bcc 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -62,11 +62,16 @@ namespace ts.FindAllReferences { node.parent.parent.left === node.parent ? node.parent.parent : undefined; - return binaryExpression && getAssignmentDeclarationKind(binaryExpression) !== AssignmentDeclarationKind.None ? - getDeclarationForDeclarationSpan(binaryExpression) : - undefined; + if (binaryExpression && getAssignmentDeclarationKind(binaryExpression) !== AssignmentDeclarationKind.None) { + return getDeclarationForDeclarationSpan(binaryExpression); + } } - return undefined; + + // Handle computed property name + const propertyName = findAncestor(node, isComputedPropertyName); + return propertyName ? + getDeclarationForDeclarationSpan(propertyName.parent) : + undefined; } if (isConstructorDeclaration(node.parent) || diff --git a/tests/cases/fourslash/renameContextuallyTypedProperties.ts b/tests/cases/fourslash/renameContextuallyTypedProperties.ts index 4ce3c2b0738..118c53be2b7 100644 --- a/tests/cases/fourslash/renameContextuallyTypedProperties.ts +++ b/tests/cases/fourslash/renameContextuallyTypedProperties.ts @@ -1,58 +1,58 @@ /// ////interface I { -//// [|prop1|]: () => void; +//// [|[|{| "declarationRangeIndex": 0 |}prop1|]: () => void;|] //// prop2(): void; ////} //// ////var o1: I = { -//// [|prop1|]() { }, +//// [|[|{| "declarationRangeIndex": 2 |}prop1|]() { }|], //// prop2() { } ////}; //// ////var o2: I = { -//// [|prop1|]: () => { }, +//// [|[|{| "declarationRangeIndex": 4 |}prop1|]: () => { }|], //// prop2: () => { } ////}; //// ////var o3: I = { -//// get [|prop1|]() { return () => { }; }, +//// [|get [|{| "declarationRangeIndex": 6 |}prop1|]() { return () => { }; }|], //// get prop2() { return () => { }; } ////}; //// ////var o4: I = { -//// set [|prop1|](v) { }, +//// [|set [|{| "declarationRangeIndex": 8 |}prop1|](v) { }|], //// set prop2(v) { } ////}; //// ////var o5: I = { -//// "[|prop1|]"() { }, +//// [|"[|{| "declarationRangeIndex": 10 |}prop1|]"() { }|], //// "prop2"() { } ////}; //// ////var o6: I = { -//// "[|prop1|]": function () { }, +//// [|"[|{| "declarationRangeIndex": 12 |}prop1|]": function () { }|], //// "prop2": function () { } ////}; //// ////var o7: I = { -//// ["[|prop1|]"]: function () { }, +//// [|["[|{| "declarationRangeIndex": 14 |}prop1|]"]: function () { }|], //// ["prop2"]: function () { } ////}; //// ////var o8: I = { -//// ["[|prop1|]"]() { }, +//// [|["[|{| "declarationRangeIndex": 16 |}prop1|]"]() { }|], //// ["prop2"]() { } ////}; //// ////var o9: I = { -//// get ["[|prop1|]"]() { return () => { }; }, +//// [|get ["[|{| "declarationRangeIndex": 18 |}prop1|]"]() { return () => { }; }|], //// get ["prop2"]() { return () => { }; } ////}; //// ////var o10: I = { -//// set ["[|prop1|]"](v) { }, +//// [|set ["[|{| "declarationRangeIndex": 20 |}prop1|]"](v) { }|], //// set ["prop2"](v) { } ////}; -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("prop1")); diff --git a/tests/cases/fourslash/renameContextuallyTypedProperties2.ts b/tests/cases/fourslash/renameContextuallyTypedProperties2.ts index 01e638395a0..5439a2215d2 100644 --- a/tests/cases/fourslash/renameContextuallyTypedProperties2.ts +++ b/tests/cases/fourslash/renameContextuallyTypedProperties2.ts @@ -2,57 +2,57 @@ ////interface I { //// prop1: () => void; -//// [|prop2|](): void; +//// [|[|{| "declarationRangeIndex": 0 |}prop2|](): void;|] ////} //// ////var o1: I = { //// prop1() { }, -//// [|prop2|]() { } +//// [|[|{| "declarationRangeIndex": 2 |}prop2|]() { }|] ////}; //// ////var o2: I = { //// prop1: () => { }, -//// [|prop2|]: () => { } +//// [|[|{| "declarationRangeIndex": 4 |}prop2|]: () => { }|] ////}; //// ////var o3: I = { //// get prop1() { return () => { }; }, -//// get [|prop2|]() { return () => { }; } +//// [|get [|{| "declarationRangeIndex": 6 |}prop2|]() { return () => { }; }|] ////}; //// ////var o4: I = { //// set prop1(v) { }, -//// set [|prop2|](v) { } +//// [|set [|{| "declarationRangeIndex": 8 |}prop2|](v) { }|] ////}; //// ////var o5: I = { //// "prop1"() { }, -//// "[|prop2|]"() { } +//// [|"[|{| "declarationRangeIndex": 10 |}prop2|]"() { }|] ////}; //// ////var o6: I = { //// "prop1": function () { }, -//// "[|prop2|]": function () { } +//// [|"[|{| "declarationRangeIndex": 12 |}prop2|]": function () { }|] ////}; //// ////var o7: I = { //// ["prop1"]: function () { }, -//// ["[|prop2|]"]: function () { } +//// [|["[|{| "declarationRangeIndex": 14 |}prop2|]"]: function () { }|] ////}; //// ////var o8: I = { //// ["prop1"]() { }, -//// ["[|prop2|]"]() { } +//// [|["[|{| "declarationRangeIndex": 16 |}prop2|]"]() { }|] ////}; //// ////var o9: I = { //// get ["prop1"]() { return () => { }; }, -//// get ["[|prop2|]"]() { return () => { }; } +//// [|get ["[|{| "declarationRangeIndex": 18 |}prop2|]"]() { return () => { }; }|] ////}; //// ////var o10: I = { //// set ["prop1"](v) { }, -//// set ["[|prop2|]"](v) { } +//// [|set ["[|{| "declarationRangeIndex": 20 |}prop2|]"](v) { }|] ////}; -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("prop2"));