Home / Function/ visitDependency() — react Function Reference

visitDependency() — react Function Reference

Architecture documentation for the visitDependency() function in PropagateScopeDependenciesHIR.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed["visitDependency()"]
  1be3b542_2ecf_364c_adef_6e5675b7385e["DependencyCollectionContext"]
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed -->|defined in| 1be3b542_2ecf_364c_adef_6e5675b7385e
  b9659720_c932_ebd9_335f_682c49188a34["visitOperand()"]
  b9659720_c932_ebd9_335f_682c49188a34 -->|calls| b1bdda46_c31a_9557_b610_d2ed7c3ceaed
  8d8b17be_69f6_c901_0c65_675b2f52ffc0["visitProperty()"]
  8d8b17be_69f6_c901_0c65_675b2f52ffc0 -->|calls| b1bdda46_c31a_9557_b610_d2ed7c3ceaed
  5b709ffb_65e9_2125_d608_a351c667cd6c["collectDependencies()"]
  5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| b1bdda46_c31a_9557_b610_d2ed7c3ceaed
  ad17cc28_c934_cf1a_ce40_409d2c34592d["inferDependenciesInFn()"]
  ad17cc28_c934_cf1a_ce40_409d2c34592d -->|calls| b1bdda46_c31a_9557_b610_d2ed7c3ceaed
  527555c0_9544_ae6b_5f83_952272d2caa1["Iterable_some()"]
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed -->|calls| 527555c0_9544_ae6b_5f83_952272d2caa1
  6e7c932f_5e2d_52c4_1399_ff365b3858b6["isUseRefType()"]
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed -->|calls| 6e7c932f_5e2d_52c4_1399_ff365b3858b6
  74898d26_a363_cc1f_3e69_ee0694fdc9b7["each()"]
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed -->|calls| 74898d26_a363_cc1f_3e69_ee0694fdc9b7
  e4202808_c854_fd63_c981_990ad95d6125["isScopeActive()"]
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed -->|calls| e4202808_c854_fd63_c981_990ad95d6125
  358cdfdf_e03f_e4de_133c_5b70e0a98d45["push()"]
  b1bdda46_c31a_9557_b610_d2ed7c3ceaed -->|calls| 358cdfdf_e03f_e4de_133c_5b70e0a98d45
  style b1bdda46_c31a_9557_b610_d2ed7c3ceaed fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts lines 558–610

  visitDependency(maybeDependency: ReactiveScopeDependency): void {
    /*
     * Any value used after its originally defining scope has concluded must be added as an
     * output of its defining scope. Regardless of whether its a const or not,
     * some later code needs access to the value. If the current
     * scope we are visiting is the same scope where the value originates, it can't be a dependency
     * on itself.
     */

    /*
     * if originalDeclaration is undefined here, then this is not a local var
     * (all decls e.g. `let x;` should be initialized in BuildHIR)
     */
    const originalDeclaration = this.#declarations.get(
      maybeDependency.identifier.declarationId,
    );
    if (
      originalDeclaration !== undefined &&
      originalDeclaration.scope.value !== null
    ) {
      originalDeclaration.scope.each(scope => {
        if (
          !this.#isScopeActive(scope) &&
          !Iterable_some(
            scope.declarations.values(),
            decl =>
              decl.identifier.declarationId ===
              maybeDependency.identifier.declarationId,
          )
        ) {
          scope.declarations.set(maybeDependency.identifier.id, {
            identifier: maybeDependency.identifier,
            scope: originalDeclaration.scope.value!,
          });
        }
      });
    }

    // ref.current access is not a valid dep
    if (
      isUseRefType(maybeDependency.identifier) &&
      maybeDependency.path.at(0)?.property === 'current'
    ) {
      maybeDependency = {
        identifier: maybeDependency.identifier,
        reactive: maybeDependency.reactive,
        path: [],
      };
    }
    if (this.#checkValidDependency(maybeDependency)) {
      this.#dependencies.value!.push(maybeDependency);
    }
  }

Subdomains

Frequently Asked Questions

What does visitDependency() do?
visitDependency() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts.
Where is visitDependency() defined?
visitDependency() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts at line 558.
What does visitDependency() call?
visitDependency() calls 5 function(s): Iterable_some, each, isScopeActive, isUseRefType, push.
What calls visitDependency()?
visitDependency() is called by 4 function(s): collectDependencies, inferDependenciesInFn, visitOperand, visitProperty.

Analyze Your Own Codebase

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

Try Supermodel Free