Home / Function/ traverseBlock() — react Function Reference

traverseBlock() — react Function Reference

Architecture documentation for the traverseBlock() function in visitors.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  a0320514_135c_2cd9_31b2_7e30472da86b["traverseBlock()"]
  af3ace55_db6d_865e_92b9_81486f6af1e7["ReactiveFunctionTransform"]
  a0320514_135c_2cd9_31b2_7e30472da86b -->|defined in| af3ace55_db6d_865e_92b9_81486f6af1e7
  c6838a07_559a_1310_1c4f_e78266267fb1["traverseBlock()"]
  c6838a07_559a_1310_1c4f_e78266267fb1 -->|calls| a0320514_135c_2cd9_31b2_7e30472da86b
  40802d10_d9f1_10c2_2fff_626026f88fb4["transformInstruction()"]
  a0320514_135c_2cd9_31b2_7e30472da86b -->|calls| 40802d10_d9f1_10c2_2fff_626026f88fb4
  b639747b_32c3_a4bf_867f_dba5d3901073["transformScope()"]
  a0320514_135c_2cd9_31b2_7e30472da86b -->|calls| b639747b_32c3_a4bf_867f_dba5d3901073
  8946cc05_a03c_56f3_cb49_bb83d2f49a8d["transformPrunedScope()"]
  a0320514_135c_2cd9_31b2_7e30472da86b -->|calls| 8946cc05_a03c_56f3_cb49_bb83d2f49a8d
  54a12a3d_a635_8222_98f7_9dbb45563754["transformTerminal()"]
  a0320514_135c_2cd9_31b2_7e30472da86b -->|calls| 54a12a3d_a635_8222_98f7_9dbb45563754
  c6838a07_559a_1310_1c4f_e78266267fb1["traverseBlock()"]
  a0320514_135c_2cd9_31b2_7e30472da86b -->|calls| c6838a07_559a_1310_1c4f_e78266267fb1
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  a0320514_135c_2cd9_31b2_7e30472da86b -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  style a0320514_135c_2cd9_31b2_7e30472da86b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/visitors.ts lines 268–326

  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);
    }
  }

Domain

Subdomains

Called By

Frequently Asked Questions

What does traverseBlock() do?
traverseBlock() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/visitors.ts.
Where is traverseBlock() defined?
traverseBlock() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/visitors.ts at line 268.
What does traverseBlock() call?
traverseBlock() calls 6 function(s): assertExhaustive, transformInstruction, transformPrunedScope, transformScope, transformTerminal, traverseBlock.
What calls traverseBlock()?
traverseBlock() is called by 1 function(s): traverseBlock.

Analyze Your Own Codebase

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

Try Supermodel Free