Home / Function/ getReactFunctionType() — react Function Reference

getReactFunctionType() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  37c561cb_7b67_6332_ee68_b69aaf917134["getReactFunctionType()"]
  9aa4477d_960b_1ea1_b6d9_36076aaa70bd["Program.ts"]
  37c561cb_7b67_6332_ee68_b69aaf917134 -->|defined in| 9aa4477d_960b_1ea1_b6d9_36076aaa70bd
  7fe1be87_de24_09ca_229a_0644af0874a5["findFunctionsToCompile()"]
  7fe1be87_de24_09ca_229a_0644af0874a5 -->|calls| 37c561cb_7b67_6332_ee68_b69aaf917134
  6f61e521_79f8_315c_2443_8700d7e01eaa["validateNoDynamicallyCreatedComponentsOrHooks()"]
  6f61e521_79f8_315c_2443_8700d7e01eaa -->|calls| 37c561cb_7b67_6332_ee68_b69aaf917134
  931a40c4_9b75_45bd_9aff_f4c45e92c16d["tryFindDirectiveEnablingMemoization()"]
  37c561cb_7b67_6332_ee68_b69aaf917134 -->|calls| 931a40c4_9b75_45bd_9aff_f4c45e92c16d
  2bfe28c2_c730_2f65_86db_f782c4b5a3e5["getComponentOrHookLike()"]
  37c561cb_7b67_6332_ee68_b69aaf917134 -->|calls| 2bfe28c2_c730_2f65_86db_f782c4b5a3e5
  55caad3b_d237_c12f_6969_e6e7b691d35f["isComponentDeclaration()"]
  37c561cb_7b67_6332_ee68_b69aaf917134 -->|calls| 55caad3b_d237_c12f_6969_e6e7b691d35f
  9861537f_51c5_8f2f_5daa_1e82083380d5["isHookDeclaration()"]
  37c561cb_7b67_6332_ee68_b69aaf917134 -->|calls| 9861537f_51c5_8f2f_5daa_1e82083380d5
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  37c561cb_7b67_6332_ee68_b69aaf917134 -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  c0248f71_d55d_c77f_df47_00e95f877287["unwrapOr()"]
  37c561cb_7b67_6332_ee68_b69aaf917134 -->|calls| c0248f71_d55d_c77f_df47_00e95f877287
  style 37c561cb_7b67_6332_ee68_b69aaf917134 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts lines 945–992

function getReactFunctionType(
  fn: BabelFn,
  pass: CompilerPass,
): ReactFunctionType | null {
  const hookPattern = pass.opts.environment.hookPattern;
  if (fn.node.body.type === 'BlockStatement') {
    const optInDirectives = tryFindDirectiveEnablingMemoization(
      fn.node.body.directives,
      pass.opts,
    );
    if (optInDirectives.unwrapOr(null) != null) {
      return getComponentOrHookLike(fn, hookPattern) ?? 'Other';
    }
  }

  // Component and hook declarations are known components/hooks
  let componentSyntaxType: ReactFunctionType | null = null;
  if (fn.isFunctionDeclaration()) {
    if (isComponentDeclaration(fn.node)) {
      componentSyntaxType = 'Component';
    } else if (isHookDeclaration(fn.node)) {
      componentSyntaxType = 'Hook';
    }
  }

  switch (pass.opts.compilationMode) {
    case 'annotation': {
      // opt-ins are checked above
      return null;
    }
    case 'infer': {
      // Check if this is a component or hook-like function
      return componentSyntaxType ?? getComponentOrHookLike(fn, hookPattern);
    }
    case 'syntax': {
      return componentSyntaxType;
    }
    case 'all': {
      return getComponentOrHookLike(fn, hookPattern) ?? 'Other';
    }
    default: {
      assertExhaustive(
        pass.opts.compilationMode,
        `Unexpected compilationMode \`${pass.opts.compilationMode}\``,
      );
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does getReactFunctionType() do?
getReactFunctionType() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts.
Where is getReactFunctionType() defined?
getReactFunctionType() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts at line 945.
What does getReactFunctionType() call?
getReactFunctionType() calls 6 function(s): assertExhaustive, getComponentOrHookLike, isComponentDeclaration, isHookDeclaration, tryFindDirectiveEnablingMemoization, unwrapOr.
What calls getReactFunctionType()?
getReactFunctionType() is called by 2 function(s): findFunctionsToCompile, validateNoDynamicallyCreatedComponentsOrHooks.

Analyze Your Own Codebase

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

Try Supermodel Free