Skip to content

Commit 420b478

Browse files
IllusionMHRyanCavanaugh
authored andcommitted
Add prefix/suffix only to binding element name (microsoft#33538)
1 parent 9e712dd commit 420b478

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/services/findAllReferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ namespace ts.FindAllReferences {
363363
const { node, kind } = entry;
364364
const name = originalNode.text;
365365
const isShorthandAssignment = isShorthandPropertyAssignment(node.parent);
366-
if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(node.parent)) {
366+
if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(node.parent) && node.parent.name === node) {
367367
const prefixColon: PrefixAndSuffix = { prefixText: name + ": " };
368368
const suffixColon: PrefixAndSuffix = { suffixText: ": " + name };
369369
return kind === EntryKind.SearchedLocalFoundProperty ? prefixColon
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////[|const [|{| "contextRangeIndex": 0 |}external|] = true;|]
4+
////
5+
////function f({
6+
//// lvl1 = [|external|],
7+
//// nested: { lvl2 = [|external|]},
8+
//// oldName: newName = [|external|]
9+
////}) {}
10+
////
11+
////const {
12+
//// lvl1 = [|external|],
13+
//// nested: { lvl2 = [|external|]},
14+
//// oldName: newName = [|external|]
15+
////} = obj;
16+
17+
verify.rangesWithSameTextAreRenameLocations("external");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////function f([|{[|{| "contextRangeIndex": 0 |}required|], optional = [|required|]}: {[|[|{| "contextRangeIndex": 3 |}required|]: number,|] optional?: number}|]) {
4+
//// console.log("required", [|required|]);
5+
//// console.log("optional", optional);
6+
////}
7+
////
8+
////f({[|[|{| "contextRangeIndex": 6 |}required|]: 10|]});
9+
10+
const [r0Def, r0, r1, r2Def, r2, r3, r4Def, r4] = test.ranges();
11+
verify.renameLocations([r0, r1, r3], [
12+
{ range: r0, prefixText: "required: " },
13+
{ range: r1},
14+
{ range: r3}
15+
]);
16+
verify.renameLocations([r2, r4], [
17+
{ range: r0, suffixText: ": required" },
18+
{ range: r2},
19+
{ range: r4}
20+
]);

0 commit comments

Comments
 (0)