Home / Function/ codegenTerminal() — react Function Reference

codegenTerminal() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  4f146c25_f9b5_fd01_865f_04b2fc3071a8["codegenTerminal()"]
  dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|defined in| dc7f10c2_c914_a162_d02b_a10a15c64a5f
  6913ca73_f3c4_9919_bf65_7b95559378b7["codegenBlockNoReset()"]
  6913ca73_f3c4_9919_bf65_7b95559378b7 -->|calls| 4f146c25_f9b5_fd01_865f_04b2fc3071a8
  49736686_6dd0_c888_a448_9dcd1498a17a["codegenLabel()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| 49736686_6dd0_c888_a448_9dcd1498a17a
  ba08546d_2fde_b751_b6d4_89a52ff181a5["codegenForInit()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| ba08546d_2fde_b751_b6d4_89a52ff181a5
  d2920090_42bc_7919_897f_42680a08ace6["codegenInstructionValueToExpression()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| d2920090_42bc_7919_897f_42680a08ace6
  b8125226_b7ac_716f_9ed0_db7e7d00571c["codegenBlock()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| b8125226_b7ac_716f_9ed0_db7e7d00571c
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64["throwTodo()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| cf8d627e_c2f0_6cd4_e5fc_35f3c7005b64
  fa00221c_3f87_f634_2655_5b0ca5860306["codegenLValue()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| fa00221c_3f87_f634_2655_5b0ca5860306
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  0b424541_28a8_fc42_ac4b_b6ae2672cb88["codegenPlaceToExpression()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| 0b424541_28a8_fc42_ac4b_b6ae2672cb88
  9bb6f6d9_ff05_0f27_1a27_bc67145db7ba["convertIdentifier()"]
  4f146c25_f9b5_fd01_865f_04b2fc3071a8 -->|calls| 9bb6f6d9_ff05_0f27_1a27_bc67145db7ba
  style 4f146c25_f9b5_fd01_865f_04b2fc3071a8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts lines 937–1225

function codegenTerminal(
  cx: Context,
  terminal: ReactiveTerminal,
): t.Statement | null {
  switch (terminal.kind) {
    case 'break': {
      if (terminal.targetKind === 'implicit') {
        return null;
      }
      return createBreakStatement(
        terminal.loc,
        terminal.targetKind === 'labeled'
          ? t.identifier(codegenLabel(terminal.target))
          : null,
      );
    }
    case 'continue': {
      if (terminal.targetKind === 'implicit') {
        return null;
      }
      return createContinueStatement(
        terminal.loc,
        terminal.targetKind === 'labeled'
          ? t.identifier(codegenLabel(terminal.target))
          : null,
      );
    }
    case 'for': {
      return createForStatement(
        terminal.loc,
        codegenForInit(cx, terminal.init),
        codegenInstructionValueToExpression(cx, terminal.test),
        terminal.update !== null
          ? codegenInstructionValueToExpression(cx, terminal.update)
          : null,
        codegenBlock(cx, terminal.loop),
      );
    }
    case 'for-in': {
      CompilerError.invariant(terminal.init.kind === 'SequenceExpression', {
        reason: `Expected a sequence expression init for for..in`,
        description: `Got \`${terminal.init.kind}\` expression instead`,
        loc: terminal.init.loc,
      });
      if (terminal.init.instructions.length !== 2) {
        CompilerError.throwTodo({
          reason: 'Support non-trivial for..in inits',
          description: null,
          loc: terminal.init.loc,
          suggestions: null,
        });
      }
      const iterableCollection = terminal.init.instructions[0];
      const iterableItem = terminal.init.instructions[1];
      let lval: t.LVal;
      switch (iterableItem.value.kind) {
        case 'StoreLocal': {
          lval = codegenLValue(cx, iterableItem.value.lvalue.place);
          break;
        }
        case 'Destructure': {
          lval = codegenLValue(cx, iterableItem.value.lvalue.pattern);
          break;
        }
        case 'StoreContext': {
          CompilerError.throwTodo({
            reason: 'Support non-trivial for..in inits',
            description: null,
            loc: terminal.init.loc,
            suggestions: null,
          });
        }
        default:
          CompilerError.invariant(false, {
            reason: `Expected a StoreLocal or Destructure to be assigned to the collection`,
            description: `Found ${iterableItem.value.kind}`,
            loc: iterableItem.value.loc,
          });
      }
      let varDeclKind: 'const' | 'let';
      switch (iterableItem.value.lvalue.kind) {

Domain

Subdomains

Frequently Asked Questions

What does codegenTerminal() do?
codegenTerminal() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts.
Where is codegenTerminal() defined?
codegenTerminal() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts at line 937.
What does codegenTerminal() call?
codegenTerminal() calls 10 function(s): assertExhaustive, codegenBlock, codegenForInit, codegenInstructionValueToExpression, codegenLValue, codegenLabel, codegenPlaceToExpression, convertIdentifier, and 2 more.
What calls codegenTerminal()?
codegenTerminal() is called by 1 function(s): codegenBlockNoReset.

Analyze Your Own Codebase

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

Try Supermodel Free