Home / Class/ State Class — react Architecture

State Class — react Architecture

Architecture documentation for the State class in DeadCodeElimination.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  a43ec24c_7afb_47c4_0951_89905012df7f["State"]
  12a58551_b77c_3215_7e97_0c27aabd262e["DeadCodeElimination.ts"]
  a43ec24c_7afb_47c4_0951_89905012df7f -->|defined in| 12a58551_b77c_3215_7e97_0c27aabd262e
  2631e558_59f0_77c5_38d6_1dcbff7863e9["constructor()"]
  a43ec24c_7afb_47c4_0951_89905012df7f -->|method| 2631e558_59f0_77c5_38d6_1dcbff7863e9
  b1f70586_b3c9_0ab7_ac2b_08f8ff64792a["reference()"]
  a43ec24c_7afb_47c4_0951_89905012df7f -->|method| b1f70586_b3c9_0ab7_ac2b_08f8ff64792a
  1ddcaaa6_a274_5751_db05_5448b1a769b9["isIdOrNameUsed()"]
  a43ec24c_7afb_47c4_0951_89905012df7f -->|method| 1ddcaaa6_a274_5751_db05_5448b1a769b9
  568e9c36_44d8_d092_103e_197bdf559e4e["isIdUsed()"]
  a43ec24c_7afb_47c4_0951_89905012df7f -->|method| 568e9c36_44d8_d092_103e_197bdf559e4e
  0904d9e4_2b2d_5bd0_b241_5d479a5f6271["count()"]
  a43ec24c_7afb_47c4_0951_89905012df7f -->|method| 0904d9e4_2b2d_5bd0_b241_5d479a5f6271

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Optimization/DeadCodeElimination.ts lines 72–112

class State {
  env: Environment;
  named: Set<string> = new Set();
  identifiers: Set<IdentifierId> = new Set();

  constructor(env: Environment) {
    this.env = env;
  }

  // Mark the identifier as being referenced (not dead code)
  reference(identifier: Identifier): void {
    this.identifiers.add(identifier.id);
    if (identifier.name !== null) {
      this.named.add(identifier.name.value);
    }
  }

  /*
   * Check if any version of the given identifier is used somewhere.
   * This checks both for usage of this specific identifer id (ssa id)
   * and (for named identifiers) for any usages of that identifier name.
   */
  isIdOrNameUsed(identifier: Identifier): boolean {
    return (
      this.identifiers.has(identifier.id) ||
      (identifier.name !== null && this.named.has(identifier.name.value))
    );
  }

  /*
   * Like `used()`, but only checks for usages of this specific identifier id
   * (ssa id).
   */
  isIdUsed(identifier: Identifier): boolean {
    return this.identifiers.has(identifier.id);
  }

  get count(): number {
    return this.identifiers.size;
  }
}

Domain

Frequently Asked Questions

What is the State class?
State is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/DeadCodeElimination.ts.
Where is State defined?
State is defined in compiler/packages/babel-plugin-react-compiler/src/Optimization/DeadCodeElimination.ts at line 72.

Analyze Your Own Codebase

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

Try Supermodel Free