@@ -98,16 +98,21 @@ namespace ts.codefix {
9898 symbolToken : Node | undefined ,
9999 preferences : UserPreferences ,
100100 ) : { readonly moduleSpecifier : string , readonly codeAction : CodeAction } {
101- const exportInfos = getAllReExportingModules ( exportedSymbol , symbolName , checker , allSourceFiles ) ;
101+ const exportInfos = getAllReExportingModules ( exportedSymbol , moduleSymbol , symbolName , sourceFile , checker , allSourceFiles ) ;
102102 Debug . assert ( exportInfos . some ( info => info . moduleSymbol === moduleSymbol ) ) ;
103103 // We sort the best codefixes first, so taking `first` is best for completions.
104104 const moduleSpecifier = first ( getNewImportInfos ( program , sourceFile , exportInfos , compilerOptions , getCanonicalFileName , host , preferences ) ) . moduleSpecifier ;
105105 const ctx : ImportCodeFixContext = { host, program, checker, compilerOptions, sourceFile, formatContext, symbolName, getCanonicalFileName, symbolToken, preferences } ;
106106 return { moduleSpecifier, codeAction : first ( getCodeActionsForImport ( exportInfos , ctx ) ) } ;
107107 }
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 > {
109109 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+
111116 for ( const exported of checker . getExportsOfModule ( moduleSymbol ) ) {
112117 if ( exported . escapedName === InternalSymbolName . Default || exported . name === symbolName && skipAlias ( exported , checker ) === exportedSymbol ) {
113118 const isDefaultExport = checker . tryGetMemberInModuleExports ( InternalSymbolName . Default , moduleSymbol ) === exported ;
0 commit comments