@@ -210,7 +210,9 @@ namespace ts.codefix {
210210 preferences : UserPreferences ,
211211 ) : { readonly moduleSpecifier : string , readonly codeAction : CodeAction } {
212212 const compilerOptions = program . getCompilerOptions ( ) ;
213- const exportInfos = getAllReExportingModules ( sourceFile , exportedSymbol , moduleSymbol , symbolName , host , program , /*useAutoImportProvider*/ true ) ;
213+ const exportInfos = pathIsBareSpecifier ( stripQuotes ( moduleSymbol . name ) )
214+ ? [ getSymbolExportInfoForSymbol ( exportedSymbol , moduleSymbol , sourceFile , program , host ) ]
215+ : getAllReExportingModules ( sourceFile , exportedSymbol , moduleSymbol , symbolName , host , program , /*useAutoImportProvider*/ true ) ;
214216 const useRequire = shouldUseRequire ( sourceFile , program ) ;
215217 const preferTypeOnlyImport = compilerOptions . importsNotUsedAsValues === ImportsNotUsedAsValues . Error && ! isSourceFileJS ( sourceFile ) && isValidTypeOnlyAliasUseSite ( getTokenAtPosition ( sourceFile , position ) ) ;
216218 const moduleSpecifier = first ( getNewImportInfos ( program , sourceFile , position , preferTypeOnlyImport , useRequire , exportInfos , host , preferences ) ) . moduleSpecifier ;
@@ -228,6 +230,27 @@ namespace ts.codefix {
228230 return { description, changes, commands } ;
229231 }
230232
233+ function getSymbolExportInfoForSymbol ( symbol : Symbol , moduleSymbol : Symbol , importingFile : SourceFile , program : Program , host : LanguageServiceHost ) : SymbolExportInfo {
234+ const compilerOptions = program . getCompilerOptions ( ) ;
235+ const mainProgramInfo = getInfoWithChecker ( program . getTypeChecker ( ) ) ;
236+ if ( mainProgramInfo ) {
237+ return mainProgramInfo ;
238+ }
239+ const autoImportProvider = host . getPackageJsonAutoImportProvider ?.( ) ?. getTypeChecker ( ) ;
240+ return Debug . checkDefined ( autoImportProvider && getInfoWithChecker ( autoImportProvider ) , `Could not find symbol in specified module for code actions` ) ;
241+
242+ function getInfoWithChecker ( checker : TypeChecker ) : SymbolExportInfo | undefined {
243+ const defaultInfo = getDefaultLikeExportInfo ( importingFile , moduleSymbol , checker , compilerOptions ) ;
244+ if ( defaultInfo && skipAlias ( defaultInfo . symbol , checker ) === symbol ) {
245+ return { moduleSymbol, importKind : defaultInfo . kind , exportedSymbolIsTypeOnly : isTypeOnlySymbol ( symbol , checker ) } ;
246+ }
247+ const named = checker . tryGetMemberInModuleExportsAndProperties ( symbol . name , moduleSymbol ) ;
248+ if ( named && skipAlias ( named , checker ) === symbol ) {
249+ return { moduleSymbol, importKind : ImportKind . Named , exportedSymbolIsTypeOnly : isTypeOnlySymbol ( symbol , checker ) } ;
250+ }
251+ }
252+ }
253+
231254 function getAllReExportingModules ( importingFile : SourceFile , exportedSymbol : Symbol , exportingModuleSymbol : Symbol , symbolName : string , host : LanguageServiceHost , program : Program , useAutoImportProvider : boolean ) : readonly SymbolExportInfo [ ] {
232255 const result : SymbolExportInfo [ ] = [ ] ;
233256 const compilerOptions = program . getCompilerOptions ( ) ;
0 commit comments