Home / Class/ CollectPromotableTemporaries Class — react Architecture

CollectPromotableTemporaries Class — react Architecture

Architecture documentation for the CollectPromotableTemporaries class in PromoteUsedTemporaries.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  2d7f49dc_9f8c_81fd_309a_8073e926f822["CollectPromotableTemporaries"]
  dea6b9e7_3c69_6e86_5d64_ba83c7d43ed6["PromoteUsedTemporaries.ts"]
  2d7f49dc_9f8c_81fd_309a_8073e926f822 -->|defined in| dea6b9e7_3c69_6e86_5d64_ba83c7d43ed6
  0969615b_d42e_1e00_4d32_241b2d2f6b7c["visitPlace()"]
  2d7f49dc_9f8c_81fd_309a_8073e926f822 -->|method| 0969615b_d42e_1e00_4d32_241b2d2f6b7c
  fef1bf35_8d3b_cf6f_067f_15c57d993e32["visitValue()"]
  2d7f49dc_9f8c_81fd_309a_8073e926f822 -->|method| fef1bf35_8d3b_cf6f_067f_15c57d993e32
  8834a4be_3fe5_9e26_47ef_edf1535bc455["visitPrunedScope()"]
  2d7f49dc_9f8c_81fd_309a_8073e926f822 -->|method| 8834a4be_3fe5_9e26_47ef_edf1535bc455
  2ff2db5a_e5d3_6bcb_94e0_c3c5c01c2e77["visitScope()"]
  2d7f49dc_9f8c_81fd_309a_8073e926f822 -->|method| 2ff2db5a_e5d3_6bcb_94e0_c3c5c01c2e77

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts lines 186–230

class CollectPromotableTemporaries extends ReactiveFunctionVisitor<State> {
  activeScopes: Array<ScopeId> = [];

  override visitPlace(_id: InstructionId, place: Place, state: State): void {
    if (
      this.activeScopes.length !== 0 &&
      state.pruned.has(place.identifier.declarationId)
    ) {
      const prunedPlace = state.pruned.get(place.identifier.declarationId)!;
      if (prunedPlace.activeScopes.indexOf(this.activeScopes.at(-1)!) === -1) {
        prunedPlace.usedOutsideScope = true;
      }
    }
  }

  override visitValue(
    id: InstructionId,
    value: ReactiveValue,
    state: State,
  ): void {
    this.traverseValue(id, value, state);
    if (value.kind === 'JsxExpression' && value.tag.kind === 'Identifier') {
      state.tags.add(value.tag.identifier.declarationId);
    }
  }

  override visitPrunedScope(
    scopeBlock: PrunedReactiveScopeBlock,
    state: State,
  ): void {
    for (const [_id, decl] of scopeBlock.scope.declarations) {
      state.pruned.set(decl.identifier.declarationId, {
        activeScopes: [...this.activeScopes],
        usedOutsideScope: false,
      });
    }
    this.visitBlock(scopeBlock.instructions, state);
  }

  override visitScope(scopeBlock: ReactiveScopeBlock, state: State): void {
    this.activeScopes.push(scopeBlock.scope.id);
    this.traverseScope(scopeBlock, state);
    this.activeScopes.pop();
  }
}

Domain

Frequently Asked Questions

What is the CollectPromotableTemporaries class?
CollectPromotableTemporaries is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts.
Where is CollectPromotableTemporaries defined?
CollectPromotableTemporaries is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts at line 186.

Analyze Your Own Codebase

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

Try Supermodel Free