Home / Function/ mergeOverlappingReactiveScopesHIR() — react Function Reference

mergeOverlappingReactiveScopesHIR() — react Function Reference

Architecture documentation for the mergeOverlappingReactiveScopesHIR() function in MergeOverlappingReactiveScopesHIR.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  ee1add24_e8b1_776d_87ba_d88fe78f7873["mergeOverlappingReactiveScopesHIR()"]
  78244170_3d42_f86a_ea59_bce3e065fcfd["MergeOverlappingReactiveScopesHIR.ts"]
  ee1add24_e8b1_776d_87ba_d88fe78f7873 -->|defined in| 78244170_3d42_f86a_ea59_bce3e065fcfd
  20604946_1e38_3a1d_16f9_b7ef2a574d7c["collectScopeInfo()"]
  ee1add24_e8b1_776d_87ba_d88fe78f7873 -->|calls| 20604946_1e38_3a1d_16f9_b7ef2a574d7c
  764ec9fb_0ee9_a9ca_abc4_d7c652d01a09["getOverlappingReactiveScopes()"]
  ee1add24_e8b1_776d_87ba_d88fe78f7873 -->|calls| 764ec9fb_0ee9_a9ca_abc4_d7c652d01a09
  4c434fb2_75ab_6c2c_c237_b1d38a1b0141["forEach()"]
  ee1add24_e8b1_776d_87ba_d88fe78f7873 -->|calls| 4c434fb2_75ab_6c2c_c237_b1d38a1b0141
  d0270ab6_a621_bd55_a1b9_a5cad8b406b2["makeInstructionId()"]
  ee1add24_e8b1_776d_87ba_d88fe78f7873 -->|calls| d0270ab6_a621_bd55_a1b9_a5cad8b406b2
  74efde51_a311_d84c_0e23_ddafd072e338["find()"]
  ee1add24_e8b1_776d_87ba_d88fe78f7873 -->|calls| 74efde51_a311_d84c_0e23_ddafd072e338
  style ee1add24_e8b1_776d_87ba_d88fe78f7873 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/HIR/MergeOverlappingReactiveScopesHIR.ts lines 105–136

export function mergeOverlappingReactiveScopesHIR(fn: HIRFunction): void {
  /**
   * Collect all scopes eagerly because some scopes begin before the first
   * instruction that references them (due to alignReactiveScopesToBlocks)
   */
  const scopesInfo = collectScopeInfo(fn);

  /**
   * Iterate through scopes and instructions to find which should be merged
   */
  const joinedScopes = getOverlappingReactiveScopes(fn, scopesInfo);

  /**
   * Merge scopes and rewrite all references
   */
  joinedScopes.forEach((scope, groupScope) => {
    if (scope !== groupScope) {
      groupScope.range.start = makeInstructionId(
        Math.min(groupScope.range.start, scope.range.start),
      );
      groupScope.range.end = makeInstructionId(
        Math.max(groupScope.range.end, scope.range.end),
      );
    }
  });
  for (const [place, originalScope] of scopesInfo.placeScopes) {
    const nextScope = joinedScopes.find(originalScope);
    if (nextScope !== null && nextScope !== originalScope) {
      place.identifier.scope = nextScope;
    }
  }
}

Subdomains

Frequently Asked Questions

What does mergeOverlappingReactiveScopesHIR() do?
mergeOverlappingReactiveScopesHIR() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/HIR/MergeOverlappingReactiveScopesHIR.ts.
Where is mergeOverlappingReactiveScopesHIR() defined?
mergeOverlappingReactiveScopesHIR() is defined in compiler/packages/babel-plugin-react-compiler/src/HIR/MergeOverlappingReactiveScopesHIR.ts at line 105.
What does mergeOverlappingReactiveScopesHIR() call?
mergeOverlappingReactiveScopesHIR() calls 5 function(s): collectScopeInfo, find, forEach, getOverlappingReactiveScopes, makeInstructionId.

Analyze Your Own Codebase

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

Try Supermodel Free