diff --git a/src/services/services.ts b/src/services/services.ts
index 143594e75c..1974ece9e4 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -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;
}
diff --git a/tests/cases/fourslash/referencesForIndexProperty.ts b/tests/cases/fourslash/referencesForIndexProperty.ts
new file mode 100644
index 0000000000..96ae1ff05e
--- /dev/null
+++ b/tests/cases/fourslash/referencesForIndexProperty.ts
@@ -0,0 +1,18 @@
+///
+
+// 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);
diff --git a/tests/cases/fourslash/referencesForIndexProperty2.ts b/tests/cases/fourslash/referencesForIndexProperty2.ts
new file mode 100644
index 0000000000..a84adf672a
--- /dev/null
+++ b/tests/cases/fourslash/referencesForIndexProperty2.ts
@@ -0,0 +1,9 @@
+///
+
+// References to a unknown index property
+
+////var a;
+////a[/*1*/"blah"];
+
+goTo.marker("1");
+verify.referencesCountIs(1);
\ No newline at end of file
diff --git a/tests/cases/fourslash/referencesForIndexProperty3.ts b/tests/cases/fourslash/referencesForIndexProperty3.ts
new file mode 100644
index 0000000000..72a2b560b4
--- /dev/null
+++ b/tests/cases/fourslash/referencesForIndexProperty3.ts
@@ -0,0 +1,19 @@
+///
+
+// 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);