Home / Function/ codegenReactiveFunction() — react Function Reference

codegenReactiveFunction() — react Function Reference

Architecture documentation for the codegenReactiveFunction() function in CodegenReactiveFunction.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  cc29904c_66f3_5155_9ed7_837866d52047["codegenReactiveFunction()"]
  dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|defined in| dc7f10c2_c914_a162_d02b_a10a15c64a5f
  33e8ddc7_2075_1da1_7e05_66d1f4c34a3c["codegenFunction()"]
  33e8ddc7_2075_1da1_7e05_66d1f4c34a3c -->|calls| cc29904c_66f3_5155_9ed7_837866d52047
  d8edf87e_ea78_c9d0_b5c9_13d68891efec["codegenInstructionValue()"]
  d8edf87e_ea78_c9d0_b5c9_13d68891efec -->|calls| cc29904c_66f3_5155_9ed7_837866d52047
  a9a859b4_40bd_bdc3_176d_9a4435a365fc["declare()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| a9a859b4_40bd_bdc3_176d_9a4435a365fc
  8dfb7762_ed37_e375_e758_7cbc52714531["convertParameter()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| 8dfb7762_ed37_e375_e758_7cbc52714531
  b8125226_b7ac_716f_9ed0_db7e7d00571c["codegenBlock()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| b8125226_b7ac_716f_9ed0_db7e7d00571c
  6d8385f7_ca89_0968_e79e_ed2e1aa846c9["hasAnyErrors()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| 6d8385f7_ca89_0968_e79e_ed2e1aa846c9
  9217845a_d29d_c624_b607_e3b35cf604bc["Err()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| 9217845a_d29d_c624_b607_e3b35cf604bc
  2435b5f8_41a6_0458_ba88_4479b965455f["visitReactiveFunction()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| 2435b5f8_41a6_0458_ba88_4479b965455f
  9f0e6a52_ff9e_00f3_1760_5fddfd89b234["Ok()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| 9f0e6a52_ff9e_00f3_1760_5fddfd89b234
  8e8b7ee8_d3c2_f98d_17e1_c5ff5fff1940["map()"]
  cc29904c_66f3_5155_9ed7_837866d52047 -->|calls| 8e8b7ee8_d3c2_f98d_17e1_c5ff5fff1940
  style cc29904c_66f3_5155_9ed7_837866d52047 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts lines 347–394

function codegenReactiveFunction(
  cx: Context,
  fn: ReactiveFunction,
): Result<CodegenFunction, CompilerError> {
  for (const param of fn.params) {
    const place = param.kind === 'Identifier' ? param : param.place;
    cx.temp.set(place.identifier.declarationId, null);
    cx.declare(place.identifier);
  }

  const params = fn.params.map(param => convertParameter(param));
  const body: t.BlockStatement = codegenBlock(cx, fn.body);
  body.directives = fn.directives.map(d => t.directive(t.directiveLiteral(d)));
  const statements = body.body;
  if (statements.length !== 0) {
    const last = statements[statements.length - 1];
    if (last.type === 'ReturnStatement' && last.argument == null) {
      statements.pop();
    }
  }

  if (cx.errors.hasAnyErrors()) {
    return Err(cx.errors);
  }

  const countMemoBlockVisitor = new CountMemoBlockVisitor(fn.env);
  visitReactiveFunction(fn, countMemoBlockVisitor, undefined);

  return Ok({
    type: 'CodegenFunction',
    loc: fn.loc,
    id: fn.id !== null ? t.identifier(fn.id) : null,
    nameHint: fn.nameHint,
    params,
    body,
    generator: fn.generator,
    async: fn.async,
    memoSlotsUsed: cx.nextCacheIndex,
    memoBlocks: countMemoBlockVisitor.memoBlocks,
    memoValues: countMemoBlockVisitor.memoValues,
    prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks,
    prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
    outlined: [],
    hasFireRewrite: fn.env.hasFireRewrite,
    hasInferredEffect: fn.env.hasInferredEffect,
    inferredEffectLocations: fn.env.inferredEffectLocations,
  });
}

Domain

Subdomains

Frequently Asked Questions

What does codegenReactiveFunction() do?
codegenReactiveFunction() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts.
Where is codegenReactiveFunction() defined?
codegenReactiveFunction() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts at line 347.
What does codegenReactiveFunction() call?
codegenReactiveFunction() calls 8 function(s): Err, Ok, codegenBlock, convertParameter, declare, hasAnyErrors, map, visitReactiveFunction.
What calls codegenReactiveFunction()?
codegenReactiveFunction() is called by 2 function(s): codegenFunction, codegenInstructionValue.

Analyze Your Own Codebase

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

Try Supermodel Free