Repository: facebook/react
File: compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts (TypeScript)

Code before:
        pass.code,
      );
      pass.opts.logger?.logEvent(pass.filename, {
        kind: 'CompileSuccess',
        fnLoc: fn.node.loc ?? null,
        fnName: compiledFn.id?.name ?? null,
        memoSlots: compiledFn.memoSlotsUsed,
        memoBlocks: compiledFn.memoBlocks,
        memoValues: compiledFn.memoValues,
        prunedMemoBlocks: compiledFn.prunedMemoBlocks,
        prunedMemoValues: compiledFn.prunedMemoValues,
      });
    } catch (err) {
      /**
       * If an opt out directive is present, log only instead of throwing and don't mark as
       * containing a critical error.
       */
      if (fn.node.body.type === 'BlockStatement') {
        const optOutDirectives = findDirectiveDisablingMemoization(
          fn.node.body.directives,
        );
        if (optOutDirectives.length > 0) {
          logError(err, pass, fn.node.loc ?? null);
          return null;
        }
      }
      hasCriticalError ||= isCriticalError(err);
      handleError(err, pass, fn.node.loc ?? null);
      return null;
    }

    if (fn.node.body.type === 'BlockStatement') {
      const optInDirectives = findDirectiveEnablingMemoization(
        fn.node.body.directives,
      );
      const optOutDirectives = findDirectiveDisablingMemoization(
        fn.node.body.directives,
      );

      /**
       * Always compile functions with opt in directives.
       */
      if (optInDirectives.length > 0) {
        return compiledFn;
      } else if (pass.opts.compilationMode === 'annotation') {
        /**
         * No opt-in directive in annotation mode, so don't insert the compiled function.
         */
        return null;
      }


Review comment (suggestion):
i think you need similar logic to this above on https://github.com/facebook/react/pull/30720/files#diff-def62b77d903a117d9a493b69a884f79317eb8c8beac025622265c99f1c7189fR403 (ugh, why doesn't GH let you comment on lines that weren't changed by a PR)

Code after:
        } else {
          handleError(lintError, pass, fn.node.loc ?? null);
        }
      }
    }

    let compiledFn: CodegenFunction;
    try {
      compiledFn = compileFn(
        fn,
        environment,
        fnType,
        useMemoCacheIdentifier.name,
        pass.opts.logger,
        pass.filename,
        pass.code,
      );
      pass.opts.logger?.logEvent(pass.filename, {
        kind: 'CompileSuccess',
        fnLoc: fn.node.loc ?? null,
        fnName: compiledFn.id?.name ?? null,
        memoSlots: compiledFn.memoSlotsUsed,
        memoBlocks: compiledFn.memoBlocks,
        memoValues: compiledFn.memoValues,
        prunedMemoBlocks: compiledFn.prunedMemoBlocks,
        prunedMemoValues: compiledFn.prunedMemoValues,
      });
    } catch (err) {
      /**
       * If an opt out directive is present, log only instead of throwing and don't mark as
       * containing a critical error.
       */
      if (fn.node.body.type === 'BlockStatement') {
        if (optOutDirectives.length > 0) {
          logError(err, pass, fn.node.loc ?? null);
          return null;
        }
      }
      hasCriticalError ||= isCriticalError(err);
      handleError(err, pass, fn.node.loc ?? null);
      return null;
    }

    /**
     * Always compile functions with opt in directives.
     */
    if (optInDirectives.length > 0) {
      return compiledFn;
    } else if (pass.opts.compilationMode === 'annotation') {
      /**
       * No opt-in directive in annotation mode, so don't insert the compiled function.