Home / Function/ transformScope() — react Function Reference

transformScope() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  1e7c0dce_245f_f126_024d_01c422b5d768["transformScope()"]
  d9cfc6c8_2b94_462b_69b8_bedddf5c2c61["Transform"]
  1e7c0dce_245f_f126_024d_01c422b5d768 -->|defined in| d9cfc6c8_2b94_462b_69b8_bedddf5c2c61
  style 1e7c0dce_245f_f126_024d_01c422b5d768 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneAlwaysInvalidatingScopes.ts lines 84–117

  override transformScope(
    scopeBlock: ReactiveScopeBlock,
    _withinScope: boolean,
  ): Transformed<ReactiveStatement> {
    this.visitScope(scopeBlock, true);

    for (const dep of scopeBlock.scope.dependencies) {
      if (this.unmemoizedValues.has(dep.identifier)) {
        /*
         * This scope depends on an always-invalidating value so the scope will always invalidate:
         * prune it to avoid wasted comparisons
         */
        for (const [_, decl] of scopeBlock.scope.declarations) {
          if (this.alwaysInvalidatingValues.has(decl.identifier)) {
            this.unmemoizedValues.add(decl.identifier);
          }
        }
        for (const identifier of scopeBlock.scope.reassignments) {
          if (this.alwaysInvalidatingValues.has(identifier)) {
            this.unmemoizedValues.add(identifier);
          }
        }
        return {
          kind: 'replace',
          value: {
            kind: 'pruned-scope',
            scope: scopeBlock.scope,
            instructions: scopeBlock.instructions,
          },
        };
      }
    }
    return {kind: 'keep'};
  }

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/PruneAlwaysInvalidatingScopes.ts.
Where is transformScope() defined?
transformScope() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneAlwaysInvalidatingScopes.ts at line 84.

Analyze Your Own Codebase

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

Try Supermodel Free