Home / Function/ transformTerminal() — react Function Reference

transformTerminal() — react Function Reference

Architecture documentation for the transformTerminal() function in PruneUnusedLabels.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  3ce1ff3b_6e81_02a3_536a_76e3ce96f6c3["transformTerminal()"]
  894c3941_1d64_1249_9677_948e95b5ad37["Transform"]
  3ce1ff3b_6e81_02a3_536a_76e3ce96f6c3 -->|defined in| 894c3941_1d64_1249_9677_948e95b5ad37
  54a12a3d_a635_8222_98f7_9dbb45563754["transformTerminal()"]
  3ce1ff3b_6e81_02a3_536a_76e3ce96f6c3 -->|calls| 54a12a3d_a635_8222_98f7_9dbb45563754
  55773a39_5b37_d0fb_a280_dc321d87f4fb["traverseTerminal()"]
  3ce1ff3b_6e81_02a3_536a_76e3ce96f6c3 -->|calls| 55773a39_5b37_d0fb_a280_dc321d87f4fb
  style 3ce1ff3b_6e81_02a3_536a_76e3ce96f6c3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedLabels.ts lines 32–65

  override transformTerminal(
    stmt: ReactiveTerminalStatement,
    state: Labels,
  ): Transformed<ReactiveStatement> {
    this.traverseTerminal(stmt, state);
    const {terminal} = stmt;
    if (
      (terminal.kind === 'break' || terminal.kind === 'continue') &&
      terminal.targetKind === 'labeled'
    ) {
      state.add(terminal.target);
    }
    // Is this terminal reachable via a break/continue to its label?
    const isReachableLabel = stmt.label !== null && state.has(stmt.label.id);
    if (stmt.terminal.kind === 'label' && !isReachableLabel) {
      // Flatten labeled terminals where the label isn't necessary
      const block = [...stmt.terminal.block];
      const last = block.at(-1);
      if (
        last !== undefined &&
        last.kind === 'terminal' &&
        last.terminal.kind === 'break' &&
        last.terminal.target === null
      ) {
        block.pop();
      }
      return {kind: 'replace-many', value: block};
    } else {
      if (!isReachableLabel && stmt.label != null) {
        stmt.label.implicit = true;
      }
      return {kind: 'keep'};
    }
  }

Domain

Subdomains

Frequently Asked Questions

What does transformTerminal() do?
transformTerminal() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedLabels.ts.
Where is transformTerminal() defined?
transformTerminal() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneUnusedLabels.ts at line 32.
What does transformTerminal() call?
transformTerminal() calls 2 function(s): transformTerminal, traverseTerminal.

Analyze Your Own Codebase

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

Try Supermodel Free