Handle destructuring assignments
This commit is contained in:
parent
c0537d9bad
commit
0fee3b023d
|
@ -81,7 +81,7 @@ namespace ts.FindAllReferences {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
export function getDeclarationForDeclarationSpan(node: NamedDeclaration | BinaryExpression | undefined): DeclarationNode | undefined {
|
||||
export function getDeclarationForDeclarationSpan(node: NamedDeclaration | BinaryExpression | ForInOrOfStatement | undefined): DeclarationNode | undefined {
|
||||
if (!node) return undefined;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
|
@ -90,8 +90,8 @@ namespace ts.FindAllReferences {
|
|||
isVariableStatement(node.parent.parent) ?
|
||||
node.parent.parent :
|
||||
isForInOrOfStatement(node.parent.parent) ?
|
||||
{ start: node.parent.parent.initializer, end: node.parent.parent.expression } :
|
||||
node.parent;
|
||||
getDeclarationForDeclarationSpan(node.parent.parent) :
|
||||
node.parent;
|
||||
|
||||
case SyntaxKind.BindingElement:
|
||||
return getDeclarationForDeclarationSpan(node.parent.parent as NamedDeclaration);
|
||||
|
@ -114,12 +114,27 @@ namespace ts.FindAllReferences {
|
|||
case SyntaxKind.BinaryExpression:
|
||||
return isExpressionStatement(node.parent) ?
|
||||
node.parent :
|
||||
undefined;
|
||||
node;
|
||||
|
||||
// Not really interesting definition
|
||||
case SyntaxKind.ForOfStatement:
|
||||
case SyntaxKind.ForInStatement:
|
||||
return {
|
||||
start: (node as ForInOrOfStatement).initializer,
|
||||
end: (node as ForInOrOfStatement).expression
|
||||
};
|
||||
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
// TODO(shkamat):: Should we show whole object literal instead?
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
return undefined;
|
||||
return isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent) ?
|
||||
getDeclarationForDeclarationSpan(
|
||||
findAncestor(node.parent, node =>
|
||||
isBinaryExpression(node) || isForInOrOfStatement(node)
|
||||
) as BinaryExpression | ForInOrOfStatement
|
||||
) :
|
||||
node.kind === SyntaxKind.PropertyAssignment ?
|
||||
node :
|
||||
undefined;
|
||||
|
||||
default:
|
||||
return node;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I {
|
||||
//// [|x|]: number;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}x|]: number;|]
|
||||
////}
|
||||
////var a: I;
|
||||
////var x;
|
||||
////({ [|x|]: x } = a);
|
||||
////([|{ [|{| "declarationRangeIndex": 2 |}x|]: x } = a|]);
|
||||
|
||||
verify.rangesAreRenameLocations();
|
||||
verify.rangesAreRenameLocations(test.rangesByText().get("x"));
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I {
|
||||
//// [|property1|]: number;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|]
|
||||
//// property2: string;
|
||||
////}
|
||||
////var elems: I[];
|
||||
////
|
||||
////var p2: number, [|property1|]: number;
|
||||
////for ({ [|property1|] } = elems[0]; p2 < 100; p2++) {
|
||||
////var p2: number, [|[|{| "declarationRangeIndex": 2 |}property1|]: number|];
|
||||
////for ([|{ [|{| "declarationRangeIndex": 4 |}property1|] } = elems[0]|]; p2 < 100; p2++) {
|
||||
//// p2 = [|property1|]++;
|
||||
////}
|
||||
////for ({ [|property1|]: p2 } = elems[0]; p2 < 100; p2++) {
|
||||
////for ([|{ [|{| "declarationRangeIndex": 7 |}property1|]: p2 } = elems[0]|]; p2 < 100; p2++) {
|
||||
////}
|
||||
|
||||
verify.noErrors();
|
||||
const ranges = test.ranges();
|
||||
const [r0, r1, r2, r3, r4] = ranges;
|
||||
const [r0Def, r0, r1Def, r1, r2Def, r2, r3, r4Def, r4] = ranges;
|
||||
verify.renameLocations([r0, r4], [r0, { range: r2, suffixText: ": property1" }, r4]);
|
||||
verify.renameLocations([r1, r2, r3], [r1, { range: r2, prefixText: "property1: " }, r3]);
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I {
|
||||
//// [|property1|]: number;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|]
|
||||
//// property2: string;
|
||||
////}
|
||||
////var elems: I[];
|
||||
////
|
||||
////var [|property1|]: number, p2: number;
|
||||
////for ({ [|property1|] } of elems) {
|
||||
////var [|[|{| "declarationRangeIndex": 2 |}property1|]: number|], p2: number;
|
||||
////for ([|{ [|{| "declarationRangeIndex": 4 |}property1|] } of elems|]) {
|
||||
//// [|property1|]++;
|
||||
////}
|
||||
////for ({ [|property1|]: p2 } of elems) {
|
||||
////for ([|{ [|{| "declarationRangeIndex": 7 |}property1|]: p2 } of elems|]) {
|
||||
////}
|
||||
|
||||
verify.noErrors();
|
||||
const ranges = test.ranges();
|
||||
const [r0, r1, r2, r3, r4] = ranges;
|
||||
const [r0Def, r0, r1Def, r1, r2Def, r2, r3, r4Def, r4] = ranges;
|
||||
verify.renameLocations([r0, r4], [r0, { range: r2, suffixText: ": property1" }, r4]);
|
||||
verify.renameLocations([r1, r2, r3], [r1, { range: r2, prefixText: "property1: " }, r3]);
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I {
|
||||
//// [|property1|]: number;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|]
|
||||
//// property2: string;
|
||||
////}
|
||||
////var elems: I[], p1: number, [|property1|]: number;
|
||||
////[{ [|property1|]: p1 }] = elems;
|
||||
////[{ [|property1|] }] = elems;
|
||||
////var elems: I[], p1: number, [|[|{| "declarationRangeIndex": 2 |}property1|]: number|];
|
||||
////[|[{ [|{| "declarationRangeIndex": 4 |}property1|]: p1 }] = elems;|]
|
||||
////[|[{ [|{| "declarationRangeIndex": 6 |}property1|] }] = elems;|]
|
||||
|
||||
const ranges = test.ranges();
|
||||
const [r0, r1, r2, r3] = ranges;
|
||||
const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3] = ranges;
|
||||
verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": property1" }]);
|
||||
verify.renameLocations([r1, r3], [r1, { range: r3, prefixText: "property1: " }]);
|
||||
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
////interface MultiRobot {
|
||||
//// name: string;
|
||||
//// skills: {
|
||||
//// [|primary|]: string;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|]
|
||||
//// secondary: string;
|
||||
//// };
|
||||
////}
|
||||
////let multiRobot: MultiRobot, [|primary|]: string, secondary: string, primaryA: string, secondaryA: string, i: number;
|
||||
////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) {
|
||||
////let multiRobot: MultiRobot, [|[|{| "declarationRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string, i: number;
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } = multiRobot|], i = 0; i < 1; i++) {
|
||||
//// primaryA;
|
||||
////}
|
||||
////for ({ skills: { [|primary|], secondary } } = multiRobot, i = 0; i < 1; i++) {
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } = multiRobot|], i = 0; i < 1; i++) {
|
||||
//// [|primary|];
|
||||
////}
|
||||
|
||||
verify.noErrors();
|
||||
const ranges = test.ranges();
|
||||
const [r0, r1, r2, r3, r4] = ranges;
|
||||
const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = ranges;
|
||||
verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]);
|
||||
verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4]);
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
////interface MultiRobot {
|
||||
//// name: string;
|
||||
//// skills: {
|
||||
//// [|primary|]: string;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|]
|
||||
//// secondary: string;
|
||||
//// };
|
||||
////}
|
||||
////let multiRobot: MultiRobot, [|primary|]: string, secondary: string, primaryA: string, secondaryA: string, i: number;
|
||||
////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) {
|
||||
////let multiRobot: MultiRobot, [|[|{| "declarationRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string, i: number;
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } = multiRobot|], i = 0; i < 1; i++) {
|
||||
//// primaryA;
|
||||
////}
|
||||
////for ({ skills: { [|primary|], secondary } } = multiRobot, i = 0; i < 1; i++) {
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } = multiRobot|], i = 0; i < 1; i++) {
|
||||
//// [|primary|];
|
||||
////}
|
||||
|
||||
verify.noErrors();
|
||||
const ranges = test.ranges();
|
||||
const [r0, r1, r2, r3, r4] = ranges;
|
||||
const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = ranges;
|
||||
verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]);
|
||||
verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4]);
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
////interface MultiRobot {
|
||||
//// name: string;
|
||||
//// skills: {
|
||||
//// [|primary|]: string;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|]
|
||||
//// secondary: string;
|
||||
//// };
|
||||
////}
|
||||
////let multiRobots: MultiRobot[];
|
||||
////let [|primary|]: string, secondary: string, primaryA: string, secondaryA: string;
|
||||
////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } of multiRobots) {
|
||||
////let [|[|{| "declarationRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string;
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } of multiRobots|]) {
|
||||
//// primaryA;
|
||||
////}
|
||||
////for ({ skills: { [|primary|], secondary } } of multiRobots) {
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } of multiRobots|]) {
|
||||
//// [|primary|];
|
||||
////}
|
||||
|
||||
verify.noErrors();
|
||||
const [r0, r1, r2, r3, r4] = test.ranges();
|
||||
const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = test.ranges();
|
||||
verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]);
|
||||
verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4])
|
||||
|
|
|
@ -3,19 +3,19 @@
|
|||
////interface MultiRobot {
|
||||
//// name: string;
|
||||
//// skills: {
|
||||
//// [|primary|]: string;
|
||||
//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|]
|
||||
//// secondary: string;
|
||||
//// };
|
||||
////}
|
||||
////let multiRobots: MultiRobot[], [|primary|]: string;
|
||||
////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } of multiRobots) {
|
||||
////let multiRobots: MultiRobot[], [|[|{| "declarationRangeIndex": 2 |}primary|]: string|];
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } of multiRobots|]) {
|
||||
//// console.log(primaryA);
|
||||
////}
|
||||
////for ({ skills: { [|primary|], secondary } } of multiRobots) {
|
||||
////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } of multiRobots|]) {
|
||||
//// console.log([|primary|]);
|
||||
////}
|
||||
|
||||
const ranges = test.ranges();
|
||||
const [r0, r1, r2, r3, r4] = ranges;
|
||||
const [r0Def, r0, r1Def, r1,r2Def, r2, r3Def, r3, r4] = ranges;
|
||||
verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]);
|
||||
verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4]);
|
||||
|
|
Loading…
Reference in a new issue