@@ -386,7 +386,7 @@ namespace ts.FindAllReferences.Core {
386
386
const searchMeaning = getIntersectingMeaningFromDeclarations ( getMeaningFromLocation ( node ) , symbol . declarations ) ;
387
387
388
388
const result : SymbolAndEntries [ ] = [ ] ;
389
- const state = new State ( sourceFiles , node , checker , cancellationToken , searchMeaning , options , result ) ;
389
+ const state = new State ( sourceFiles , /*isForConstructor*/ node . kind === SyntaxKind . ConstructorKeyword , checker , cancellationToken , searchMeaning , options , result ) ;
390
390
const search = state . createSearch ( node , symbol , /*comingFrom*/ undefined , { allSearchSymbols : populateSearchSymbolSet ( symbol , node , checker , options . implementations ) } ) ;
391
391
392
392
// Try to get the smallest valid scope that we can limit our search to;
@@ -447,26 +447,17 @@ namespace ts.FindAllReferences.Core {
447
447
* Unlike `Search`, there is only one `State`.
448
448
*/
449
449
class State {
450
- /** True if we're searching for constructor references. */
451
- readonly isForConstructor : boolean ;
452
-
453
450
/** Cache for `explicitlyinheritsFrom`. */
454
451
readonly inheritsFromCache = createMap < boolean > ( ) ;
455
452
456
- private readonly symbolIdToReferences : Entry [ ] [ ] = [ ] ;
457
- // Source file ID → symbol ID → Whether the symbol has been searched for in the source file.
458
- private readonly sourceFileToSeenSymbols : Array < Array < true > > = [ ] ;
459
-
460
- private importTracker : ImportTracker | undefined ;
461
-
462
453
/**
463
454
* Type nodes can contain multiple references to the same type. For example:
464
455
* let x: Foo & (Foo & Bar) = ...
465
456
* Because we are returning the implementation locations and not the identifier locations,
466
457
* duplicate entries would be returned here as each of the type references is part of
467
458
* the same implementation. For that reason, check before we add a new entry.
468
459
*/
469
- readonly markSeenContainingTypeReference : ( containingTypeReference : Node ) => boolean ;
460
+ readonly markSeenContainingTypeReference = nodeSeenTracker ( ) ;
470
461
471
462
/**
472
463
* It's possible that we will encounter the right side of `export { foo as bar } from "x";` more than once.
@@ -479,51 +470,39 @@ namespace ts.FindAllReferences.Core {
479
470
* But another reference to it may appear in the same source file.
480
471
* See `tests/cases/fourslash/transitiveExportImports3.ts`.
481
472
*/
482
- readonly markSeenReExportRHS : ( rhs : Identifier ) => boolean ;
483
-
484
- readonly findInStrings ?: boolean ;
485
- readonly findInComments ?: boolean ;
486
- readonly isForRename ?: boolean ;
487
- readonly implementations ?: boolean ;
473
+ readonly markSeenReExportRHS = nodeSeenTracker ( ) ;
488
474
489
475
constructor (
490
476
readonly sourceFiles : SourceFile [ ] ,
491
- originalLocation : Node ,
477
+ /** True if we're searching for constructor references. */
478
+ readonly isForConstructor : boolean ,
492
479
readonly checker : TypeChecker ,
493
480
readonly cancellationToken : CancellationToken ,
494
481
readonly searchMeaning : SemanticMeaning ,
495
- options : Options ,
496
- private readonly result : Push < SymbolAndEntries > ) {
497
-
498
- this . findInStrings = options . findInStrings ;
499
- this . findInComments = options . findInComments ;
500
- this . isForRename = options . isForRename ;
501
- this . implementations = options . implementations ;
502
-
503
- this . isForConstructor = originalLocation . kind === SyntaxKind . ConstructorKeyword ;
504
- this . markSeenContainingTypeReference = nodeSeenTracker ( ) ;
505
- this . markSeenReExportRHS = nodeSeenTracker ( ) ;
506
- }
482
+ readonly options : Options ,
483
+ private readonly result : Push < SymbolAndEntries > ) { }
507
484
485
+ private importTracker : ImportTracker | undefined ;
508
486
/** Gets every place to look for references of an exported symbols. See `ImportsResult` in `importTracker.ts` for more documentation. */
509
487
getImportSearches ( exportSymbol : Symbol , exportInfo : ExportInfo ) : ImportsResult {
510
488
if ( ! this . importTracker ) this . importTracker = createImportTracker ( this . sourceFiles , this . checker , this . cancellationToken ) ;
511
- return this . importTracker ( exportSymbol , exportInfo , this . isForRename ) ;
489
+ return this . importTracker ( exportSymbol , exportInfo , this . options . isForRename ) ;
512
490
}
513
491
514
492
/** @param allSearchSymbols set of additinal symbols for use by `includes`. */
515
493
createSearch ( location : Node , symbol : Symbol , comingFrom : ImportExport | undefined , searchOptions : { text ?: string , allSearchSymbols ?: Symbol [ ] } = { } ) : Search {
516
494
// Note: if this is an external module symbol, the name doesn't include quotes.
517
495
const { text = stripQuotes ( getDeclaredName ( this . checker , symbol , location ) ) , allSearchSymbols = undefined } = searchOptions ;
518
496
const escapedText = escapeIdentifier ( text ) ;
519
- const parents = this . implementations && getParentSymbolsOfPropertyAccess ( location , symbol , this . checker ) ;
497
+ const parents = this . options . implementations && getParentSymbolsOfPropertyAccess ( location , symbol , this . checker ) ;
520
498
return { location, symbol, comingFrom, text, escapedText, parents, includes } ;
521
499
522
500
function includes ( referenceSymbol : Symbol ) : boolean {
523
501
return allSearchSymbols ? contains ( allSearchSymbols , referenceSymbol ) : referenceSymbol === symbol ;
524
502
}
525
503
}
526
504
505
+ private readonly symbolIdToReferences : Entry [ ] [ ] = [ ] ;
527
506
/**
528
507
* Callback to add references for a particular searched symbol.
529
508
* This initializes a reference group, so only call this if you will add at least one reference.
@@ -546,6 +525,8 @@ namespace ts.FindAllReferences.Core {
546
525
} ) ;
547
526
}
548
527
528
+ // Source file ID → symbol ID → Whether the symbol has been searched for in the source file.
529
+ private readonly sourceFileToSeenSymbols : Array < Array < true > > = [ ] ;
549
530
/** Returns `true` the first time we search for a symbol in a file and `false` afterwards. */
550
531
markSearchedSymbol ( sourceFile : SourceFile , symbol : Symbol ) : boolean {
551
532
const sourceId = getNodeId ( sourceFile ) ;
@@ -580,7 +561,7 @@ namespace ts.FindAllReferences.Core {
580
561
break ;
581
562
case ExportKind . Default :
582
563
// Search for a property access to '.default'. This can't be renamed.
583
- indirectSearch = state . isForRename ? undefined : state . createSearch ( exportLocation , exportSymbol , ImportExport . Export , { text : "default" } ) ;
564
+ indirectSearch = state . options . isForRename ? undefined : state . createSearch ( exportLocation , exportSymbol , ImportExport . Export , { text : "default" } ) ;
584
565
break ;
585
566
case ExportKind . ExportEquals :
586
567
break ;
@@ -806,7 +787,7 @@ namespace ts.FindAllReferences.Core {
806
787
return ;
807
788
}
808
789
809
- for ( const position of getPossibleSymbolReferencePositions ( sourceFile , search . text , container , /*fullStart*/ state . findInComments || container . jsDoc !== undefined ) ) {
790
+ for ( const position of getPossibleSymbolReferencePositions ( sourceFile , search . text , container , /*fullStart*/ state . options . findInComments || container . jsDoc !== undefined ) ) {
810
791
getReferencesAtLocation ( sourceFile , position , search , state ) ;
811
792
}
812
793
}
@@ -818,7 +799,7 @@ namespace ts.FindAllReferences.Core {
818
799
// This wasn't the start of a token. Check to see if it might be a
819
800
// match in a comment or string if that's what the caller is asking
820
801
// for.
821
- if ( ! state . implementations && ( state . findInStrings && isInString ( sourceFile , position ) || state . findInComments && isInNonReferenceComment ( sourceFile , position ) ) ) {
802
+ if ( ! state . options . implementations && ( state . options . findInStrings && isInString ( sourceFile , position ) || state . options . findInComments && isInNonReferenceComment ( sourceFile , position ) ) ) {
822
803
// In the case where we're looking inside comments/strings, we don't have
823
804
// an actual definition. So just use 'undefined' here. Features like
824
805
// 'Rename' won't care (as they ignore the definitions), and features like
@@ -884,7 +865,7 @@ namespace ts.FindAllReferences.Core {
884
865
addRef ( ) ;
885
866
}
886
867
887
- if ( ! state . isForRename && state . markSeenReExportRHS ( name ) ) {
868
+ if ( ! state . options . isForRename && state . markSeenReExportRHS ( name ) ) {
888
869
addReference ( name , referenceSymbol , name , state ) ;
889
870
}
890
871
}
@@ -895,7 +876,7 @@ namespace ts.FindAllReferences.Core {
895
876
}
896
877
897
878
// For `export { foo as bar }`, rename `foo`, but not `bar`.
898
- if ( ! ( referenceLocation === propertyName && state . isForRename ) ) {
879
+ if ( ! ( referenceLocation === propertyName && state . options . isForRename ) ) {
899
880
const exportKind = ( referenceLocation as Identifier ) . originalKeywordKind === ts . SyntaxKind . DefaultKeyword ? ExportKind . Default : ExportKind . Named ;
900
881
const exportInfo = getExportInfo ( referenceSymbol , exportKind , state . checker ) ;
901
882
Debug . assert ( ! ! exportInfo ) ;
@@ -937,7 +918,7 @@ namespace ts.FindAllReferences.Core {
937
918
const { symbol } = importOrExport ;
938
919
939
920
if ( importOrExport . kind === ImportExport . Import ) {
940
- if ( ! state . isForRename || importOrExport . isNamedImport ) {
921
+ if ( ! state . options . isForRename || importOrExport . isNamedImport ) {
941
922
searchForImportedSymbol ( symbol , state ) ;
942
923
}
943
924
}
@@ -963,7 +944,7 @@ namespace ts.FindAllReferences.Core {
963
944
964
945
function addReference ( referenceLocation : Node , relatedSymbol : Symbol , searchLocation : Node , state : State ) : void {
965
946
const addRef = state . referenceAdder ( relatedSymbol , searchLocation ) ;
966
- if ( state . implementations ) {
947
+ if ( state . options . implementations ) {
967
948
addImplementationReferences ( referenceLocation , addRef , state ) ;
968
949
}
969
950
else {
0 commit comments