@@ -34,32 +34,26 @@ export function getImportPathTransformer({ pattern, template }) {
34
34
export const importPathTransformer = ( ) => ( {
35
35
before : [
36
36
transformImportPath ( {
37
- pattern : / ^ ( @ f i r e b a s e .* ) - e x p ( .* ) $ / g ,
37
+ pattern : / ^ ( @ f i r e b a s e .* ) - e x p ( .* ) $ / ,
38
38
template : [ 1 , 2 ]
39
39
} )
40
40
] ,
41
41
after : [ ] ,
42
42
afterDeclarations : [
43
43
transformImportPath ( {
44
- pattern : / ^ ( @ f i r e b a s e .* ) - e x p ( .* ) $ / g ,
44
+ pattern : / ^ ( @ f i r e b a s e .* ) - e x p ( .* ) $ / ,
45
45
template : [ 1 , 2 ]
46
46
} )
47
47
]
48
48
} ) ;
49
49
50
50
function transformImportPath ( { pattern, template } ) {
51
51
return context => file => {
52
- const firstPass = visitNodeAndChildren (
53
- file ,
54
- context ,
55
- { pattern, template } ,
56
- transformDeclareNode
57
- ) ;
58
52
return visitNodeAndChildren (
59
- firstPass ,
53
+ file ,
60
54
context ,
61
55
{ pattern, template } ,
62
- transformImportExportNode
56
+ transformNode
63
57
) ;
64
58
} ;
65
59
}
@@ -105,36 +99,27 @@ function replacePath(pathString, pattern, template) {
105
99
return null ;
106
100
}
107
101
108
- function transformDeclareNode ( node , { pattern, template } ) {
109
- if ( ts . isModuleDeclaration ( node ) && node . name ) {
110
- const importPathWithQuotes = node . name . getText ( ) ;
111
-
112
- const newName = replacePath ( importPathWithQuotes , pattern , template ) ;
113
- if ( newName ) {
114
- const newNode = ts . getMutableClone ( node ) ;
115
- newNode . name = ts . createLiteral ( newName ) ;
116
- return newNode ;
117
- }
118
- return node ;
119
- }
120
-
121
- return node ;
122
- }
123
-
124
- function transformImportExportNode ( node , { pattern, template } ) {
102
+ function transformNode ( node , { pattern, template } ) {
125
103
if (
126
104
( ts . isImportDeclaration ( node ) || ts . isExportDeclaration ( node ) ) &&
127
105
node . moduleSpecifier
128
106
) {
129
107
const importPathWithQuotes = node . moduleSpecifier . getText ( ) ;
130
-
131
108
const newName = replacePath ( importPathWithQuotes , pattern , template ) ;
132
109
133
110
if ( newName ) {
134
111
const newNode = ts . getMutableClone ( node ) ;
135
112
newNode . moduleSpecifier = ts . createLiteral ( newName ) ;
136
113
return newNode ;
137
114
}
115
+ } else if ( ts . isModuleDeclaration ( node ) && node . name ) {
116
+ const importPathWithQuotes = node . name . getText ( ) ;
117
+ const newName = replacePath ( importPathWithQuotes , pattern , template ) ;
118
+ if ( newName ) {
119
+ const newNode = ts . getMutableClone ( node ) ;
120
+ newNode . name = ts . createLiteral ( newName ) ;
121
+ return newNode ;
122
+ }
138
123
}
139
124
140
125
return node ;
0 commit comments