Home / Function/ handleRewrite() — react Function Reference

handleRewrite() — react Function Reference

Architecture documentation for the handleRewrite() function in BuildReactiveScopeTerminalsHIR.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  f438b84b_922a_ab8c_c0d1_580131953f20["handleRewrite()"]
  779d40ec_03b1_7ad7_ef48_9ccec3c3bf70["BuildReactiveScopeTerminalsHIR.ts"]
  f438b84b_922a_ab8c_c0d1_580131953f20 -->|defined in| 779d40ec_03b1_7ad7_ef48_9ccec3c3bf70
  67879f67_c0fc_dc2d_b736_b9213153bc4a["buildReactiveScopeTerminalsHIR()"]
  67879f67_c0fc_dc2d_b736_b9213153bc4a -->|calls| f438b84b_922a_ab8c_c0d1_580131953f20
  style f438b84b_922a_ab8c_c0d1_580131953f20 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts lines 271–311

function handleRewrite(
  terminalInfo: TerminalRewriteInfo,
  idx: number,
  context: RewriteContext,
): void {
  // TODO make consistent instruction IDs instead of reusing
  const terminal: ReactiveScopeTerminal | GotoTerminal =
    terminalInfo.kind === 'StartScope'
      ? {
          kind: 'scope',
          fallthrough: terminalInfo.fallthroughId,
          block: terminalInfo.blockId,
          scope: terminalInfo.scope,
          id: terminalInfo.instrId,
          loc: GeneratedSource,
        }
      : {
          kind: 'goto',
          variant: GotoVariant.Break,
          block: terminalInfo.fallthroughId,
          id: terminalInfo.instrId,
          loc: GeneratedSource,
        };

  const currBlockId = context.nextBlockId;
  context.rewrites.push({
    kind: context.source.kind,
    id: currBlockId,
    instructions: context.source.instructions.slice(context.instrSliceIdx, idx),
    preds: context.nextPreds,
    // Only the first rewrite should reuse source block phis
    phis: context.rewrites.length === 0 ? context.source.phis : new Set(),
    terminal,
  });
  context.nextPreds = new Set([currBlockId]);
  context.nextBlockId =
    terminalInfo.kind === 'StartScope'
      ? terminalInfo.blockId
      : terminalInfo.fallthroughId;
  context.instrSliceIdx = idx;
}

Subdomains

Frequently Asked Questions

What does handleRewrite() do?
handleRewrite() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts.
Where is handleRewrite() defined?
handleRewrite() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts at line 271.
What calls handleRewrite()?
handleRewrite() is called by 1 function(s): buildReactiveScopeTerminalsHIR.

Analyze Your Own Codebase

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

Try Supermodel Free