@@ -26,48 +26,59 @@ module.exports = {
26
26
const sourceFilename = context . getFilename ( ) ;
27
27
28
28
if ( isOldFork ( sourceFilename ) ) {
29
+ const visitor = node => {
30
+ const sourceNode = node . source ;
31
+ if ( sourceNode === null ) {
32
+ return ;
33
+ }
34
+ const filename = sourceNode . value ;
35
+ if ( isNewFork ( filename ) ) {
36
+ context . report ( {
37
+ node : sourceNode ,
38
+ message :
39
+ 'A module that belongs to the old fork cannot import a module ' +
40
+ 'from the new fork.' ,
41
+ fix ( fixer ) {
42
+ return fixer . replaceText (
43
+ sourceNode ,
44
+ `'${ filename . replace ( / \. n e w ( \. j s ) ? $ / , '.old' ) } '`
45
+ ) ;
46
+ } ,
47
+ } ) ;
48
+ }
49
+ } ;
29
50
return {
30
- ImportDeclaration ( node ) {
31
- const importSourceNode = node . source ;
32
- const filename = importSourceNode . value ;
33
- if ( isNewFork ( filename ) ) {
34
- context . report ( {
35
- node : importSourceNode ,
36
- message :
37
- 'A module that belongs to the old fork cannot import a module ' +
38
- 'from the new fork.' ,
39
- fix ( fixer ) {
40
- return fixer . replaceText (
41
- importSourceNode ,
42
- `'${ filename . replace ( / \. n e w ( \. j s ) ? $ / , '.old' ) } '`
43
- ) ;
44
- } ,
45
- } ) ;
46
- }
47
- } ,
51
+ ImportDeclaration : visitor ,
52
+ ExportNamedDeclaration : visitor ,
48
53
} ;
49
54
}
50
55
51
56
if ( isNewFork ( sourceFilename ) ) {
57
+ const visitor = node => {
58
+ const sourceNode = node . source ;
59
+ if ( sourceNode === null ) {
60
+ return ;
61
+ }
62
+ const filename = sourceNode . value ;
63
+ if ( isOldFork ( filename ) ) {
64
+ context . report ( {
65
+ node : sourceNode ,
66
+ message :
67
+ 'A module that belongs to the new fork cannot import a module ' +
68
+ 'from the old fork.' ,
69
+ fix ( fixer ) {
70
+ return fixer . replaceText (
71
+ sourceNode ,
72
+ `'${ filename . replace ( / \. o l d ( \. j s ) ? $ / , '.new' ) } '`
73
+ ) ;
74
+ } ,
75
+ } ) ;
76
+ }
77
+ } ;
78
+
52
79
return {
53
- ImportDeclaration ( node ) {
54
- const importSourceNode = node . source ;
55
- const filename = importSourceNode . value ;
56
- if ( isOldFork ( filename ) ) {
57
- context . report ( {
58
- node : importSourceNode ,
59
- message :
60
- 'A module that belongs to the new fork cannot import a module ' +
61
- 'from the old fork.' ,
62
- fix ( fixer ) {
63
- return fixer . replaceText (
64
- importSourceNode ,
65
- `'${ filename . replace ( / \. o l d ( \. j s ) ? $ / , '.new' ) } '`
66
- ) ;
67
- } ,
68
- } ) ;
69
- }
70
- } ,
80
+ ImportDeclaration : visitor ,
81
+ ExportNamedDeclaration : visitor ,
71
82
} ;
72
83
}
73
84
0 commit comments