Add prefix/suffix only to binding element name (#33538)

This commit is contained in:
Andrii Dieiev
2020-01-24 20:46:41 +02:00
committed by Ryan Cavanaugh
parent 9e712dd097
commit 420b478c65
3 changed files with 38 additions and 1 deletions

View File

@@ -363,7 +363,7 @@ namespace ts.FindAllReferences {
const { node, kind } = entry;
const name = originalNode.text;
const isShorthandAssignment = isShorthandPropertyAssignment(node.parent);
if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(node.parent)) {
if (isShorthandAssignment || isObjectBindingElementWithoutPropertyName(node.parent) && node.parent.name === node) {
const prefixColon: PrefixAndSuffix = { prefixText: name + ": " };
const suffixColon: PrefixAndSuffix = { suffixText: ": " + name };
return kind === EntryKind.SearchedLocalFoundProperty ? prefixColon

View File

@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts"/>
////[|const [|{| "contextRangeIndex": 0 |}external|] = true;|]
////
////function f({
//// lvl1 = [|external|],
//// nested: { lvl2 = [|external|]},
//// oldName: newName = [|external|]
////}) {}
////
////const {
//// lvl1 = [|external|],
//// nested: { lvl2 = [|external|]},
//// oldName: newName = [|external|]
////} = obj;
verify.rangesWithSameTextAreRenameLocations("external");

View File

@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts"/>
////function f([|{[|{| "contextRangeIndex": 0 |}required|], optional = [|required|]}: {[|[|{| "contextRangeIndex": 3 |}required|]: number,|] optional?: number}|]) {
//// console.log("required", [|required|]);
//// console.log("optional", optional);
////}
////
////f({[|[|{| "contextRangeIndex": 6 |}required|]: 10|]});
const [r0Def, r0, r1, r2Def, r2, r3, r4Def, r4] = test.ranges();
verify.renameLocations([r0, r1, r3], [
{ range: r0, prefixText: "required: " },
{ range: r1},
{ range: r3}
]);
verify.renameLocations([r2, r4], [
{ range: r0, suffixText: ": required" },
{ range: r2},
{ range: r4}
]);