Home / Class/ Context Class — react Architecture

Context Class — react Architecture

Architecture documentation for the Context class in CodegenReactiveFunction.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  0fc11255_0435_9837_dff9_fb4e66f27eb6["Context"]
  dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"]
  0fc11255_0435_9837_dff9_fb4e66f27eb6 -->|defined in| dc7f10c2_c914_a162_d02b_a10a15c64a5f
  a9e371c9_dd30_c43b_b3e2_c9bcd79a0909["constructor()"]
  0fc11255_0435_9837_dff9_fb4e66f27eb6 -->|method| a9e371c9_dd30_c43b_b3e2_c9bcd79a0909
  82938135_65b7_8228_78bc_e476d302aed6["nextCacheIndex()"]
  0fc11255_0435_9837_dff9_fb4e66f27eb6 -->|method| 82938135_65b7_8228_78bc_e476d302aed6
  a9a859b4_40bd_bdc3_176d_9a4435a365fc["declare()"]
  0fc11255_0435_9837_dff9_fb4e66f27eb6 -->|method| a9a859b4_40bd_bdc3_176d_9a4435a365fc
  43b28878_9b1d_6aeb_0d77_25080004044d["hasDeclared()"]
  0fc11255_0435_9837_dff9_fb4e66f27eb6 -->|method| 43b28878_9b1d_6aeb_0d77_25080004044d
  a599ee29_a03a_9f21_bb90_a7ef23973fc6["synthesizeName()"]
  0fc11255_0435_9837_dff9_fb4e66f27eb6 -->|method| a599ee29_a03a_9f21_bb90_a7ef23973fc6

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts lines 434–489

class Context {
  env: Environment;
  fnName: string;
  #nextCacheIndex: number = 0;
  /**
   * Tracks which named variables have been declared to dedupe declarations,
   * so this uses DeclarationId instead of IdentifierId
   */
  #declarations: Set<DeclarationId> = new Set();
  temp: Temporaries;
  errors: CompilerError = new CompilerError();
  objectMethods: Map<IdentifierId, ObjectMethod> = new Map();
  uniqueIdentifiers: Set<string>;
  fbtOperands: Set<IdentifierId>;
  synthesizedNames: Map<string, ValidIdentifierName> = new Map();

  constructor(
    env: Environment,
    fnName: string,
    uniqueIdentifiers: Set<string>,
    fbtOperands: Set<IdentifierId>,
    temporaries: Temporaries | null = null,
  ) {
    this.env = env;
    this.fnName = fnName;
    this.uniqueIdentifiers = uniqueIdentifiers;
    this.fbtOperands = fbtOperands;
    this.temp = temporaries !== null ? new Map(temporaries) : new Map();
  }
  get nextCacheIndex(): number {
    return this.#nextCacheIndex++;
  }

  declare(identifier: Identifier): void {
    this.#declarations.add(identifier.declarationId);
  }

  hasDeclared(identifier: Identifier): boolean {
    return this.#declarations.has(identifier.declarationId);
  }

  synthesizeName(name: string): ValidIdentifierName {
    const previous = this.synthesizedNames.get(name);
    if (previous !== undefined) {
      return previous;
    }
    let validated = makeIdentifierName(name).value;
    let index = 0;
    while (this.uniqueIdentifiers.has(validated)) {
      validated = makeIdentifierName(`${name}${index++}`).value;
    }
    this.uniqueIdentifiers.add(validated);
    this.synthesizedNames.set(name, validated);
    return validated;
  }
}

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free