@@ -210,7 +210,9 @@ namespace ts.codefix {
210
210
preferences : UserPreferences ,
211
211
) : { readonly moduleSpecifier : string , readonly codeAction : CodeAction } {
212
212
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 ) ;
214
216
const useRequire = shouldUseRequire ( sourceFile , program ) ;
215
217
const preferTypeOnlyImport = compilerOptions . importsNotUsedAsValues === ImportsNotUsedAsValues . Error && ! isSourceFileJS ( sourceFile ) && isValidTypeOnlyAliasUseSite ( getTokenAtPosition ( sourceFile , position ) ) ;
216
218
const moduleSpecifier = first ( getNewImportInfos ( program , sourceFile , position , preferTypeOnlyImport , useRequire , exportInfos , host , preferences ) ) . moduleSpecifier ;
@@ -228,6 +230,27 @@ namespace ts.codefix {
228
230
return { description, changes, commands } ;
229
231
}
230
232
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
+
231
254
function getAllReExportingModules ( importingFile : SourceFile , exportedSymbol : Symbol , exportingModuleSymbol : Symbol , symbolName : string , host : LanguageServiceHost , program : Program , useAutoImportProvider : boolean ) : readonly SymbolExportInfo [ ] {
232
255
const result : SymbolExportInfo [ ] = [ ] ;
233
256
const compilerOptions = program . getCompilerOptions ( ) ;
0 commit comments