@@ -43,8 +43,18 @@ export function tsImportTypes({ dryRun, organiseImports, sourcePatterns, tsConfi
4343 } ;
4444
4545 namedImports . forEach ( function visitNamedImport ( namedImport ) {
46+ const alias = namedImport . getAliasNode ( ) ?. getText ( ) ;
4647 const definitions = namedImport . getNameNode ( ) . getDefinitions ( ) ;
47- definitions . forEach ( collectImports ( moduleSpecifierValue ) ) ;
48+ definitions . forEach ( function collectImports ( definition : DefinitionInfo < ts . DefinitionInfo > ) {
49+ const definitionName = definition . getName ( ) ;
50+ const finalName = alias ? `${ definitionName } as ${ alias } ` : definitionName ;
51+ const definitionKind = definition . getKind ( ) ;
52+ if ( [ 'type' , 'interface' ] . includes ( definitionKind ) ) {
53+ importsByModuleSpecifierValue [ moduleSpecifierValue ] . types . push ( finalName ) ;
54+ } else {
55+ importsByModuleSpecifierValue [ moduleSpecifierValue ] . code . push ( finalName ) ;
56+ }
57+ } ) ;
4858 } ) ;
4959
5060 importDeclaration . remove ( ) ;
@@ -79,17 +89,5 @@ export function tsImportTypes({ dryRun, organiseImports, sourcePatterns, tsConfi
7989 } else {
8090 sourceFile . saveSync ( ) ;
8191 }
82-
83- function collectImports ( moduleSpecifierValue : string ) {
84- return function importCollector ( definition : DefinitionInfo < ts . DefinitionInfo > ) {
85- const definitionName = definition . getName ( ) ;
86- const definitionKind = definition . getKind ( ) ;
87- if ( [ 'type' , 'interface' ] . includes ( definitionKind ) ) {
88- importsByModuleSpecifierValue [ moduleSpecifierValue ] . types . push ( definitionName ) ;
89- } else {
90- importsByModuleSpecifierValue [ moduleSpecifierValue ] . code . push ( definitionName ) ;
91- }
92- } ;
93- }
9492 } ) ;
9593}
0 commit comments