@@ -235,16 +235,16 @@ namespace ts.FindAllReferences {
235
235
markSeenContainingTypeReference ( containingTypeReference : Node ) : boolean ;
236
236
237
237
/**
238
- * It's possible that we will encounter either side of `export { foo as bar } from "x";` more than once.
238
+ * It's possible that we will encounter the right side of `export { foo as bar } from "x";` more than once.
239
239
* For example:
240
- * export { foo as bar } from "a";
241
- * import { foo } from "a";
240
+ * // b.ts
241
+ * export { foo as bar } from "./a";
242
+ * import { bar } from "./b";
242
243
*
243
244
* Normally at `foo as bar` we directly add `foo` and do not locally search for it (since it doesn't declare a local).
244
245
* But another reference to it may appear in the same source file.
245
246
* See `tests/cases/fourslash/transitiveExportImports3.ts`.
246
247
*/
247
- markSeenReExportLHS ( lhs : Identifier ) : boolean ;
248
248
markSeenReExportRHS ( rhs : Identifier ) : boolean ;
249
249
}
250
250
@@ -259,7 +259,7 @@ namespace ts.FindAllReferences {
259
259
return {
260
260
...options ,
261
261
sourceFiles, isForConstructor, checker, cancellationToken, searchMeaning, inheritsFromCache, getImportSearches, createSearch, referenceAdder, addStringOrCommentReference,
262
- markSearchedSymbol, markSeenContainingTypeReference : nodeSeenTracker ( ) , markSeenReExportLHS : nodeSeenTracker ( ) , markSeenReExportRHS : nodeSeenTracker ( ) ,
262
+ markSearchedSymbol, markSeenContainingTypeReference : nodeSeenTracker ( ) , markSeenReExportRHS : nodeSeenTracker ( ) ,
263
263
} ;
264
264
265
265
function getImportSearches ( exportSymbol : Symbol , exportInfo : ExportInfo ) : ImportsResult {
@@ -312,9 +312,7 @@ namespace ts.FindAllReferences {
312
312
if ( singleReferences . length ) {
313
313
const addRef = state . referenceAdder ( exportSymbol , exportLocation ) ;
314
314
for ( const singleRef of singleReferences ) {
315
- if ( state . markSeenReExportLHS ( singleRef ) ) {
316
- addRef ( singleRef ) ;
317
- }
315
+ addRef ( singleRef ) ;
318
316
}
319
317
}
320
318
@@ -645,9 +643,15 @@ namespace ts.FindAllReferences {
645
643
return ;
646
644
}
647
645
648
- if ( isExportSpecifier ( referenceLocation . parent ) ) {
646
+ const { parent } = referenceLocation ;
647
+ if ( isImportSpecifier ( parent ) && parent . propertyName === referenceLocation ) {
648
+ // This is added through `singleReferences` in ImportsResult. If we happen to see it again, don't add it again.
649
+ return ;
650
+ }
651
+
652
+ if ( isExportSpecifier ( parent ) ) {
649
653
Debug . assert ( referenceLocation . kind === SyntaxKind . Identifier ) ;
650
- getReferencesAtExportSpecifier ( referenceLocation as Identifier , referenceSymbol , referenceLocation . parent , search , state ) ;
654
+ getReferencesAtExportSpecifier ( referenceLocation as Identifier , referenceSymbol , parent , search , state ) ;
651
655
return ;
652
656
}
653
657
@@ -669,39 +673,48 @@ namespace ts.FindAllReferences {
669
673
670
674
function getReferencesAtExportSpecifier ( referenceLocation : Identifier , referenceSymbol : Symbol , exportSpecifier : ExportSpecifier , search : Search , state : State ) : void {
671
675
const { parent, propertyName, name } = exportSpecifier ;
672
- searchForExport ( getLocalSymbolForExportSpecifier ( referenceLocation , referenceSymbol , exportSpecifier , state . checker ) ) ;
673
-
674
676
const exportDeclaration = parent . parent ;
675
- if ( search . comingFrom !== ImportExport . Export && exportDeclaration . moduleSpecifier && ! propertyName ) {
676
- searchForImportedSymbol ( state . checker . getExportSpecifierLocalTargetSymbol ( exportSpecifier ) , state ) ;
677
+ const localSymbol = getLocalSymbolForExportSpecifier ( referenceLocation , referenceSymbol , exportSpecifier , state . checker ) ;
678
+ if ( ! search . includes ( localSymbol ) ) {
679
+ return ;
677
680
}
678
681
679
- function searchForExport ( localSymbol : Symbol ) : void {
680
- if ( ! search . includes ( localSymbol ) ) {
681
- return ;
682
+ if ( ! propertyName ) {
683
+ addRef ( )
684
+ }
685
+ else if ( referenceLocation === propertyName ) {
686
+ // For `export { foo as bar } from "baz"`, "`foo`" will be added from the singleReferences for import searches of the original export.
687
+ // For `export { foo as bar };`, where `foo` is a local, so add it now.
688
+ if ( ! exportDeclaration . moduleSpecifier ) {
689
+ addRef ( ) ;
682
690
}
683
691
684
- if ( ! propertyName || ( propertyName === referenceLocation ? state . markSeenReExportLHS : state . markSeenReExportRHS ) ( referenceLocation ) ) {
685
- addReference ( referenceLocation , localSymbol , search . location , state ) ;
692
+ if ( ! state . isForRename && state . markSeenReExportRHS ( name ) ) {
693
+ addReference ( name , referenceSymbol , name , state ) ;
686
694
}
687
-
688
- const renameExportRHS = propertyName === referenceLocation ? name : undefined ;
689
- if ( renameExportRHS ) {
690
- // For `export { foo as bar }`, rename `foo`, but not `bar`.
691
- if ( state . isForRename ) {
692
- return ;
693
- }
694
-
695
- if ( state . markSeenReExportRHS ( renameExportRHS ) ) {
696
- addReference ( renameExportRHS , referenceSymbol , renameExportRHS , state ) ;
697
- }
695
+ }
696
+ else {
697
+ if ( state . markSeenReExportRHS ( referenceLocation ) ) {
698
+ addRef ( ) ;
698
699
}
700
+ }
699
701
702
+ // For `export { foo as bar }`, rename `foo`, but not `bar`.
703
+ if ( ! ( referenceLocation === propertyName && state . isForRename ) ) {
700
704
const exportKind = ( referenceLocation as Identifier ) . originalKeywordKind === ts . SyntaxKind . DefaultKeyword ? ExportKind . Default : ExportKind . Named ;
701
705
const exportInfo = getExportInfo ( referenceSymbol , exportKind , state . checker ) ;
702
706
Debug . assert ( ! ! exportInfo ) ;
703
707
searchForImportsOfExport ( referenceLocation , referenceSymbol , exportInfo , state ) ;
704
708
}
709
+
710
+ // At `export { x } from "foo"`, also search for the imported symbol `"foo".x`.
711
+ if ( search . comingFrom !== ImportExport . Export && exportDeclaration . moduleSpecifier && ! propertyName ) {
712
+ searchForImportedSymbol ( state . checker . getExportSpecifierLocalTargetSymbol ( exportSpecifier ) , state ) ;
713
+ }
714
+
715
+ function addRef ( ) {
716
+ addReference ( referenceLocation , localSymbol , search . location , state ) ;
717
+ }
705
718
}
706
719
707
720
function getLocalSymbolForExportSpecifier ( referenceLocation : Identifier , referenceSymbol : Symbol , exportSpecifier : ExportSpecifier , checker : TypeChecker ) : Symbol {
0 commit comments