mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Fix #8415: Add method declaration to contextually typed locations when searching for symbols
This commit is contained in:
parent
7f82bebb03
commit
13aff17975
@ -2583,8 +2583,17 @@ namespace ts {
|
||||
|
||||
/** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */
|
||||
function isNameOfPropertyAssignment(node: Node): boolean {
|
||||
return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) &&
|
||||
(node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) && (<PropertyDeclaration>node.parent).name === node;
|
||||
if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) {
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return (<PropertyDeclaration>node.parent).name === node;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean {
|
||||
|
||||
43
tests/cases/fourslash/renameContextuallyTypedProperties.ts
Normal file
43
tests/cases/fourslash/renameContextuallyTypedProperties.ts
Normal file
@ -0,0 +1,43 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I {
|
||||
//// [|prop1|]: () => void;
|
||||
//// prop2(): void;
|
||||
////}
|
||||
////
|
||||
////var o1: I = {
|
||||
//// [|prop1|]() { },
|
||||
//// prop2() { }
|
||||
////};
|
||||
////
|
||||
////var o2: I = {
|
||||
//// [|prop1|]: () => { },
|
||||
//// prop2: () => { }
|
||||
////};
|
||||
////
|
||||
////var o3: I = {
|
||||
//// get [|prop1|]() { return () => { }; },
|
||||
//// get prop2() { return () => { }; }
|
||||
////};
|
||||
////
|
||||
////var o4: I = {
|
||||
//// set [|prop1|](v) { },
|
||||
//// set prop2(v) { }
|
||||
////};
|
||||
////
|
||||
////var o5: I = {
|
||||
//// "[|prop1|]"() { },
|
||||
//// "prop2"() { }
|
||||
////};
|
||||
////
|
||||
////var o6: I = {
|
||||
//// "[|prop1|]": function () { },
|
||||
//// "prop2": function () { }
|
||||
////};
|
||||
|
||||
let ranges = test.ranges()
|
||||
for (let range of ranges) {
|
||||
goTo.file(range.fileName);
|
||||
goTo.position(range.start);
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
}
|
||||
43
tests/cases/fourslash/renameContextuallyTypedProperties2.ts
Normal file
43
tests/cases/fourslash/renameContextuallyTypedProperties2.ts
Normal file
@ -0,0 +1,43 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I {
|
||||
//// prop1: () => void;
|
||||
//// [|prop2|](): void;
|
||||
////}
|
||||
////
|
||||
////var o1: I = {
|
||||
//// prop1() { },
|
||||
//// [|prop2|]() { }
|
||||
////};
|
||||
////
|
||||
////var o2: I = {
|
||||
//// prop1: () => { },
|
||||
//// [|prop2|]: () => { }
|
||||
////};
|
||||
////
|
||||
////var o3: I = {
|
||||
//// get prop1() { return () => { }; },
|
||||
//// get [|prop2|]() { return () => { }; }
|
||||
////};
|
||||
////
|
||||
////var o4: I = {
|
||||
//// set prop1(v) { },
|
||||
//// set [|prop2|](v) { }
|
||||
////};
|
||||
////
|
||||
////var o5: I = {
|
||||
//// "prop1"() { },
|
||||
//// "[|prop2|]"() { }
|
||||
////};
|
||||
////
|
||||
////var o6: I = {
|
||||
//// "prop1": function () { },
|
||||
//// "[|prop2|]": function () { }
|
||||
////};
|
||||
|
||||
let ranges = test.ranges()
|
||||
for (let range of ranges) {
|
||||
goTo.file(range.fileName);
|
||||
goTo.position(range.start);
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user