@@ -98,16 +98,21 @@ namespace ts.codefix {
98
98
symbolToken : Node | undefined ,
99
99
preferences : UserPreferences ,
100
100
) : { readonly moduleSpecifier : string , readonly codeAction : CodeAction } {
101
- const exportInfos = getAllReExportingModules ( exportedSymbol , symbolName , checker , allSourceFiles ) ;
101
+ const exportInfos = getAllReExportingModules ( exportedSymbol , moduleSymbol , symbolName , sourceFile , checker , allSourceFiles ) ;
102
102
Debug . assert ( exportInfos . some ( info => info . moduleSymbol === moduleSymbol ) ) ;
103
103
// We sort the best codefixes first, so taking `first` is best for completions.
104
104
const moduleSpecifier = first ( getNewImportInfos ( program , sourceFile , exportInfos , compilerOptions , getCanonicalFileName , host , preferences ) ) . moduleSpecifier ;
105
105
const ctx : ImportCodeFixContext = { host, program, checker, compilerOptions, sourceFile, formatContext, symbolName, getCanonicalFileName, symbolToken, preferences } ;
106
106
return { moduleSpecifier, codeAction : first ( getCodeActionsForImport ( exportInfos , ctx ) ) } ;
107
107
}
108
- function getAllReExportingModules ( exportedSymbol : Symbol , symbolName : string , checker : TypeChecker , allSourceFiles : ReadonlyArray < SourceFile > ) : ReadonlyArray < SymbolExportInfo > {
108
+ function getAllReExportingModules ( exportedSymbol : Symbol , exportingModuleSymbol : Symbol , symbolName : string , sourceFile : SourceFile , checker : TypeChecker , allSourceFiles : ReadonlyArray < SourceFile > ) : ReadonlyArray < SymbolExportInfo > {
109
109
const result : SymbolExportInfo [ ] = [ ] ;
110
- forEachExternalModule ( checker , allSourceFiles , moduleSymbol => {
110
+ forEachExternalModule ( checker , allSourceFiles , ( moduleSymbol , moduleFile ) => {
111
+ // Don't import from a re-export when looking "up" like to `./index` or `../index`.
112
+ if ( moduleFile && moduleSymbol !== exportingModuleSymbol && startsWith ( sourceFile . fileName , getDirectoryPath ( moduleFile . fileName ) ) ) {
113
+ return ;
114
+ }
115
+
111
116
for ( const exported of checker . getExportsOfModule ( moduleSymbol ) ) {
112
117
if ( exported . escapedName === InternalSymbolName . Default || exported . name === symbolName && skipAlias ( exported , checker ) === exportedSymbol ) {
113
118
const isDefaultExport = checker . tryGetMemberInModuleExports ( InternalSymbolName . Default , moduleSymbol ) === exported ;
0 commit comments