@@ -10,11 +10,11 @@ function mergeNamedBinding(base: ts.NamedImportBindings | undefined, head: ts.Na
10
10
return astf . updateNamedImports ( base , [ ...base . elements , ...head . elements ] ) ;
11
11
}
12
12
13
- function removeFromNamedBinding ( base : ts . NamedImportBindings | undefined , name : string ) {
13
+ function removeFromNamedBinding ( base : ts . NamedImportBindings | undefined , names : string [ ] ) {
14
14
if ( ! base ) return undefined ;
15
15
// treat namedImports only
16
16
if ( ts . isNamespaceImport ( base ) ) return base ;
17
- const elements = base . elements . filter ( elm => elm . name . text !== name ) ;
17
+ const elements = base . elements . filter ( elm => ! names . includes ( elm . name . text ) ) ;
18
18
if ( elements . length === 0 ) return undefined ;
19
19
return astf . updateNamedImports ( base , elements ) ;
20
20
}
@@ -29,12 +29,12 @@ function mergeImportClause(base: ts.ImportClause | undefined, head: ts.ImportCla
29
29
return astf . updateImportClause ( base , isTypeOnly , name , namedBindings ) ;
30
30
}
31
31
32
- function removeFromImportClause ( base : ts . ImportClause | undefined , name : string ) {
32
+ function removeFromImportClause ( base : ts . ImportClause | undefined , names : string [ ] ) {
33
33
if ( ! base ) return undefined ;
34
- const namedBindings = removeFromNamedBinding ( base . namedBindings , name ) ;
35
- const nameId = base . name ?. text !== name ? base . name : undefined ;
36
- if ( ! nameId && ! namedBindings ) return undefined ;
37
- return astf . updateImportClause ( base , base . isTypeOnly , nameId , namedBindings ) ;
34
+ const namedBindings = removeFromNamedBinding ( base . namedBindings , names ) ;
35
+ const nameIdentifier = base . name && names . includes ( base . name . text ) ? undefined : base . name ;
36
+ if ( ! nameIdentifier && ! namedBindings ) return undefined ;
37
+ return astf . updateImportClause ( base , base . isTypeOnly , nameIdentifier , namedBindings ) ;
38
38
}
39
39
40
40
export function findNode ( sourceFile : ts . SourceFile , position : number ) : ts . Node | undefined {
@@ -121,9 +121,9 @@ export function mergeImportDeclarationsWithSameModules(base: ts.ImportDeclaratio
121
121
return astf . updateImportDeclaration ( base , modifiers , importClause , base . moduleSpecifier , undefined ) ;
122
122
}
123
123
124
- export function removeAliasFromImportDeclaration ( base : ts . ImportDeclaration , name : string ) {
124
+ export function removeAliasFromImportDeclaration ( base : ts . ImportDeclaration , names : string [ ] ) {
125
125
const modifiers = base . modifiers ;
126
- const importClause = removeFromImportClause ( base . importClause , name ) ;
126
+ const importClause = removeFromImportClause ( base . importClause , names ) ;
127
127
if ( ! importClause ) return undefined ;
128
128
return astf . updateImportDeclaration ( base , modifiers , importClause , base . moduleSpecifier , undefined ) ;
129
129
}
0 commit comments