@@ -58,9 +58,10 @@ module ts {
58
58
}
59
59
60
60
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
+
64
65
getNamedDeclarations ( ) : Declaration [ ] ;
65
66
getLineAndCharacterOfPosition ( pos : number ) : LineAndCharacter ;
66
67
getLineStarts ( ) : number [ ] ;
@@ -4138,27 +4139,6 @@ module ts {
4138
4139
return getReferencesForNode ( node , program . getSourceFiles ( ) , /*searchOnlyInCurrentFile*/ false , findInStrings , findInComments ) ;
4139
4140
}
4140
4141
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
-
4162
4142
function getReferencesForNode ( node : Node , sourceFiles : SourceFile [ ] , searchOnlyInCurrentFile : boolean , findInStrings : boolean , findInComments : boolean ) : ReferenceEntry [ ] {
4163
4143
// Labels
4164
4144
if ( isLabelName ( node ) ) {
@@ -4225,13 +4205,9 @@ module ts {
4225
4205
forEach ( sourceFiles , sourceFile => {
4226
4206
cancellationToken . throwIfCancellationRequested ( ) ;
4227
4207
4228
- if ( ! sourceFile . nameTable ) {
4229
- initializeNameTable ( sourceFile )
4230
- }
4208
+ var nameTable = getNameTable ( sourceFile ) ;
4231
4209
4232
- Debug . assert ( sourceFile . nameTable !== undefined ) ;
4233
-
4234
- if ( lookUp ( sourceFile . nameTable , internedName ) ) {
4210
+ if ( lookUp ( nameTable , internedName ) ) {
4235
4211
result = result || [ ] ;
4236
4212
getReferencesInNode ( sourceFile , symbol , declaredName , node , searchMeaning , findInStrings , findInComments , result ) ;
4237
4213
}
@@ -5775,6 +5751,52 @@ module ts {
5775
5751
} ;
5776
5752
}
5777
5753
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
+
5778
5800
/// Classifier
5779
5801
export function createClassifier ( ) : Classifier {
5780
5802
var scanner = createScanner ( ScriptTarget . Latest , /*skipTrivia*/ false ) ;
0 commit comments