@@ -386,7 +386,7 @@ namespace ts.FindAllReferences.Core {
386386 const searchMeaning = getIntersectingMeaningFromDeclarations ( getMeaningFromLocation ( node ) , symbol . declarations ) ;
387387
388388 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 ) ;
390390 const search = state . createSearch ( node , symbol , /*comingFrom*/ undefined , { allSearchSymbols : populateSearchSymbolSet ( symbol , node , checker , options . implementations ) } ) ;
391391
392392 // Try to get the smallest valid scope that we can limit our search to;
@@ -447,26 +447,17 @@ namespace ts.FindAllReferences.Core {
447447 * Unlike `Search`, there is only one `State`.
448448 */
449449 class State {
450- /** True if we're searching for constructor references. */
451- readonly isForConstructor : boolean ;
452-
453450 /** Cache for `explicitlyinheritsFrom`. */
454451 readonly inheritsFromCache = createMap < boolean > ( ) ;
455452
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-
462453 /**
463454 * Type nodes can contain multiple references to the same type. For example:
464455 * let x: Foo & (Foo & Bar) = ...
465456 * Because we are returning the implementation locations and not the identifier locations,
466457 * duplicate entries would be returned here as each of the type references is part of
467458 * the same implementation. For that reason, check before we add a new entry.
468459 */
469- readonly markSeenContainingTypeReference : ( containingTypeReference : Node ) => boolean ;
460+ readonly markSeenContainingTypeReference = nodeSeenTracker ( ) ;
470461
471462 /**
472463 * 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 {
479470 * But another reference to it may appear in the same source file.
480471 * See `tests/cases/fourslash/transitiveExportImports3.ts`.
481472 */
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 ( ) ;
488474
489475 constructor (
490476 readonly sourceFiles : SourceFile [ ] ,
491- originalLocation : Node ,
477+ /** True if we're searching for constructor references. */
478+ readonly isForConstructor : boolean ,
492479 readonly checker : TypeChecker ,
493480 readonly cancellationToken : CancellationToken ,
494481 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 > ) { }
507484
485+ private importTracker : ImportTracker | undefined ;
508486 /** Gets every place to look for references of an exported symbols. See `ImportsResult` in `importTracker.ts` for more documentation. */
509487 getImportSearches ( exportSymbol : Symbol , exportInfo : ExportInfo ) : ImportsResult {
510488 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 ) ;
512490 }
513491
514492 /** @param allSearchSymbols set of additinal symbols for use by `includes`. */
515493 createSearch ( location : Node , symbol : Symbol , comingFrom : ImportExport | undefined , searchOptions : { text ?: string , allSearchSymbols ?: Symbol [ ] } = { } ) : Search {
516494 // Note: if this is an external module symbol, the name doesn't include quotes.
517495 const { text = stripQuotes ( getDeclaredName ( this . checker , symbol , location ) ) , allSearchSymbols = undefined } = searchOptions ;
518496 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 ) ;
520498 return { location, symbol, comingFrom, text, escapedText, parents, includes } ;
521499
522500 function includes ( referenceSymbol : Symbol ) : boolean {
523501 return allSearchSymbols ? contains ( allSearchSymbols , referenceSymbol ) : referenceSymbol === symbol ;
524502 }
525503 }
526504
505+ private readonly symbolIdToReferences : Entry [ ] [ ] = [ ] ;
527506 /**
528507 * Callback to add references for a particular searched symbol.
529508 * 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 {
546525 } ) ;
547526 }
548527
528+ // Source file ID → symbol ID → Whether the symbol has been searched for in the source file.
529+ private readonly sourceFileToSeenSymbols : Array < Array < true > > = [ ] ;
549530 /** Returns `true` the first time we search for a symbol in a file and `false` afterwards. */
550531 markSearchedSymbol ( sourceFile : SourceFile , symbol : Symbol ) : boolean {
551532 const sourceId = getNodeId ( sourceFile ) ;
@@ -580,7 +561,7 @@ namespace ts.FindAllReferences.Core {
580561 break ;
581562 case ExportKind . Default :
582563 // 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" } ) ;
584565 break ;
585566 case ExportKind . ExportEquals :
586567 break ;
@@ -806,7 +787,7 @@ namespace ts.FindAllReferences.Core {
806787 return ;
807788 }
808789
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 ) ) {
810791 getReferencesAtLocation ( sourceFile , position , search , state ) ;
811792 }
812793 }
@@ -818,7 +799,7 @@ namespace ts.FindAllReferences.Core {
818799 // This wasn't the start of a token. Check to see if it might be a
819800 // match in a comment or string if that's what the caller is asking
820801 // 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 ) ) ) {
822803 // In the case where we're looking inside comments/strings, we don't have
823804 // an actual definition. So just use 'undefined' here. Features like
824805 // 'Rename' won't care (as they ignore the definitions), and features like
@@ -884,7 +865,7 @@ namespace ts.FindAllReferences.Core {
884865 addRef ( ) ;
885866 }
886867
887- if ( ! state . isForRename && state . markSeenReExportRHS ( name ) ) {
868+ if ( ! state . options . isForRename && state . markSeenReExportRHS ( name ) ) {
888869 addReference ( name , referenceSymbol , name , state ) ;
889870 }
890871 }
@@ -895,7 +876,7 @@ namespace ts.FindAllReferences.Core {
895876 }
896877
897878 // For `export { foo as bar }`, rename `foo`, but not `bar`.
898- if ( ! ( referenceLocation === propertyName && state . isForRename ) ) {
879+ if ( ! ( referenceLocation === propertyName && state . options . isForRename ) ) {
899880 const exportKind = ( referenceLocation as Identifier ) . originalKeywordKind === ts . SyntaxKind . DefaultKeyword ? ExportKind . Default : ExportKind . Named ;
900881 const exportInfo = getExportInfo ( referenceSymbol , exportKind , state . checker ) ;
901882 Debug . assert ( ! ! exportInfo ) ;
@@ -937,7 +918,7 @@ namespace ts.FindAllReferences.Core {
937918 const { symbol } = importOrExport ;
938919
939920 if ( importOrExport . kind === ImportExport . Import ) {
940- if ( ! state . isForRename || importOrExport . isNamedImport ) {
921+ if ( ! state . options . isForRename || importOrExport . isNamedImport ) {
941922 searchForImportedSymbol ( symbol , state ) ;
942923 }
943924 }
@@ -963,7 +944,7 @@ namespace ts.FindAllReferences.Core {
963944
964945 function addReference ( referenceLocation : Node , relatedSymbol : Symbol , searchLocation : Node , state : State ) : void {
965946 const addRef = state . referenceAdder ( relatedSymbol , searchLocation ) ;
966- if ( state . implementations ) {
947+ if ( state . options . implementations ) {
967948 addImplementationReferences ( referenceLocation , addRef , state ) ;
968949 }
969950 else {
0 commit comments