add support for getReferences on property string index access
This commit is contained in:
parent
bfd13347d4
commit
fa1033ab7a
|
@ -2219,6 +2219,22 @@ module ts {
|
|||
return result;
|
||||
}
|
||||
|
||||
function isValidReferencePosition(node: Node, searchSymbol: Symbol): boolean {
|
||||
if (node) {
|
||||
var searchSymbolName = searchSymbol.getName();
|
||||
|
||||
// Compare the length so we filter out strict superstrings of the symbol we are looking for
|
||||
if (node.kind === SyntaxKind.Identifier && node.getWidth() === searchSymbolName.length) {
|
||||
return true;
|
||||
}
|
||||
else if (isIndexOfStringIndexAccess(node) && node.getWidth() === searchSymbolName.length + 2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getReferencesInNode(container: Node, searchSymbol: Symbol, result: ReferenceEntry[]): void {
|
||||
var searchSymbolName = searchSymbol.getName();
|
||||
|
||||
|
@ -2233,10 +2249,7 @@ module ts {
|
|||
// Each position we're searching for should be at the start of an identifier.
|
||||
var node = getNodeAtPosition(sourceFile, position);
|
||||
|
||||
///TODO: handle string properties
|
||||
|
||||
// Compare the length so we filter out strict superstrings of the symbol we are looking for
|
||||
if (!node || node.kind !== SyntaxKind.Identifier || node.getWidth() !== searchSymbolName.length) {
|
||||
if (!isValidReferencePosition(node, searchSymbol)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
18
tests/cases/fourslash/referencesForIndexProperty.ts
Normal file
18
tests/cases/fourslash/referencesForIndexProperty.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// References a class property using string index access
|
||||
|
||||
////class Foo {
|
||||
//// property: number;
|
||||
//// method(): void { }
|
||||
////}
|
||||
////
|
||||
////var f: Foo;
|
||||
////f[/*1*/"property"];
|
||||
////f[/*2*/"method"];
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.referencesCountIs(2);
|
9
tests/cases/fourslash/referencesForIndexProperty2.ts
Normal file
9
tests/cases/fourslash/referencesForIndexProperty2.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// References to a unknown index property
|
||||
|
||||
////var a;
|
||||
////a[/*1*/"blah"];
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(1);
|
19
tests/cases/fourslash/referencesForIndexProperty3.ts
Normal file
19
tests/cases/fourslash/referencesForIndexProperty3.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// References to a property of the apparent type using string indexer
|
||||
|
||||
////interface Object {
|
||||
//// toMyString();
|
||||
////}
|
||||
////
|
||||
////var y: Object;
|
||||
////y./*1*/toMyString();
|
||||
////
|
||||
////var x = {};
|
||||
////x[/*2*/"toMyString"]();
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(3);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.referencesCountIs(3);
|
Loading…
Reference in a new issue