Home / Class/ ReactiveFunctionTransform Class — react Architecture

ReactiveFunctionTransform Class — react Architecture

Architecture documentation for the ReactiveFunctionTransform class in visitors.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  af3ace55_db6d_865e_92b9_81486f6af1e7["ReactiveFunctionTransform"]
  21609915_b03a_fd75_b58a_4cb86ef9315b["visitors.ts"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|defined in| 21609915_b03a_fd75_b58a_4cb86ef9315b
  a0320514_135c_2cd9_31b2_7e30472da86b["traverseBlock()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| a0320514_135c_2cd9_31b2_7e30472da86b
  40802d10_d9f1_10c2_2fff_626026f88fb4["transformInstruction()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 40802d10_d9f1_10c2_2fff_626026f88fb4
  54a12a3d_a635_8222_98f7_9dbb45563754["transformTerminal()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 54a12a3d_a635_8222_98f7_9dbb45563754
  b639747b_32c3_a4bf_867f_dba5d3901073["transformScope()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| b639747b_32c3_a4bf_867f_dba5d3901073
  8946cc05_a03c_56f3_cb49_bb83d2f49a8d["transformPrunedScope()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 8946cc05_a03c_56f3_cb49_bb83d2f49a8d
  41f8ce8e_b5b8_2fcb_46ab_0111bb06c2f2["transformValue()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 41f8ce8e_b5b8_2fcb_46ab_0111bb06c2f2
  6ce07d08_da43_d6e5_757c_4e3b219165e2["transformReactiveFunctionValue()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 6ce07d08_da43_d6e5_757c_4e3b219165e2
  2046f7e5_51f5_4e62_fa3f_1036329a3746["traverseValue()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 2046f7e5_51f5_4e62_fa3f_1036329a3746
  31c2e15e_64cc_996c_4233_ced53a2d09ed["traverseInstruction()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 31c2e15e_64cc_996c_4233_ced53a2d09ed
  50f3d941_f0f5_a432_b09a_ae83726a516f["traverseTerminal()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7 -->|method| 50f3d941_f0f5_a432_b09a_ae83726a516f

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/visitors.ts lines 265–573

export class ReactiveFunctionTransform<
  TState = void,
> extends ReactiveFunctionVisitor<TState> {
  override traverseBlock(block: ReactiveBlock, state: TState): void {
    let nextBlock: ReactiveBlock | null = null;
    for (let i = 0; i < block.length; i++) {
      const instr = block[i]!;
      let transformed: Transformed<ReactiveStatement>;
      switch (instr.kind) {
        case 'instruction': {
          transformed = this.transformInstruction(instr.instruction, state);
          break;
        }
        case 'scope': {
          transformed = this.transformScope(instr, state);
          break;
        }
        case 'pruned-scope': {
          transformed = this.transformPrunedScope(instr, state);
          break;
        }
        case 'terminal': {
          transformed = this.transformTerminal(instr, state);
          break;
        }
        default: {
          assertExhaustive(
            instr,
            `Unexpected instruction kind \`${(instr as any).kind}\``,
          );
        }
      }
      switch (transformed.kind) {
        case 'keep': {
          if (nextBlock !== null) {
            nextBlock.push(instr);
          }
          break;
        }
        case 'remove': {
          if (nextBlock === null) {
            nextBlock = block.slice(0, i);
          }
          break;
        }
        case 'replace': {
          nextBlock ??= block.slice(0, i);
          nextBlock.push(transformed.value);
          break;
        }
        case 'replace-many': {
          nextBlock ??= block.slice(0, i);
          nextBlock.push(...transformed.value);
          break;
        }
      }
    }
    if (nextBlock !== null) {
      block.length = 0;
      block.push(...nextBlock);
    }
  }

  transformInstruction(
    instruction: ReactiveInstruction,
    state: TState,
  ): Transformed<ReactiveStatement> {
    this.visitInstruction(instruction, state);
    return {kind: 'keep'};
  }

  transformTerminal(
    stmt: ReactiveTerminalStatement,
    state: TState,
  ): Transformed<ReactiveStatement> {
    this.visitTerminal(stmt, state);
    return {kind: 'keep'};
  }

  transformScope(
    scope: ReactiveScopeBlock,

Domain

Frequently Asked Questions

What is the ReactiveFunctionTransform class?
ReactiveFunctionTransform is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/visitors.ts.
Where is ReactiveFunctionTransform defined?
ReactiveFunctionTransform is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/visitors.ts at line 265.

Analyze Your Own Codebase

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

Try Supermodel Free