@@ -21,44 +21,51 @@ export = createRule<[], MessageId>({
21
21
} ,
22
22
defaultOptions : [ ] ,
23
23
create ( context ) {
24
- function checkDefault (
25
- nameKey : 'local' | 'exported' ,
26
- defaultSpecifier : TSESTree . ImportDefaultSpecifier ,
27
- // | TSESTree.ExportDefaultSpecifier,
28
- ) {
29
- // #566: default is a valid specifier
30
- // @ts -expect-error - ExportDefaultSpecifier is unavailable yet
31
- const nameValue = defaultSpecifier [ nameKey ] . name as string
24
+ function createCheckDefault ( nameKey : 'local' | 'exported' ) {
25
+ return function checkDefault (
26
+ defaultSpecifier : TSESTree . ImportDefaultSpecifier ,
27
+ // | TSESTree.ExportDefaultSpecifier,
28
+ ) {
29
+ // #566: default is a valid specifier
30
+ // @ts -expect-error - ExportDefaultSpecifier is unavailable yet
31
+ const nameValue = defaultSpecifier [ nameKey ] . name as string
32
32
33
- if ( nameValue === 'default' ) {
34
- return
35
- }
33
+ if ( nameValue === 'default' ) {
34
+ return
35
+ }
36
36
37
- const declaration = importDeclaration ( context , defaultSpecifier )
37
+ const declaration = importDeclaration ( context , defaultSpecifier )
38
38
39
- const imports = ExportMap . get ( declaration . source . value , context )
40
- if ( imports == null ) {
41
- return
42
- }
39
+ const exportMapOfImported = ExportMap . get (
40
+ declaration . source . value ,
41
+ context ,
42
+ )
43
+ if ( exportMapOfImported == null ) {
44
+ return
45
+ }
43
46
44
- if ( imports . errors . length > 0 ) {
45
- imports . reportErrors ( context , declaration )
46
- return
47
- }
47
+ if ( exportMapOfImported . errors . length > 0 ) {
48
+ exportMapOfImported . reportErrors ( context , declaration )
49
+ return
50
+ }
48
51
49
- if ( imports . has ( 'default' ) && imports . has ( nameValue ) ) {
50
- context . report ( {
51
- node : defaultSpecifier ,
52
- messageId : 'default' ,
53
- data : {
54
- name : nameValue ,
55
- } ,
56
- } )
52
+ if (
53
+ exportMapOfImported . exports . has ( 'default' ) &&
54
+ exportMapOfImported . exports . has ( nameValue )
55
+ ) {
56
+ context . report ( {
57
+ node : defaultSpecifier ,
58
+ messageId : 'default' ,
59
+ data : {
60
+ name : nameValue ,
61
+ } ,
62
+ } )
63
+ }
57
64
}
58
65
}
59
66
return {
60
- ImportDefaultSpecifier : checkDefault . bind ( null , 'local' ) ,
61
- ExportDefaultSpecifier : checkDefault . bind ( null , 'exported' ) ,
67
+ ImportDefaultSpecifier : createCheckDefault ( 'local' ) ,
68
+ ExportDefaultSpecifier : createCheckDefault ( 'exported' ) ,
62
69
}
63
70
} ,
64
71
} )
0 commit comments