diff --git a/src/services/services.ts b/src/services/services.ts index 65eba7e0a65..efee09e01e6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4138,43 +4138,6 @@ module ts { return getReferencesForNode(node, program.getSourceFiles(), /*searchOnlyInCurrentFile*/ false, findInStrings, findInComments); } - function initializeNameTable(sourceFile: SourceFile): void { - var nameTable: Map = {}; - - walk(sourceFile); - sourceFile.nameTable = nameTable; - - function walk(node: Node) { - switch (node.kind) { - case SyntaxKind.Identifier: - nameTable[(node).text] = (node).text; - break; - case SyntaxKind.StringLiteral: - case SyntaxKind.NumericLiteral: - // 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); - } - } - } - - 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)) { @@ -4241,13 +4204,9 @@ module ts { forEach(sourceFiles, sourceFile => { cancellationToken.throwIfCancellationRequested(); - if (!sourceFile.nameTable) { - initializeNameTable(sourceFile) - } + var nameTable = getNameTable(sourceFile); - Debug.assert(sourceFile.nameTable !== undefined); - - if (lookUp(sourceFile.nameTable, internedName)) { + if (lookUp(nameTable, internedName)) { result = result || []; getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } @@ -5791,6 +5750,52 @@ module ts { }; } + /* @internal */ + export function getNameTable(sourceFile: SourceFile): Map { + if (!sourceFile.nameTable) { + initializeNameTable(sourceFile) + } + + return sourceFile.nameTable; + } + + function initializeNameTable(sourceFile: SourceFile): void { + var nameTable: Map = {}; + + walk(sourceFile); + sourceFile.nameTable = nameTable; + + function walk(node: Node) { + switch (node.kind) { + case SyntaxKind.Identifier: + nameTable[(node).text] = (node).text; + break; + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + // 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); + } + } + } + + function isArgumentOfElementAccessExpression(node: Node) { + return node && + node.parent && + node.parent.kind === SyntaxKind.ElementAccessExpression && + (node.parent).argumentExpression === node; + } + /// Classifier export function createClassifier(): Classifier { var scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ false);