@@ -26,12 +26,14 @@ export interface Specifiers {
26
26
export function Specifiers (
27
27
specifiers : Array < ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier > ,
28
28
) : Specifiers {
29
- let defaultName : Specifiers [ 'default' ] = null ;
30
- let specificNames : Specifiers [ 'specific' ] = [ ] ;
31
- let localNames : Specifiers [ 'local' ] = [ ] ;
29
+ const returnable : Specifiers = {
30
+ default : null ,
31
+ specific : [ ] ,
32
+ local : [ ] ,
33
+ } ;
32
34
33
35
for ( const specifier of specifiers ) {
34
- localNames . push ( specifier . local . name ) ;
36
+ returnable . local . push ( specifier . local . name ) ;
35
37
36
38
switch ( specifier . type ) {
37
39
case IMPORT_SPECIFIER :
@@ -40,34 +42,31 @@ export function Specifiers(
40
42
const { name : imported } = ( specifier as ImportSpecifier ) . imported ;
41
43
42
44
if ( local === imported ) {
43
- specificNames . push ( local ) ;
45
+ returnable . specific . push ( local ) ;
44
46
} else {
45
- specificNames . push ( `${ imported } as ${ local } ` ) ;
47
+ returnable . specific . push ( `${ imported } as ${ local } ` ) ;
46
48
}
47
49
break ;
48
50
case IMPORT_DEFAULT_SPECIFIER :
49
- defaultName = specifier . local . name ;
51
+ returnable . default = specifier . local . name ;
50
52
break ;
51
53
}
52
54
}
53
55
54
- return {
55
- default : defaultName ,
56
- specific : specificNames ,
57
- local : localNames ,
58
- } ;
56
+ return returnable ;
59
57
}
60
58
61
59
export function FormatSpecifiers ( specifiers : Specifiers , name : string ) : string {
62
60
let formatted : string = 'import ' ;
61
+ let values : Array < string > = [ ] ;
63
62
64
63
if ( specifiers . default !== null ) {
65
- formatted += specifiers . default ;
64
+ values . push ( specifiers . default ) ;
66
65
}
67
66
if ( specifiers . specific . length > 0 ) {
68
- formatted += ` ${ specifiers . default !== null ? ',' : '' } { ${ specifiers . specific . join ( ',' ) } }`;
67
+ values . push ( `{ ${ specifiers . specific . join ( ',' ) } }`) ;
69
68
}
70
- formatted += ` from '${ name } ';` ;
69
+ formatted += `${ values . join ( ',' ) } from '${ name } ';` ;
71
70
72
71
return formatted ;
73
72
}
0 commit comments