Home / Class/ Visitor Class — react Architecture

Visitor Class — react Architecture

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

Entity Profile

Dependency Diagram

graph TD
  a0777e2d_7e90_b69c_255a_fe48677d448a["Visitor"]
  4021b024_bc48_5236_4c88_793e93a1cbe0["CollectReactiveIdentifiers.ts"]
  a0777e2d_7e90_b69c_255a_fe48677d448a -->|defined in| 4021b024_bc48_5236_4c88_793e93a1cbe0
  d6e73cbd_7bc3_86c6_6046_fb97854d92e5["visitLValue()"]
  a0777e2d_7e90_b69c_255a_fe48677d448a -->|method| d6e73cbd_7bc3_86c6_6046_fb97854d92e5
  94ee66e2_17c4_3e91_090f_7cb223ef7f75["visitPlace()"]
  a0777e2d_7e90_b69c_255a_fe48677d448a -->|method| 94ee66e2_17c4_3e91_090f_7cb223ef7f75
  a9c6b7d9_4ec5_27f1_c527_5516a037bb60["visitPrunedScope()"]
  a0777e2d_7e90_b69c_255a_fe48677d448a -->|method| a9c6b7d9_4ec5_27f1_c527_5516a037bb60

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CollectReactiveIdentifiers.ts lines 20–63

class Visitor extends ReactiveFunctionVisitor<Set<IdentifierId>> {
  /*
   * Visitors don't visit lvalues as places by default, but we want to visit all places to
   * check for reactivity
   */
  override visitLValue(
    id: InstructionId,
    lvalue: Place,
    state: Set<IdentifierId>,
  ): void {
    this.visitPlace(id, lvalue, state);
  }

  /*
   * This visitor only infers data dependencies and does not account for control dependencies
   * where a variable may be assigned a different value based on some conditional, eg via two
   * different paths of an if statement.
   */
  override visitPlace(
    _id: InstructionId,
    place: Place,
    state: Set<IdentifierId>,
  ): void {
    if (place.reactive) {
      state.add(place.identifier.id);
    }
  }

  override visitPrunedScope(
    scopeBlock: PrunedReactiveScopeBlock,
    state: Set<IdentifierId>,
  ): void {
    this.traversePrunedScope(scopeBlock, state);

    for (const [id, decl] of scopeBlock.scope.declarations) {
      if (
        !isPrimitiveType(decl.identifier) &&
        !isStableRefType(decl.identifier, state)
      ) {
        state.add(id);
      }
    }
  }
}

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/CollectReactiveIdentifiers.ts.
Where is Visitor defined?
Visitor is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CollectReactiveIdentifiers.ts at line 20.

Analyze Your Own Codebase

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

Try Supermodel Free