Skip to content

Commit b6c1d9c

Browse files
committed
improve transform rename function
1 parent 6b0a479 commit b6c1d9c

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

transform-rename-functions.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ const methodsMapping: MethodsMappingItemType[] = [
5555
];
5656

5757
const debug = require("debug")("transform:script-rename");
58+
const debug2 = require("debug")("transform:print:script-rename");
5859

5960
module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
6061
debug(
6162
`**************************************************
6263
*** ${fileInfo.path}
6364
**************************************************`
6465
);
66+
let fileChanged = false;
67+
6568
const rootCollection = j(fileInfo.source);
6669
// debug(rootCollection)
6770

@@ -125,6 +128,7 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
125128
);
126129
debug("+++by this", j(byNode.value).toSource());
127130
j(replaceThisPath).replaceWith(byNode.value);
131+
fileChanged = true;
128132

129133
// increase the counter
130134
replaceCounter += 1;
@@ -134,17 +138,23 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
134138
// find the parent function
135139
const parentFunctionPath = findParentFunction(replaceThisPath);
136140
if (parentFunctionPath) {
137-
setFunctionAsync(parentFunctionPath);
141+
if (setFunctionAsync(parentFunctionPath)) {
142+
fileChanged = true;
143+
}
138144
// then find all functions which use this async function
139145
switch (parentFunctionPath.value.type) {
140146
case "FunctionDeclaration": {
141147
debug("+++the parent", parentFunctionPath.value?.id?.loc?.start);
142148
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+
}
148158
}
149159
break;
150160
}
@@ -232,5 +242,8 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
232242

233243
debug("**************************************************");
234244

235-
return rootCollection.toSource();
245+
if (fileChanged) {
246+
debug2("file changed:", fileInfo.path);
247+
return rootCollection.toSource();
248+
}
236249
};

0 commit comments

Comments
 (0)