Home / Function/ alignObjectMethodScopes() — react Function Reference

alignObjectMethodScopes() — react Function Reference

Architecture documentation for the alignObjectMethodScopes() function in AlignObjectMethodScopes.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  a0a21769_2c81_3d16_a177_aa964620987f["alignObjectMethodScopes()"]
  ad600d8a_ade3_8a40_a17a_ccb4623a8608["AlignObjectMethodScopes.ts"]
  a0a21769_2c81_3d16_a177_aa964620987f -->|defined in| ad600d8a_ade3_8a40_a17a_ccb4623a8608
  a7abe9d6_8eba_2cf2_6e34_62ed30d56ff9["findScopesToMerge()"]
  a0a21769_2c81_3d16_a177_aa964620987f -->|calls| a7abe9d6_8eba_2cf2_6e34_62ed30d56ff9
  cc6dbdb8_321f_04a6_e222_5616c33d7c7c["canonicalize()"]
  a0a21769_2c81_3d16_a177_aa964620987f -->|calls| cc6dbdb8_321f_04a6_e222_5616c33d7c7c
  style a0a21769_2c81_3d16_a177_aa964620987f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignObjectMethodScopes.ts lines 56–100

export function alignObjectMethodScopes(fn: HIRFunction): void {
  // Handle inner functions: we assume that Scopes are disjoint across functions
  for (const [_, block] of fn.body.blocks) {
    for (const {value} of block.instructions) {
      if (
        value.kind === 'ObjectMethod' ||
        value.kind === 'FunctionExpression'
      ) {
        alignObjectMethodScopes(value.loweredFunc.func);
      }
    }
  }

  const scopeGroupsMap = findScopesToMerge(fn).canonicalize();
  /**
   * Step 1: Merge affected scopes to their canonical root.
   */
  for (const [scope, root] of scopeGroupsMap) {
    if (scope !== root) {
      root.range.start = makeInstructionId(
        Math.min(scope.range.start, root.range.start),
      );
      root.range.end = makeInstructionId(
        Math.max(scope.range.end, root.range.end),
      );
    }
  }

  /**
   * Step 2: Repoint identifiers whose scopes were merged.
   */
  for (const [_, block] of fn.body.blocks) {
    for (const {
      lvalue: {identifier},
    } of block.instructions) {
      if (identifier.scope != null) {
        const root = scopeGroupsMap.get(identifier.scope);
        if (root != null) {
          identifier.scope = root;
        }
        // otherwise, this identifier's scope was not affected by this pass
      }
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does alignObjectMethodScopes() do?
alignObjectMethodScopes() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignObjectMethodScopes.ts.
Where is alignObjectMethodScopes() defined?
alignObjectMethodScopes() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignObjectMethodScopes.ts at line 56.
What does alignObjectMethodScopes() call?
alignObjectMethodScopes() calls 2 function(s): canonicalize, findScopesToMerge.

Analyze Your Own Codebase

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

Try Supermodel Free