@samitouri / QOS-React-1 / commits / cf70ef899e

Validate options before replacing with compiled function

Sathya Gunasekaran committed Nov 7, 2023 at 11:04 UTC cf70ef899e50db5eb463d98ac41e1ed1f08ff031
1 file changed +12 -12
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+12 -12
@@ -332,18 +332,6 @@ export function compileProgram(
332 }
333 }
334
335 - for (const { originalFn: fn, compiledFn } of compiledFns) {
336 - // Only insert Forget-ified functions if we have not encountered a critical
337 - // error elsewhere in the file, regardless of bailout mode.
338 - insertNewFunctionDeclaration(fn, compiledFn, pass);
339 - hasForgetMutatedOriginalSource = true;
340 - }
341 -
342 - // Forget compiled the component, we need to update existing imports of unstable_useMemoCache
343 - if (hasForgetMutatedOriginalSource) {
344 - updateUseMemoCacheImport(program, options);
345 - }
346 -
335 const externalFunctions: ExternalFunction[] = [];
336 try {
337 // TODO: check for duplicate import specifiers
@@ -370,6 +358,18 @@ export function compileProgram(
358 return;
359 }
360
361 + // Only insert Forget-ified functions if we have not encountered a critical
362 + // error elsewhere in the file, regardless of bailout mode.
363 + for (const { originalFn: fn, compiledFn } of compiledFns) {
364 + insertNewFunctionDeclaration(fn, compiledFn, pass);
365 + hasForgetMutatedOriginalSource = true;
366 + }
367 +
368 + // Forget compiled the component, we need to update existing imports of unstable_useMemoCache
369 + if (hasForgetMutatedOriginalSource) {
370 + updateUseMemoCacheImport(program, options);
371 + }
372 +
373 addImportsToProgram(program, externalFunctions);
374 }
375