[be] More babel plugin Program cleanup
Give a more descriptive name
Lauren Tan committed
Aug 11, 2023 at 16:39 UTC
3ec95c531b458876a75124247bfd322f45376e82
1 file changed
+8
-8
compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+8
-8
@@ -53,7 +53,8 @@ function compileAndInsertNewFunctionDeclaration(
53
fnPath: NodePath<t.FunctionDeclaration>,
54
pass: CompilerPass
55
): boolean {
56
- let compiledFn: t.FunctionDeclaration | null;
56
+ let compiledFn: t.FunctionDeclaration | null = null;
57
+ let hasForgetMutatedOriginalSource = false;
58
try {
59
compiledFn = compileFn(fnPath, pass.opts.environment);
60
} catch (err) {
@@ -75,7 +76,6 @@ function compileAndInsertNewFunctionDeclaration(
76
log(err, pass.filename ?? null);
77
}
78
}
78
- return false;
79
}
80
81
if (pass.opts.noEmit === true) {
@@ -115,10 +115,10 @@ function compileAndInsertNewFunctionDeclaration(
115
addInstrumentForget(gatedFn, originalIdent.name, instrumentFnName);
116
}
117
}
118
- return true;
118
+ hasForgetMutatedOriginalSource = true;
119
}
120
121
- return false;
121
+ return hasForgetMutatedOriginalSource;
122
}
123
124
export function compileProgram(
@@ -128,7 +128,7 @@ export function compileProgram(
128
const options = parsePluginOptions(pass.opts);
129
const violations = [];
130
const fileComments = pass.comments;
131
- let hasForgetCompiledCode: boolean = false;
131
+ let hasForgetMutatedOriginalSource: boolean = false;
132
let fileHasUseForgetDirective = false;
133
134
if (Array.isArray(fileComments)) {
@@ -205,7 +205,7 @@ export function compileProgram(
205
return;
206
}
207
208
- hasForgetCompiledCode = compileAndInsertNewFunctionDeclaration(
208
+ hasForgetMutatedOriginalSource = compileAndInsertNewFunctionDeclaration(
209
fn,
210
pass
211
);
@@ -239,7 +239,7 @@ export function compileProgram(
239
return;
240
}
241
242
- hasForgetCompiledCode = compileAndInsertNewFunctionDeclaration(
242
+ hasForgetMutatedOriginalSource = compileAndInsertNewFunctionDeclaration(
243
loweredFn,
244
pass
245
);
@@ -254,7 +254,7 @@ export function compileProgram(
254
255
// If there isn't already an import of * as React, insert it so useMemoCache doesn't
256
// throw
257
- if (hasForgetCompiledCode) {
257
+ if (hasForgetMutatedOriginalSource) {
258
const { didInsertUseMemoCache, hasExistingReactImport } =
259
findExistingImports(program);
260