Home / Function/ recordScopes() — react Function Reference

recordScopes() — react Function Reference

Architecture documentation for the recordScopes() function in visitors.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  e905b26b_28fa_658a_742c_b1836921c75b["recordScopes()"]
  5ffcc39a_a87d_d30c_d2cd_be7a39db81a1["ScopeBlockTraversal"]
  e905b26b_28fa_658a_742c_b1836921c75b -->|defined in| 5ffcc39a_a87d_d30c_d2cd_be7a39db81a1
  3cbb5167_d55c_6775_cfe5_cd15846ca8d2["findTemporariesUsedOutsideDeclaringScope()"]
  3cbb5167_d55c_6775_cfe5_cd15846ca8d2 -->|calls| e905b26b_28fa_658a_742c_b1836921c75b
  5b709ffb_65e9_2125_d608_a351c667cd6c["collectDependencies()"]
  5b709ffb_65e9_2125_d608_a351c667cd6c -->|calls| e905b26b_28fa_658a_742c_b1836921c75b
  style e905b26b_28fa_658a_742c_b1836921c75b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/visitors.ts lines 1256–1294

  recordScopes(block: BasicBlock): void {
    const blockInfo = this.blockInfos.get(block.id);
    if (blockInfo?.kind === 'begin') {
      this.#activeScopes.push(blockInfo.scope.id);
    } else if (blockInfo?.kind === 'end') {
      const top = this.#activeScopes.at(-1);
      CompilerError.invariant(blockInfo.scope.id === top, {
        reason:
          'Expected traversed block fallthrough to match top-most active scope',
        loc: block.instructions[0]?.loc ?? block.terminal.loc,
      });
      this.#activeScopes.pop();
    }

    if (
      block.terminal.kind === 'scope' ||
      block.terminal.kind === 'pruned-scope'
    ) {
      CompilerError.invariant(
        !this.blockInfos.has(block.terminal.block) &&
          !this.blockInfos.has(block.terminal.fallthrough),
        {
          reason: 'Expected unique scope blocks and fallthroughs',
          loc: block.terminal.loc,
        },
      );
      this.blockInfos.set(block.terminal.block, {
        kind: 'begin',
        scope: block.terminal.scope,
        pruned: block.terminal.kind === 'pruned-scope',
        fallthrough: block.terminal.fallthrough,
      });
      this.blockInfos.set(block.terminal.fallthrough, {
        kind: 'end',
        scope: block.terminal.scope,
        pruned: block.terminal.kind === 'pruned-scope',
      });
    }
  }

Subdomains

Frequently Asked Questions

What does recordScopes() do?
recordScopes() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/visitors.ts.
Where is recordScopes() defined?
recordScopes() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/visitors.ts at line 1256.
What calls recordScopes()?
recordScopes() is called by 2 function(s): collectDependencies, findTemporariesUsedOutsideDeclaringScope.

Analyze Your Own Codebase

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

Try Supermodel Free