@@ -4,28 +4,35 @@ import Set from 'es6-set'
4
4
5
5
import resolve from '../core/resolve'
6
6
7
+ function checkImports ( imported , context ) {
8
+ for ( let [ module , nodes ] of imported . entries ( ) ) {
9
+ if ( nodes . size > 1 ) {
10
+ for ( let node of nodes ) {
11
+ context . report ( node , `'${ module } ' imported multiple times.` )
12
+ }
13
+ }
14
+ }
15
+ }
16
+
7
17
module . exports = function ( context ) {
8
18
const imported = new Map ( )
19
+ const typesImported = new Map ( )
9
20
return {
10
21
'ImportDeclaration' : function ( n ) {
11
22
// resolved path will cover aliased duplicates
12
- let resolvedPath = resolve ( n . source . value , context ) || n . source . value
23
+ const resolvedPath = resolve ( n . source . value , context ) || n . source . value
24
+ const importMap = n . importKind === 'type' ? typesImported : imported
13
25
14
- if ( imported . has ( resolvedPath ) ) {
15
- imported . get ( resolvedPath ) . add ( n . source )
26
+ if ( importMap . has ( resolvedPath ) ) {
27
+ importMap . get ( resolvedPath ) . add ( n . source )
16
28
} else {
17
- imported . set ( resolvedPath , new Set ( [ n . source ] ) )
29
+ importMap . set ( resolvedPath , new Set ( [ n . source ] ) )
18
30
}
19
31
} ,
20
32
21
33
'Program:exit' : function ( ) {
22
- for ( let [ module , nodes ] of imported . entries ( ) ) {
23
- if ( nodes . size > 1 ) {
24
- for ( let node of nodes ) {
25
- context . report ( node , `'${ module } ' imported multiple times.` )
26
- }
27
- }
28
- }
34
+ checkImports ( imported , context )
35
+ checkImports ( typesImported , context )
29
36
} ,
30
37
}
31
38
}
0 commit comments