@@ -55,13 +55,16 @@ const methodsMapping: MethodsMappingItemType[] = [
55
55
] ;
56
56
57
57
const debug = require ( "debug" ) ( "transform:script-rename" ) ;
58
+ const debug2 = require ( "debug" ) ( "transform:print:script-rename" ) ;
58
59
59
60
module . exports = function ( fileInfo : FileInfo , { j } : API , options : Options ) {
60
61
debug (
61
62
`**************************************************
62
63
*** ${ fileInfo . path }
63
64
**************************************************`
64
65
) ;
66
+ let fileChanged = false ;
67
+
65
68
const rootCollection = j ( fileInfo . source ) ;
66
69
// debug(rootCollection)
67
70
@@ -125,6 +128,7 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
125
128
) ;
126
129
debug ( "+++by this" , j ( byNode . value ) . toSource ( ) ) ;
127
130
j ( replaceThisPath ) . replaceWith ( byNode . value ) ;
131
+ fileChanged = true ;
128
132
129
133
// increase the counter
130
134
replaceCounter += 1 ;
@@ -134,17 +138,23 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
134
138
// find the parent function
135
139
const parentFunctionPath = findParentFunction ( replaceThisPath ) ;
136
140
if ( parentFunctionPath ) {
137
- setFunctionAsync ( parentFunctionPath ) ;
141
+ if ( setFunctionAsync ( parentFunctionPath ) ) {
142
+ fileChanged = true ;
143
+ }
138
144
// then find all functions which use this async function
139
145
switch ( parentFunctionPath . value . type ) {
140
146
case "FunctionDeclaration" : {
141
147
debug ( "+++the parent" , parentFunctionPath . value ?. id ?. loc ?. start ) ;
142
148
if ( parentFunctionPath . value . id ?. type === "Identifier" ) {
143
- convertAllCallExpressionToAsync (
144
- parentFunctionPath . value . id ?. name ,
145
- rootCollection ,
146
- j
147
- ) ;
149
+ if (
150
+ convertAllCallExpressionToAsync (
151
+ parentFunctionPath . value . id ?. name ,
152
+ rootCollection ,
153
+ j
154
+ )
155
+ ) {
156
+ fileChanged = true ;
157
+ }
148
158
}
149
159
break ;
150
160
}
@@ -232,5 +242,8 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
232
242
233
243
debug ( "**************************************************" ) ;
234
244
235
- return rootCollection . toSource ( ) ;
245
+ if ( fileChanged ) {
246
+ debug2 ( "file changed:" , fileInfo . path ) ;
247
+ return rootCollection . toSource ( ) ;
248
+ }
236
249
} ;
0 commit comments