@@ -206,9 +206,10 @@ namespace ts.FindAllReferences {
206
206
207
207
export function findReferencedSymbols ( program : Program , cancellationToken : CancellationToken , sourceFiles : readonly SourceFile [ ] , sourceFile : SourceFile , position : number ) : ReferencedSymbol [ ] | undefined {
208
208
const node = getTouchingPropertyName ( sourceFile , position ) ;
209
- const referencedSymbols = Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , { use : FindReferencesUse . References } ) ;
209
+ const options = { use : FindReferencesUse . References } ;
210
+ const referencedSymbols = Core . getReferencedSymbolsForNode ( position , node , program , sourceFiles , cancellationToken , options ) ;
210
211
const checker = program . getTypeChecker ( ) ;
211
- const symbol = checker . getSymbolAtLocation ( node ) ;
212
+ const symbol = checker . getSymbolAtLocation ( getAdjustedReferenceLocation ( Core . getAdjustedNode ( node , options ) ) ) ;
212
213
return ! referencedSymbols || ! referencedSymbols . length ? undefined : mapDefined < SymbolAndEntries , ReferencedSymbol > ( referencedSymbols , ( { definition, references } ) =>
213
214
// Only include referenced symbols that have a valid definition.
214
215
definition && {
@@ -622,12 +623,7 @@ namespace ts.FindAllReferences {
622
623
export namespace Core {
623
624
/** Core find-all-references algorithm. Handles special cases before delegating to `getReferencedSymbolsForSymbol`. */
624
625
export function getReferencedSymbolsForNode ( position : number , node : Node , program : Program , sourceFiles : readonly SourceFile [ ] , cancellationToken : CancellationToken , options : Options = { } , sourceFilesSet : ReadonlySet < string > = new Set ( sourceFiles . map ( f => f . fileName ) ) ) : readonly SymbolAndEntries [ ] | undefined {
625
- if ( options . use === FindReferencesUse . References ) {
626
- node = getAdjustedReferenceLocation ( node ) ;
627
- }
628
- else if ( options . use === FindReferencesUse . Rename ) {
629
- node = getAdjustedRenameLocation ( node ) ;
630
- }
626
+ node = getAdjustedNode ( node , options ) ;
631
627
if ( isSourceFile ( node ) ) {
632
628
const resolvedRef = GoToDefinition . getReferenceAtPosition ( node , position , program ) ;
633
629
if ( ! resolvedRef ?. file ) {
@@ -695,6 +691,16 @@ namespace ts.FindAllReferences {
695
691
return mergeReferences ( program , moduleReferences , references , moduleReferencesOfExportTarget ) ;
696
692
}
697
693
694
+ export function getAdjustedNode ( node : Node , options : Options ) {
695
+ if ( options . use === FindReferencesUse . References ) {
696
+ node = getAdjustedReferenceLocation ( node ) ;
697
+ }
698
+ else if ( options . use === FindReferencesUse . Rename ) {
699
+ node = getAdjustedRenameLocation ( node ) ;
700
+ }
701
+ return node ;
702
+ }
703
+
698
704
export function getReferencesForFileName ( fileName : string , program : Program , sourceFiles : readonly SourceFile [ ] , sourceFilesSet : ReadonlySet < string > = new Set ( sourceFiles . map ( f => f . fileName ) ) ) : readonly Entry [ ] {
699
705
const moduleSymbol = program . getSourceFile ( fileName ) ?. symbol ;
700
706
if ( moduleSymbol ) {
0 commit comments