Home / Function/ visitInstruction() — react Function Reference

visitInstruction() — react Function Reference

Architecture documentation for the visitInstruction() function in PruneInitializationDependencies.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  f6a9b2b0_32d7_a868_9762_f6fe2182d587["visitInstruction()"]
  e1b0b28f_0a55_63f6_4092_ecaa28a68023["Visitor"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|defined in| e1b0b28f_0a55_63f6_4092_ecaa28a68023
  e1291b8d_d23d_3a82_5ffa_61cb16b82596["visitInstruction()"]
  e1291b8d_d23d_3a82_5ffa_61cb16b82596 -->|calls| f6a9b2b0_32d7_a868_9762_f6fe2182d587
  a7715c66_6895_207b_7553_143987538107["join()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| a7715c66_6895_207b_7553_143987538107
  1f4c3be2_48dd_6671_2858_1a62b1026c5e["visitPlace()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| 1f4c3be2_48dd_6671_2858_1a62b1026c5e
  f96e5378_6102_8b6c_e959_c4faf30befb9["isCreateOnlyHook()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| f96e5378_6102_8b6c_e959_c4faf30befb9
  e1291b8d_d23d_3a82_5ffa_61cb16b82596["visitInstruction()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| e1291b8d_d23d_3a82_5ffa_61cb16b82596
  10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| 10043bf1_f7ee_9ed9_307a_fe3edfd02b09
  1803e4c2_f3f7_62d0_524e_2dde97cd0ee4["eachCallArgument()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| 1803e4c2_f3f7_62d0_524e_2dde97cd0ee4
  4c434fb2_75ab_6c2c_c237_b1d38a1b0141["forEach()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| 4c434fb2_75ab_6c2c_c237_b1d38a1b0141
  940018a6_e890_d3b5_6044_cb8053953421["traverseInstruction()"]
  f6a9b2b0_32d7_a868_9762_f6fe2182d587 -->|calls| 940018a6_e890_d3b5_6044_cb8053953421
  style f6a9b2b0_32d7_a868_9762_f6fe2182d587 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneInitializationDependencies.ts lines 115–171

  override visitInstruction(instruction: ReactiveInstruction): void {
    const state = this.join(
      [...eachInstructionLValue(instruction)].map(
        operand => this.map.get(operand.identifier.id) ?? 'Unknown',
      ),
    );

    const visitCallOrMethodNonArgs = (): void => {
      switch (instruction.value.kind) {
        case 'CallExpression': {
          this.visitPlace(instruction.id, instruction.value.callee, state);
          break;
        }
        case 'MethodCall': {
          this.visitPlace(instruction.id, instruction.value.property, state);
          this.visitPlace(instruction.id, instruction.value.receiver, state);
          break;
        }
      }
    };

    const isHook = (): boolean => {
      let callee = null;
      switch (instruction.value.kind) {
        case 'CallExpression': {
          callee = instruction.value.callee.identifier;
          break;
        }
        case 'MethodCall': {
          callee = instruction.value.property.identifier;
          break;
        }
      }
      return callee != null && getHookKind(this.env, callee) != null;
    };

    switch (instruction.value.kind) {
      case 'CallExpression':
      case 'MethodCall': {
        if (
          instruction.lvalue &&
          this.isCreateOnlyHook(instruction.lvalue.identifier)
        ) {
          [...eachCallArgument(instruction.value.args)].forEach(operand =>
            this.visitPlace(instruction.id, operand, 'Create'),
          );
          visitCallOrMethodNonArgs();
        } else {
          this.traverseInstruction(instruction, isHook() ? 'Update' : state);
        }
        break;
      }
      default: {
        this.traverseInstruction(instruction, state);
      }
    }
  }

Domain

Subdomains

Called By

Frequently Asked Questions

What does visitInstruction() do?
visitInstruction() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneInitializationDependencies.ts.
Where is visitInstruction() defined?
visitInstruction() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneInitializationDependencies.ts at line 115.
What does visitInstruction() call?
visitInstruction() calls 8 function(s): eachCallArgument, eachInstructionLValue, forEach, isCreateOnlyHook, join, traverseInstruction, visitInstruction, visitPlace.
What calls visitInstruction()?
visitInstruction() is called by 1 function(s): visitInstruction.

Analyze Your Own Codebase

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

Try Supermodel Free