Home / Function/ insertNewOutlinedFunctionNode() — react Function Reference

insertNewOutlinedFunctionNode() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  ade5f434_a213_5611_b4fa_0fdd254474e1["insertNewOutlinedFunctionNode()"]
  9aa4477d_960b_1ea1_b6d9_36076aaa70bd["Program.ts"]
  ade5f434_a213_5611_b4fa_0fdd254474e1 -->|defined in| 9aa4477d_960b_1ea1_b6d9_36076aaa70bd
  1c9af54b_10e9_8985_e772_1f517e46c560["compileProgram()"]
  1c9af54b_10e9_8985_e772_1f517e46c560 -->|calls| ade5f434_a213_5611_b4fa_0fdd254474e1
  1e86a202_a347_7857_88d3_50b0dc42a045["createNewFunctionNode()"]
  ade5f434_a213_5611_b4fa_0fdd254474e1 -->|calls| 1e86a202_a347_7857_88d3_50b0dc42a045
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  ade5f434_a213_5611_b4fa_0fdd254474e1 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  ade5f434_a213_5611_b4fa_0fdd254474e1 -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  style ade5f434_a213_5611_b4fa_0fdd254474e1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts lines 283–329

function insertNewOutlinedFunctionNode(
  program: NodePath<t.Program>,
  originalFn: BabelFn,
  compiledFn: CodegenFunction,
): BabelFn {
  switch (originalFn.type) {
    case 'FunctionDeclaration': {
      return originalFn.insertAfter(
        createNewFunctionNode(originalFn, compiledFn),
      )[0]!;
    }
    /**
     * We can't just append the outlined function as a sibling of the original function if it is an
     * (Arrow)FunctionExpression parented by a VariableDeclaration, as this would cause its parent
     * to become a SequenceExpression instead which breaks a bunch of assumptions elsewhere in the
     * plugin.
     *
     * To get around this, we always synthesize a new FunctionDeclaration for the outlined function
     * and insert it as a true sibling to the original function.
     */
    case 'ArrowFunctionExpression':
    case 'FunctionExpression': {
      const fn: t.FunctionDeclaration = {
        type: 'FunctionDeclaration',
        id: compiledFn.id,
        loc: originalFn.node.loc ?? null,
        async: compiledFn.async,
        generator: compiledFn.generator,
        params: compiledFn.params,
        body: compiledFn.body,
      };
      const insertedFuncDecl = program.pushContainer('body', [fn])[0]!;
      CompilerError.invariant(insertedFuncDecl.isFunctionDeclaration(), {
        reason: 'Expected inserted function declaration',
        description: `Got: ${insertedFuncDecl}`,
        loc: insertedFuncDecl.node?.loc ?? GeneratedSource,
      });
      return insertedFuncDecl;
    }
    default: {
      assertExhaustive(
        originalFn,
        `Inserting unhandled function: ${originalFn}`,
      );
    }
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does insertNewOutlinedFunctionNode() do?
insertNewOutlinedFunctionNode() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts.
Where is insertNewOutlinedFunctionNode() defined?
insertNewOutlinedFunctionNode() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts at line 283.
What does insertNewOutlinedFunctionNode() call?
insertNewOutlinedFunctionNode() calls 3 function(s): assertExhaustive, createNewFunctionNode, invariant.
What calls insertNewOutlinedFunctionNode()?
insertNewOutlinedFunctionNode() 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