@@ -58,9 +58,10 @@ module ts {
5858 }
5959
6060 export interface SourceFile {
61- version : string ;
62- scriptSnapshot : IScriptSnapshot ;
63- nameTable : Map < string > ;
61+ /* @internal */ version : string ;
62+ /* @internal */ scriptSnapshot : IScriptSnapshot ;
63+ /* @internal */ nameTable : Map < string > ;
64+
6465 getNamedDeclarations ( ) : Declaration [ ] ;
6566 getLineAndCharacterOfPosition ( pos : number ) : LineAndCharacter ;
6667 getLineStarts ( ) : number [ ] ;
@@ -4138,27 +4139,6 @@ module ts {
41384139 return getReferencesForNode ( node , program . getSourceFiles ( ) , /*searchOnlyInCurrentFile*/ false , findInStrings , findInComments ) ;
41394140 }
41404141
4141- function initializeNameTable ( sourceFile : SourceFile ) : void {
4142- var nameTable : Map < string > = { } ;
4143-
4144- walk ( sourceFile ) ;
4145- sourceFile . nameTable = nameTable ;
4146-
4147- function walk ( node : Node ) {
4148- switch ( node . kind ) {
4149- case SyntaxKind . Identifier :
4150- nameTable [ ( < Identifier > node ) . text ] = ( < Identifier > node ) . text ;
4151- break ;
4152- case SyntaxKind . StringLiteral :
4153- case SyntaxKind . NumericLiteral :
4154- nameTable [ ( < LiteralExpression > node ) . text ] = ( < LiteralExpression > node ) . text ;
4155- break ;
4156- default :
4157- forEachChild ( node , walk ) ;
4158- }
4159- }
4160- }
4161-
41624142 function getReferencesForNode ( node : Node , sourceFiles : SourceFile [ ] , searchOnlyInCurrentFile : boolean , findInStrings : boolean , findInComments : boolean ) : ReferenceEntry [ ] {
41634143 // Labels
41644144 if ( isLabelName ( node ) ) {
@@ -4225,13 +4205,9 @@ module ts {
42254205 forEach ( sourceFiles , sourceFile => {
42264206 cancellationToken . throwIfCancellationRequested ( ) ;
42274207
4228- if ( ! sourceFile . nameTable ) {
4229- initializeNameTable ( sourceFile )
4230- }
4208+ var nameTable = getNameTable ( sourceFile ) ;
42314209
4232- Debug . assert ( sourceFile . nameTable !== undefined ) ;
4233-
4234- if ( lookUp ( sourceFile . nameTable , internedName ) ) {
4210+ if ( lookUp ( nameTable , internedName ) ) {
42354211 result = result || [ ] ;
42364212 getReferencesInNode ( sourceFile , symbol , declaredName , node , searchMeaning , findInStrings , findInComments , result ) ;
42374213 }
@@ -5775,6 +5751,52 @@ module ts {
57755751 } ;
57765752 }
57775753
5754+ /* @internal */
5755+ export function getNameTable ( sourceFile : SourceFile ) : Map < string > {
5756+ if ( ! sourceFile . nameTable ) {
5757+ initializeNameTable ( sourceFile )
5758+ }
5759+
5760+ return sourceFile . nameTable ;
5761+ }
5762+
5763+ function initializeNameTable ( sourceFile : SourceFile ) : void {
5764+ var nameTable : Map < string > = { } ;
5765+
5766+ walk ( sourceFile ) ;
5767+ sourceFile . nameTable = nameTable ;
5768+
5769+ function walk ( node : Node ) {
5770+ switch ( node . kind ) {
5771+ case SyntaxKind . Identifier :
5772+ nameTable [ ( < Identifier > node ) . text ] = ( < Identifier > node ) . text ;
5773+ break ;
5774+ case SyntaxKind . StringLiteral :
5775+ case SyntaxKind . NumericLiteral :
5776+ // We want to store any numbers/strings if they were a name that could be
5777+ // related to a declaration. So, if we have 'import x = require("something")'
5778+ // then we want 'something' to be in the name table. Similarly, if we have
5779+ // "a['propname']" then we want to store "propname" in the name table.
5780+ if ( isDeclarationName ( node ) ||
5781+ node . parent . kind === SyntaxKind . ExternalModuleReference ||
5782+ isArgumentOfElementAccessExpression ( node ) ) {
5783+
5784+ nameTable [ ( < LiteralExpression > node ) . text ] = ( < LiteralExpression > node ) . text ;
5785+ }
5786+ break ;
5787+ default :
5788+ forEachChild ( node , walk ) ;
5789+ }
5790+ }
5791+ }
5792+
5793+ function isArgumentOfElementAccessExpression ( node : Node ) {
5794+ return node &&
5795+ node . parent &&
5796+ node . parent . kind === SyntaxKind . ElementAccessExpression &&
5797+ ( < ElementAccessExpression > node . parent ) . argumentExpression === node ;
5798+ }
5799+
57785800 /// Classifier
57795801 export function createClassifier ( ) : Classifier {
57805802 var scanner = createScanner ( ScriptTarget . Latest , /*skipTrivia*/ false ) ;
0 commit comments