@@ -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
@@ -648,9 +646,15 @@ namespace ts.FindAllReferences {
648
646
return ;
649
647
}
650
648
651
- if ( isExportSpecifier ( referenceLocation . parent ) ) {
649
+ const { parent } = referenceLocation ;
650
+ if ( isImportSpecifier ( parent ) && parent . propertyName === referenceLocation ) {
651
+ // This is added through `singleReferences` in ImportsResult. If we happen to see it again, don't add it again.
652
+ return ;
653
+ }
654
+
655
+ if ( isExportSpecifier ( parent ) ) {
652
656
Debug . assert ( referenceLocation . kind === SyntaxKind . Identifier ) ;
653
- getReferencesAtExportSpecifier ( referenceLocation as Identifier , referenceSymbol , referenceLocation . parent , search , state ) ;
657
+ getReferencesAtExportSpecifier ( referenceLocation as Identifier , referenceSymbol , parent , search , state ) ;
654
658
return ;
655
659
}
656
660
@@ -672,39 +676,48 @@ namespace ts.FindAllReferences {
672
676
673
677
function getReferencesAtExportSpecifier ( referenceLocation : Identifier , referenceSymbol : Symbol , exportSpecifier : ExportSpecifier , search : Search , state : State ) : void {
674
678
const { parent, propertyName, name } = exportSpecifier ;
675
- searchForExport ( getLocalSymbolForExportSpecifier ( referenceLocation , referenceSymbol , exportSpecifier , state . checker ) ) ;
676
-
677
679
const exportDeclaration = parent . parent ;
678
- if ( search . comingFrom !== ImportExport . Export && exportDeclaration . moduleSpecifier && ! propertyName ) {
679
- searchForImportedSymbol ( state . checker . getExportSpecifierLocalTargetSymbol ( exportSpecifier ) , state ) ;
680
+ const localSymbol = getLocalSymbolForExportSpecifier ( referenceLocation , referenceSymbol , exportSpecifier , state . checker ) ;
681
+ if ( ! search . includes ( localSymbol ) ) {
682
+ return ;
680
683
}
681
684
682
- function searchForExport ( localSymbol : Symbol ) : void {
683
- if ( ! search . includes ( localSymbol ) ) {
684
- return ;
685
+ if ( ! propertyName ) {
686
+ addRef ( )
687
+ }
688
+ else if ( referenceLocation === propertyName ) {
689
+ // For `export { foo as bar } from "baz"`, "`foo`" will be added from the singleReferences for import searches of the original export.
690
+ // For `export { foo as bar };`, where `foo` is a local, so add it now.
691
+ if ( ! exportDeclaration . moduleSpecifier ) {
692
+ addRef ( ) ;
685
693
}
686
694
687
- if ( ! propertyName || ( propertyName === referenceLocation ? state . markSeenReExportLHS : state . markSeenReExportRHS ) ( referenceLocation ) ) {
688
- addReference ( referenceLocation , localSymbol , search . location , state ) ;
695
+ if ( ! state . isForRename && state . markSeenReExportRHS ( name ) ) {
696
+ addReference ( name , referenceSymbol , name , state ) ;
689
697
}
690
-
691
- const renameExportRHS = propertyName === referenceLocation ? name : undefined ;
692
- if ( renameExportRHS ) {
693
- // For `export { foo as bar }`, rename `foo`, but not `bar`.
694
- if ( state . isForRename ) {
695
- return ;
696
- }
697
-
698
- if ( state . markSeenReExportRHS ( renameExportRHS ) ) {
699
- addReference ( renameExportRHS , referenceSymbol , renameExportRHS , state ) ;
700
- }
698
+ }
699
+ else {
700
+ if ( state . markSeenReExportRHS ( referenceLocation ) ) {
701
+ addRef ( ) ;
701
702
}
703
+ }
702
704
705
+ // For `export { foo as bar }`, rename `foo`, but not `bar`.
706
+ if ( ! ( referenceLocation === propertyName && state . isForRename ) ) {
703
707
const exportKind = ( referenceLocation as Identifier ) . originalKeywordKind === ts . SyntaxKind . DefaultKeyword ? ExportKind . Default : ExportKind . Named ;
704
708
const exportInfo = getExportInfo ( referenceSymbol , exportKind , state . checker ) ;
705
709
Debug . assert ( ! ! exportInfo ) ;
706
710
searchForImportsOfExport ( referenceLocation , referenceSymbol , exportInfo , state ) ;
707
711
}
712
+
713
+ // At `export { x } from "foo"`, also search for the imported symbol `"foo".x`.
714
+ if ( search . comingFrom !== ImportExport . Export && exportDeclaration . moduleSpecifier && ! propertyName ) {
715
+ searchForImportedSymbol ( state . checker . getExportSpecifierLocalTargetSymbol ( exportSpecifier ) , state ) ;
716
+ }
717
+
718
+ function addRef ( ) {
719
+ addReference ( referenceLocation , localSymbol , search . location , state ) ;
720
+ }
708
721
}
709
722
710
723
function getLocalSymbolForExportSpecifier ( referenceLocation : Identifier , referenceSymbol : Symbol , exportSpecifier : ExportSpecifier , checker : TypeChecker ) : Symbol {
0 commit comments