diff --git a/src/services/services.ts b/src/services/services.ts index ececc1082ca..a4f1bb8563a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4044,7 +4044,16 @@ module ts { break; case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: - nameTable[(node).text] = (node).text; + // We want to store any numbers/strings if they were a name that could be + // related to a declaration. So, if we have 'import x = require("something")' + // then we want 'something' to be in the name table. Similarly, if we have + // "a['propname']" then we want to store "propname" in the name table. + if (isDeclarationName(node) || + node.parent.kind === SyntaxKind.ExternalModuleReference || + isArgumentOfElementAccessExpression(node)) { + + nameTable[(node).text] = (node).text; + } break; default: forEachChild(node, walk); @@ -4052,6 +4061,13 @@ module ts { } } + function isArgumentOfElementAccessExpression(node: Node) { + return node && + node.parent && + node.parent.kind === SyntaxKind.ElementAccessExpression && + (node.parent).argumentExpression === node; + } + function getReferencesForNode(node: Node, sourceFiles: SourceFile[], searchOnlyInCurrentFile: boolean, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { // Labels if (isLabelName(node)) {