Home / Function/ transformScope() — react Function Reference

transformScope() — react Function Reference

Architecture documentation for the transformScope() function in PruneNonEscapingScopes.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  f6b0f572_362c_d22e_89ed_27e1eef4d74e["transformScope()"]
  49ee75e7_6b19_52e6_3867_ae2c90149d13["PruneScopesTransform"]
  f6b0f572_362c_d22e_89ed_27e1eef4d74e -->|defined in| 49ee75e7_6b19_52e6_3867_ae2c90149d13
  8964b840_74b5_2c96_c227_89dd281fdf38["visitScope()"]
  f6b0f572_362c_d22e_89ed_27e1eef4d74e -->|calls| 8964b840_74b5_2c96_c227_89dd281fdf38
  b639747b_32c3_a4bf_867f_dba5d3901073["transformScope()"]
  f6b0f572_362c_d22e_89ed_27e1eef4d74e -->|calls| b639747b_32c3_a4bf_867f_dba5d3901073
  bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e["values()"]
  f6b0f572_362c_d22e_89ed_27e1eef4d74e -->|calls| bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e
  style f6b0f572_362c_d22e_89ed_27e1eef4d74e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts lines 1021–1060

  override transformScope(
    scopeBlock: ReactiveScopeBlock,
    state: Set<DeclarationId>,
  ): Transformed<ReactiveStatement> {
    this.visitScope(scopeBlock, state);

    /**
     * Scopes may initially appear "empty" because the value being memoized
     * is early-returned from within the scope. For now we intentionaly keep
     * these scopes, and let them get pruned later by PruneUnusedScopes
     * _after_ handling the early-return case in PropagateEarlyReturns.
     *
     * Also keep the scope if an early return was created by some earlier pass,
     * which may happen in alternate compiler configurations.
     */
    if (
      (scopeBlock.scope.declarations.size === 0 &&
        scopeBlock.scope.reassignments.size === 0) ||
      scopeBlock.scope.earlyReturnValue !== null
    ) {
      return {kind: 'keep'};
    }

    const hasMemoizedOutput =
      Array.from(scopeBlock.scope.declarations.values()).some(decl =>
        state.has(decl.identifier.declarationId),
      ) ||
      Array.from(scopeBlock.scope.reassignments).some(identifier =>
        state.has(identifier.declarationId),
      );
    if (hasMemoizedOutput) {
      return {kind: 'keep'};
    } else {
      this.prunedScopes.add(scopeBlock.scope.id);
      return {
        kind: 'replace-many',
        value: scopeBlock.instructions,
      };
    }
  }

Domain

Subdomains

Frequently Asked Questions

What does transformScope() do?
transformScope() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts.
Where is transformScope() defined?
transformScope() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts at line 1021.
What does transformScope() call?
transformScope() calls 3 function(s): transformScope, values, visitScope.

Analyze Your Own Codebase

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

Try Supermodel Free