@@ -43,7 +43,7 @@ namespace ts.FindAllReferences {
43
43
44
44
export function findReferencedSymbols ( program : Program , cancellationToken : CancellationToken , sourceFiles : ReadonlyArray < SourceFile > , sourceFile : SourceFile , position : number ) : ReferencedSymbol [ ] | undefined {
45
45
const node = getTouchingPropertyName ( sourceFile , position , /*includeJsDocComment*/ true ) ;
46
- const referencedSymbols = Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , /*options*/ { } ) ;
46
+ const referencedSymbols = Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken ) ;
47
47
const checker = program . getTypeChecker ( ) ;
48
48
return ! referencedSymbols || ! referencedSymbols . length ? undefined : mapDefined < SymbolAndEntries , ReferencedSymbol > ( referencedSymbols , ( { definition, references } ) =>
49
49
// Only include referenced symbols that have a valid definition.
@@ -88,8 +88,8 @@ namespace ts.FindAllReferences {
88
88
return map ( flattenEntries ( Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , options ) ) , toReferenceEntry ) ;
89
89
}
90
90
91
- export function getReferenceEntriesForNode ( position : number , node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } ) : Entry [ ] | undefined {
92
- return flattenEntries ( Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , options ) ) ;
91
+ export function getReferenceEntriesForNode ( position : number , node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } , sourceFilesSet : ReadonlyMap < true > = arrayToSet ( sourceFiles , f => f . fileName ) ) : Entry [ ] | undefined {
92
+ return flattenEntries ( Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , options , sourceFilesSet ) ) ;
93
93
}
94
94
95
95
function flattenEntries ( referenceSymbols : SymbolAndEntries [ ] ) : Entry [ ] {
@@ -231,10 +231,10 @@ namespace ts.FindAllReferences {
231
231
/* @internal */
232
232
namespace ts . FindAllReferences . Core {
233
233
/** Core find-all-references algorithm. Handles special cases before delegating to `getReferencedSymbolsForSymbol`. */
234
- export function getReferencedSymbolsForNode ( position : number , node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } ) : SymbolAndEntries [ ] | undefined {
234
+ export function getReferencedSymbolsForNode ( position : number , node : Node , program : Program , sourceFiles : ReadonlyArray < SourceFile > , cancellationToken : CancellationToken , options : Options = { } , sourceFilesSet : ReadonlyMap < true > = arrayToSet ( sourceFiles , f => f . fileName ) ) : SymbolAndEntries [ ] | undefined {
235
235
if ( isSourceFile ( node ) ) {
236
236
const reference = GoToDefinition . getReferenceAtPosition ( node , position , program ) ;
237
- return reference && getReferencedSymbolsForModule ( program , program . getTypeChecker ( ) . getMergedSymbol ( reference . file . symbol ) , sourceFiles ) ;
237
+ return reference && getReferencedSymbolsForModule ( program , program . getTypeChecker ( ) . getMergedSymbol ( reference . file . symbol ) , sourceFiles , sourceFilesSet ) ;
238
238
}
239
239
240
240
if ( ! options . implementations ) {
@@ -254,10 +254,10 @@ namespace ts.FindAllReferences.Core {
254
254
}
255
255
256
256
if ( symbol . flags & SymbolFlags . Module && isModuleReferenceLocation ( node ) ) {
257
- return getReferencedSymbolsForModule ( program , symbol , sourceFiles ) ;
257
+ return getReferencedSymbolsForModule ( program , symbol , sourceFiles , sourceFilesSet ) ;
258
258
}
259
259
260
- return getReferencedSymbolsForSymbol ( symbol , node , sourceFiles , checker , cancellationToken , options ) ;
260
+ return getReferencedSymbolsForSymbol ( symbol , node , sourceFiles , sourceFilesSet , checker , cancellationToken , options ) ;
261
261
}
262
262
263
263
function isModuleReferenceLocation ( node : Node ) : boolean {
@@ -277,7 +277,7 @@ namespace ts.FindAllReferences.Core {
277
277
}
278
278
}
279
279
280
- function getReferencedSymbolsForModule ( program : Program , symbol : Symbol , sourceFiles : ReadonlyArray < SourceFile > ) : SymbolAndEntries [ ] {
280
+ function getReferencedSymbolsForModule ( program : Program , symbol : Symbol , sourceFiles : ReadonlyArray < SourceFile > , sourceFilesSet : ReadonlyMap < true > ) : SymbolAndEntries [ ] {
281
281
Debug . assert ( ! ! symbol . valueDeclaration ) ;
282
282
283
283
const references = findModuleReferences ( program , sourceFiles , symbol ) . map < Entry > ( reference => {
@@ -299,7 +299,9 @@ namespace ts.FindAllReferences.Core {
299
299
// Don't include the source file itself. (This may not be ideal behavior, but awkward to include an entire file as a reference.)
300
300
break ;
301
301
case SyntaxKind . ModuleDeclaration :
302
- references . push ( { type : "node" , node : ( decl as ModuleDeclaration ) . name } ) ;
302
+ if ( sourceFilesSet . has ( decl . getSourceFile ( ) . fileName ) ) {
303
+ references . push ( { type : "node" , node : ( decl as ModuleDeclaration ) . name } ) ;
304
+ }
303
305
break ;
304
306
default :
305
307
Debug . fail ( "Expected a module symbol to be declared by a SourceFile or ModuleDeclaration." ) ;
@@ -339,14 +341,14 @@ namespace ts.FindAllReferences.Core {
339
341
}
340
342
341
343
/** Core find-all-references algorithm for a normal symbol. */
342
- function getReferencedSymbolsForSymbol ( symbol : Symbol , node : Node , sourceFiles : ReadonlyArray < SourceFile > , checker : TypeChecker , cancellationToken : CancellationToken , options : Options ) : SymbolAndEntries [ ] {
344
+ function getReferencedSymbolsForSymbol ( symbol : Symbol , node : Node , sourceFiles : ReadonlyArray < SourceFile > , sourceFilesSet : ReadonlyMap < true > , checker : TypeChecker , cancellationToken : CancellationToken , options : Options ) : SymbolAndEntries [ ] {
343
345
symbol = skipPastExportOrImportSpecifierOrUnion ( symbol , node , checker ) || symbol ;
344
346
345
347
// Compute the meaning from the location and the symbol it references
346
348
const searchMeaning = getIntersectingMeaningFromDeclarations ( node , symbol ) ;
347
349
348
350
const result : SymbolAndEntries [ ] = [ ] ;
349
- const state = new State ( sourceFiles , getSpecialSearchKind ( node ) , checker , cancellationToken , searchMeaning , options , result ) ;
351
+ const state = new State ( sourceFiles , sourceFilesSet , getSpecialSearchKind ( node ) , checker , cancellationToken , searchMeaning , options , result ) ;
350
352
351
353
if ( node . kind === SyntaxKind . DefaultKeyword ) {
352
354
addReference ( node , symbol , state ) ;
@@ -469,28 +471,26 @@ namespace ts.FindAllReferences.Core {
469
471
*/
470
472
readonly markSeenReExportRHS = nodeSeenTracker ( ) ;
471
473
472
- private readonly includedSourceFiles : Map < true > ;
473
-
474
474
constructor (
475
475
readonly sourceFiles : ReadonlyArray < SourceFile > ,
476
+ readonly sourceFilesSet : ReadonlyMap < true > ,
476
477
/** True if we're searching for constructor references. */
477
478
readonly specialSearchKind : SpecialSearchKind ,
478
479
readonly checker : TypeChecker ,
479
480
readonly cancellationToken : CancellationToken ,
480
481
readonly searchMeaning : SemanticMeaning ,
481
482
readonly options : Options ,
482
483
private readonly result : Push < SymbolAndEntries > ) {
483
- this . includedSourceFiles = arrayToSet ( sourceFiles , s => s . fileName ) ;
484
484
}
485
485
486
486
includesSourceFile ( sourceFile : SourceFile ) : boolean {
487
- return this . includedSourceFiles . has ( sourceFile . fileName ) ;
487
+ return this . sourceFilesSet . has ( sourceFile . fileName ) ;
488
488
}
489
489
490
490
private importTracker : ImportTracker | undefined ;
491
491
/** Gets every place to look for references of an exported symbols. See `ImportsResult` in `importTracker.ts` for more documentation. */
492
492
getImportSearches ( exportSymbol : Symbol , exportInfo : ExportInfo ) : ImportsResult {
493
- if ( ! this . importTracker ) this . importTracker = createImportTracker ( this . sourceFiles , this . checker , this . cancellationToken ) ;
493
+ if ( ! this . importTracker ) this . importTracker = createImportTracker ( this . sourceFiles , this . sourceFilesSet , this . checker , this . cancellationToken ) ;
494
494
return this . importTracker ( exportSymbol , exportInfo , this . options . isForRename ) ;
495
495
}
496
496
0 commit comments