Home / Function/ findFunctionsToCompile() — react Function Reference

findFunctionsToCompile() — react Function Reference

Architecture documentation for the findFunctionsToCompile() function in Program.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  7fe1be87_de24_09ca_229a_0644af0874a5["findFunctionsToCompile()"]
  9aa4477d_960b_1ea1_b6d9_36076aaa70bd["Program.ts"]
  7fe1be87_de24_09ca_229a_0644af0874a5 -->|defined in| 9aa4477d_960b_1ea1_b6d9_36076aaa70bd
  1c9af54b_10e9_8985_e772_1f517e46c560["compileProgram()"]
  1c9af54b_10e9_8985_e772_1f517e46c560 -->|calls| 7fe1be87_de24_09ca_229a_0644af0874a5
  37c561cb_7b67_6332_ee68_b69aaf917134["getReactFunctionType()"]
  7fe1be87_de24_09ca_229a_0644af0874a5 -->|calls| 37c561cb_7b67_6332_ee68_b69aaf917134
  6f61e521_79f8_315c_2443_8700d7e01eaa["validateNoDynamicallyCreatedComponentsOrHooks()"]
  7fe1be87_de24_09ca_229a_0644af0874a5 -->|calls| 6f61e521_79f8_315c_2443_8700d7e01eaa
  073c81a5_c389_d108_5b8f_4d6dc6eece83["push()"]
  7fe1be87_de24_09ca_229a_0644af0874a5 -->|calls| 073c81a5_c389_d108_5b8f_4d6dc6eece83
  style 7fe1be87_de24_09ca_229a_0644af0874a5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts lines 504–572

function findFunctionsToCompile(
  program: NodePath<t.Program>,
  pass: CompilerPass,
  programContext: ProgramContext,
): Array<CompileSource> {
  const queue: Array<CompileSource> = [];
  const traverseFunction = (fn: BabelFn, pass: CompilerPass): void => {
    // In 'all' mode, compile only top level functions
    if (
      pass.opts.compilationMode === 'all' &&
      fn.scope.getProgramParent() !== fn.scope.parent
    ) {
      return;
    }

    const fnType = getReactFunctionType(fn, pass);

    if (pass.opts.environment.validateNoDynamicallyCreatedComponentsOrHooks) {
      validateNoDynamicallyCreatedComponentsOrHooks(fn, pass, programContext);
    }

    if (fnType === null || programContext.alreadyCompiled.has(fn.node)) {
      return;
    }

    /*
     * We may be generating a new FunctionDeclaration node, so we must skip over it or this
     * traversal will loop infinitely.
     * Ensure we avoid visiting the original function again.
     */
    programContext.alreadyCompiled.add(fn.node);
    fn.skip();

    queue.push({kind: 'original', fn, fnType});
  };

  // Main traversal to compile with Forget
  program.traverse(
    {
      ClassDeclaration(node: NodePath<t.ClassDeclaration>) {
        /*
         * Don't visit functions defined inside classes, because they
         * can reference `this` which is unsafe for compilation
         */
        node.skip();
      },

      ClassExpression(node: NodePath<t.ClassExpression>) {
        /*
         * Don't visit functions defined inside classes, because they
         * can reference `this` which is unsafe for compilation
         */
        node.skip();
      },

      FunctionDeclaration: traverseFunction,

      FunctionExpression: traverseFunction,

      ArrowFunctionExpression: traverseFunction,
    },
    {
      ...pass,
      opts: {...pass.opts, ...pass.opts},
      filename: pass.filename ?? null,
    },
  );
  return queue;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does findFunctionsToCompile() do?
findFunctionsToCompile() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts.
Where is findFunctionsToCompile() defined?
findFunctionsToCompile() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts at line 504.
What does findFunctionsToCompile() call?
findFunctionsToCompile() calls 3 function(s): getReactFunctionType, push, validateNoDynamicallyCreatedComponentsOrHooks.
What calls findFunctionsToCompile()?
findFunctionsToCompile() is called by 1 function(s): compileProgram.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free