From cf70ef899e50db5eb463d98ac41e1ed1f08ff031 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Tue, 7 Nov 2023 11:04:34 +0000 Subject: [PATCH] Validate options before replacing with compiled function --- .../src/Entrypoint/Program.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts index 8e95f0a093..7403be7c64 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -332,18 +332,6 @@ export function compileProgram( } } - for (const { originalFn: fn, compiledFn } of compiledFns) { - // Only insert Forget-ified functions if we have not encountered a critical - // error elsewhere in the file, regardless of bailout mode. - insertNewFunctionDeclaration(fn, compiledFn, pass); - hasForgetMutatedOriginalSource = true; - } - - // Forget compiled the component, we need to update existing imports of unstable_useMemoCache - if (hasForgetMutatedOriginalSource) { - updateUseMemoCacheImport(program, options); - } - const externalFunctions: ExternalFunction[] = []; try { // TODO: check for duplicate import specifiers @@ -370,6 +358,18 @@ export function compileProgram( return; } + // Only insert Forget-ified functions if we have not encountered a critical + // error elsewhere in the file, regardless of bailout mode. + for (const { originalFn: fn, compiledFn } of compiledFns) { + insertNewFunctionDeclaration(fn, compiledFn, pass); + hasForgetMutatedOriginalSource = true; + } + + // Forget compiled the component, we need to update existing imports of unstable_useMemoCache + if (hasForgetMutatedOriginalSource) { + updateUseMemoCacheImport(program, options); + } + addImportsToProgram(program, externalFunctions); }