@@ -367,6 +367,10 @@ module ts {
367
367
identifiers . push ( ( < Identifier > node ) . text ) ;
368
368
return undefined ;
369
369
case SyntaxKind . StringLiteral :
370
+ if ( isNameOfExternalModuleImportOrDeclaration ( node ) ) {
371
+ identifiers . push ( ( < LiteralExpression > node ) . text ) ;
372
+ }
373
+ // intential fall through
370
374
case SyntaxKind . NumericLiteral :
371
375
if ( isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) ) {
372
376
identifiers . push ( ( < LiteralExpression > node ) . text ) ;
@@ -1322,6 +1326,12 @@ module ts {
1322
1326
return false ;
1323
1327
}
1324
1328
1329
+ function isNameOfExternalModuleImportOrDeclaration ( node : Node ) : boolean {
1330
+ return node . kind === SyntaxKind . StringLiteral &&
1331
+ ( ( node . parent . kind === SyntaxKind . ModuleDeclaration && ( < ModuleDeclaration > node . parent ) . name === node ) ||
1332
+ ( node . parent . kind === SyntaxKind . ImportDeclaration && ( < ImportDeclaration > node . parent ) . externalModuleName === node ) ) ;
1333
+ }
1334
+
1325
1335
enum SearchMeaning {
1326
1336
Value = 0x1 ,
1327
1337
Type = 0x2 ,
@@ -2126,7 +2136,9 @@ module ts {
2126
2136
return undefined ;
2127
2137
}
2128
2138
2129
- if ( node . kind !== SyntaxKind . Identifier && ! isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) ) {
2139
+ if ( node . kind !== SyntaxKind . Identifier &&
2140
+ ! isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) &&
2141
+ ! isNameOfExternalModuleImportOrDeclaration ( node ) ) {
2130
2142
return undefined ;
2131
2143
}
2132
2144
@@ -2163,27 +2175,36 @@ module ts {
2163
2175
// Compute the meaning from the location and the symbol it references
2164
2176
var searchMeaning = getIntersectingMeaningFromDeclarations ( getMeaningFromLocation ( node ) , symbol . getDeclarations ( ) ) ;
2165
2177
2178
+ // Get the text to search for, we need to normalize it as external module names will have quote
2179
+ var symbolName = getNormalizedSymbolName ( symbol . getName ( ) ) ;
2180
+
2166
2181
var scope = getSymbolScope ( symbol ) ;
2167
2182
2168
2183
if ( scope ) {
2169
2184
result = [ ] ;
2170
- getReferencesInNode ( scope , symbol , node , searchMeaning , result ) ;
2185
+ getReferencesInNode ( scope , symbol , symbolName , node , searchMeaning , result ) ;
2171
2186
}
2172
2187
else {
2173
- var symbolName = symbol . getName ( ) ;
2174
-
2175
2188
forEach ( program . getSourceFiles ( ) , sourceFile => {
2176
2189
cancellationToken . throwIfCancellationRequested ( ) ;
2177
2190
2178
2191
if ( sourceFile . getBloomFilter ( ) . probablyContains ( symbolName ) ) {
2179
2192
result = result || [ ] ;
2180
- getReferencesInNode ( sourceFile , symbol , node , searchMeaning , result ) ;
2193
+ getReferencesInNode ( sourceFile , symbol , symbolName , node , searchMeaning , result ) ;
2181
2194
}
2182
2195
} ) ;
2183
2196
}
2184
2197
2185
2198
return result ;
2186
2199
2200
+ function getNormalizedSymbolName ( name : string ) : string {
2201
+ var length = name . length ;
2202
+ if ( length >= 2 && name . charCodeAt ( 0 ) === CharacterCodes . doubleQuote && name . charCodeAt ( length - 1 ) === CharacterCodes . doubleQuote ) {
2203
+ return name . substring ( 1 , length - 1 ) ;
2204
+ } ;
2205
+ return name ;
2206
+ }
2207
+
2187
2208
function getSymbolScope ( symbol : Symbol ) : Node {
2188
2209
// If this is private property or method, the scope is the containing class
2189
2210
if ( symbol . getFlags ( ) && ( SymbolFlags . Property | SymbolFlags . Method ) ) {
@@ -2281,17 +2302,16 @@ module ts {
2281
2302
return result ;
2282
2303
}
2283
2304
2284
- function isValidReferencePosition ( node : Node , searchSymbol : Symbol ) : boolean {
2305
+ function isValidReferencePosition ( node : Node , searchSymbolName : string ) : boolean {
2285
2306
if ( node ) {
2286
- var searchSymbolName = searchSymbol . getName ( ) ;
2287
-
2288
2307
// Compare the length so we filter out strict superstrings of the symbol we are looking for
2289
2308
switch ( node . kind ) {
2290
2309
case SyntaxKind . Identifier :
2291
2310
return node . getWidth ( ) === searchSymbolName . length ;
2292
2311
2293
2312
case SyntaxKind . StringLiteral :
2294
- if ( isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) ) {
2313
+ if ( isLiteralNameOfPropertyDeclarationOrIndexAccess ( node ) ||
2314
+ isNameOfExternalModuleImportOrDeclaration ( node ) ) {
2295
2315
// For string literals we have two additional chars for the quotes
2296
2316
return node . getWidth ( ) === searchSymbolName . length + 2 ;
2297
2317
}
@@ -2309,14 +2329,12 @@ module ts {
2309
2329
}
2310
2330
2311
2331
/// Search within node "container" for references for a search value, where the search value is defined as a
2312
- /// tuple of(searchSymbol, searchLocation, and searchMeaning).
2332
+ /// tuple of(searchSymbol, searchText, searchLocation, and searchMeaning).
2313
2333
/// searchLocation: a node where the search value
2314
- function getReferencesInNode ( container : Node , searchSymbol : Symbol , searchLocation : Node , searchMeaning : SearchMeaning , result : ReferenceEntry [ ] ) : void {
2315
- var searchSymbolName = searchSymbol . getName ( ) ;
2316
-
2334
+ function getReferencesInNode ( container : Node , searchSymbol : Symbol , searchText : string , searchLocation : Node , searchMeaning : SearchMeaning , result : ReferenceEntry [ ] ) : void {
2317
2335
var sourceFile = container . getSourceFile ( ) ;
2318
2336
2319
- var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , searchSymbolName , container . getStart ( ) , container . getEnd ( ) ) ;
2337
+ var possiblePositions = getPossibleSymbolReferencePositions ( sourceFile , searchText , container . getStart ( ) , container . getEnd ( ) ) ;
2320
2338
2321
2339
if ( possiblePositions . length ) {
2322
2340
// Build the set of symbols to search for, initially it has only the current symbol
@@ -2326,7 +2344,7 @@ module ts {
2326
2344
cancellationToken . throwIfCancellationRequested ( ) ;
2327
2345
2328
2346
var referenceLocation = getNodeAtPosition ( sourceFile , position ) ;
2329
- if ( ! isValidReferencePosition ( referenceLocation , searchSymbol ) ) {
2347
+ if ( ! isValidReferencePosition ( referenceLocation , searchText ) ) {
2330
2348
return ;
2331
2349
}
2332
2350
0 commit comments