Home / Function/ visitScope() — react Function Reference

visitScope() — react Function Reference

Architecture documentation for the visitScope() function in PruneNonReactiveDependencies.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  d124bc9e_bf1f_ee58_fa50_3bd3eae2713e["visitScope()"]
  6bdf962e_c948_094c_e8a4_6eba930b0763["Visitor"]
  d124bc9e_bf1f_ee58_fa50_3bd3eae2713e -->|defined in| 6bdf962e_c948_094c_e8a4_6eba930b0763
  d9010862_8799_d47e_ade8_fb2b056edb3c["traverseScope()"]
  d124bc9e_bf1f_ee58_fa50_3bd3eae2713e -->|calls| d9010862_8799_d47e_ade8_fb2b056edb3c
  79d26ddd_c45e_d84c_e7f4_1e02577b0087["visitScope()"]
  d124bc9e_bf1f_ee58_fa50_3bd3eae2713e -->|calls| 79d26ddd_c45e_d84c_e7f4_1e02577b0087
  style d124bc9e_bf1f_ee58_fa50_3bd3eae2713e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonReactiveDependencies.ts lines 93–118

  override visitScope(
    scopeBlock: ReactiveScopeBlock,
    state: ReactiveIdentifiers,
  ): void {
    this.traverseScope(scopeBlock, state);
    for (const dep of scopeBlock.scope.dependencies) {
      const isReactive = state.has(dep.identifier.id);
      if (!isReactive) {
        scopeBlock.scope.dependencies.delete(dep);
      }
    }
    if (scopeBlock.scope.dependencies.size !== 0) {
      /**
       * If any of a scope's dependencies are reactive, then all of its
       * outputs will re-evaluate whenever those dependencies change.
       * Mark all of the outputs as reactive to reflect the fact that
       * they may change in practice based on a reactive input.
       */
      for (const [, declaration] of scopeBlock.scope.declarations) {
        state.add(declaration.identifier.id);
      }
      for (const reassignment of scopeBlock.scope.reassignments) {
        state.add(reassignment.id);
      }
    }
  }

Frequently Asked Questions

What does visitScope() do?
visitScope() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonReactiveDependencies.ts.
Where is visitScope() defined?
visitScope() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonReactiveDependencies.ts at line 93.
What does visitScope() call?
visitScope() calls 2 function(s): traverseScope, visitScope.

Analyze Your Own Codebase

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

Try Supermodel Free