Home / Class/ Visitor Class — react Architecture

Visitor Class — react Architecture

Architecture documentation for the Visitor class in ExtractScopeDeclarationsFromDestructuring.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  b58ba090_1fb5_5776_b61b_d8510ef16394["Visitor"]
  791ee72b_8a79_10a6_5a13_5297a1e50d89["ExtractScopeDeclarationsFromDestructuring.ts"]
  b58ba090_1fb5_5776_b61b_d8510ef16394 -->|defined in| 791ee72b_8a79_10a6_5a13_5297a1e50d89
  efc55709_424e_1e0c_5f10_7e9c80368cf4["visitScope()"]
  b58ba090_1fb5_5776_b61b_d8510ef16394 -->|method| efc55709_424e_1e0c_5f10_7e9c80368cf4
  cc0d3b4e_a169_bc13_335d_35432b193034["transformInstruction()"]
  b58ba090_1fb5_5776_b61b_d8510ef16394 -->|method| cc0d3b4e_a169_bc13_335d_35432b193034

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/ExtractScopeDeclarationsFromDestructuring.ts lines 106–152

class Visitor extends ReactiveFunctionTransform<State> {
  override visitScope(scope: ReactiveScopeBlock, state: State): void {
    for (const [, declaration] of scope.scope.declarations) {
      state.declared.add(declaration.identifier.declarationId);
    }
    this.traverseScope(scope, state);
  }

  override transformInstruction(
    instruction: ReactiveInstruction,
    state: State,
  ): Transformed<ReactiveStatement> {
    this.visitInstruction(instruction, state);

    let instructionsToProcess: Array<ReactiveInstruction> = [instruction];
    let result: Transformed<ReactiveStatement> = {kind: 'keep'};

    if (instruction.value.kind === 'Destructure') {
      const transformed = transformDestructuring(
        state,
        instruction,
        instruction.value,
      );
      if (transformed) {
        instructionsToProcess = transformed;
        result = {
          kind: 'replace-many',
          value: transformed.map(instruction => ({
            kind: 'instruction',
            instruction,
          })),
        };
      }
    }

    // Update state.declared with declarations from the instruction(s)
    for (const instr of instructionsToProcess) {
      for (const [place, kind] of eachInstructionLValueWithKind(instr)) {
        if (kind !== InstructionKind.Reassign) {
          state.declared.add(place.identifier.declarationId);
        }
      }
    }

    return result;
  }
}

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free