Home / Class/ PromoteInterposedTemporaries Class — react Architecture

PromoteInterposedTemporaries Class — react Architecture

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

Entity Profile

Dependency Diagram

graph TD
  5e243776_c8a5_6f17_8176_c71b7263aa40["PromoteInterposedTemporaries"]
  dea6b9e7_3c69_6e86_5d64_ba83c7d43ed6["PromoteUsedTemporaries.ts"]
  5e243776_c8a5_6f17_8176_c71b7263aa40 -->|defined in| dea6b9e7_3c69_6e86_5d64_ba83c7d43ed6
  f9fdd0de_c229_7995_966c_feea161831aa["constructor()"]
  5e243776_c8a5_6f17_8176_c71b7263aa40 -->|method| f9fdd0de_c229_7995_966c_feea161831aa
  f55f5967_4a0b_f808_1e1c_34fd02a84293["visitPlace()"]
  5e243776_c8a5_6f17_8176_c71b7263aa40 -->|method| f55f5967_4a0b_f808_1e1c_34fd02a84293
  3b1a75b6_5928_8dea_5f17_cf94a0c97374["visitInstruction()"]
  5e243776_c8a5_6f17_8176_c71b7263aa40 -->|method| 3b1a75b6_5928_8dea_5f17_cf94a0c97374

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts lines 233–423

class PromoteInterposedTemporaries extends ReactiveFunctionVisitor<InterState> {
  #promotable: State;
  #consts: Set<IdentifierId> = new Set();
  #globals: Set<IdentifierId> = new Set();

  /*
   * Unpromoted temporaries will be emitted at their use sites rather than as separate
   * declarations. However, this causes errors if an interposing temporary has been
   * promoted, or if an interposing instruction has had its lvalues deleted, because such
   * temporaries will be emitted as separate statements, which can effectively cause
   * code to be reordered, and when that code has side effects that changes program behavior.
   * This visitor promotes temporarties that have such interposing instructions to preserve
   * source ordering.
   */
  constructor(promotable: State, params: Array<Place | SpreadPattern>) {
    super();
    params.forEach(param => {
      switch (param.kind) {
        case 'Identifier':
          this.#consts.add(param.identifier.id);
          break;
        case 'Spread':
          this.#consts.add(param.place.identifier.id);
          break;
      }
    });
    this.#promotable = promotable;
  }

  override visitPlace(
    _id: InstructionId,
    place: Place,
    state: InterState,
  ): void {
    const promo = state.get(place.identifier.id);
    if (promo) {
      const [identifier, needsPromotion] = promo;
      if (
        needsPromotion &&
        identifier.name === null &&
        !this.#consts.has(identifier.id)
      ) {
        /*
         * If the identifier hasn't been promoted but is marked as needing
         * promotion by the logic in `visitInstruction`, and we've seen a
         * use of it after said marking, promote it
         */
        promoteIdentifier(identifier, this.#promotable);
      }
    }
  }

  override visitInstruction(
    instruction: ReactiveInstruction,
    state: InterState,
  ): void {
    for (const lval of eachInstructionValueLValue(instruction.value)) {
      CompilerError.invariant(lval.identifier.name != null, {
        reason:
          'PromoteInterposedTemporaries: Assignment targets not expected to be temporaries',
        loc: instruction.loc,
      });
    }

    switch (instruction.value.kind) {
      case 'CallExpression':
      case 'MethodCall':
      case 'Await':
      case 'PropertyStore':
      case 'PropertyDelete':
      case 'ComputedStore':
      case 'ComputedDelete':
      case 'PostfixUpdate':
      case 'PrefixUpdate':
      case 'StoreLocal':
      case 'StoreContext':
      case 'StoreGlobal':
      case 'Destructure': {
        let constStore = false;

        if (

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free