Home / File/ CollectReactiveIdentifiers.ts — react Source File

CollectReactiveIdentifiers.ts — react Source File

Architecture documentation for CollectReactiveIdentifiers.ts, a typescript file in the react codebase. 12 imports, 1 dependents.

File typescript BabelCompiler Validation 12 imports 1 dependents 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  4021b024_bc48_5236_4c88_793e93a1cbe0["CollectReactiveIdentifiers.ts"]
  18a78965_f593_105b_e5e8_07001321c2ec["HIR.ts"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 18a78965_f593_105b_e5e8_07001321c2ec
  e3a6ca26_1f1a_c7f8_fbf3_804737192775["IdentifierId"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> e3a6ca26_1f1a_c7f8_fbf3_804737192775
  23767d65_9554_fcd2_f2aa_7de7634389f9["InstructionId"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 23767d65_9554_fcd2_f2aa_7de7634389f9
  c7aaa235_c19e_3530_31c2_911f38eed3e0["Place"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> c7aaa235_c19e_3530_31c2_911f38eed3e0
  02f69dfe_af02_6deb_8891_1b0229142fd1["PrunedReactiveScopeBlock"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 02f69dfe_af02_6deb_8891_1b0229142fd1
  c0555545_1ea3_9d37_62ad_521eafe2daa8["ReactiveFunction"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> c0555545_1ea3_9d37_62ad_521eafe2daa8
  85046cfe_6315_ef8a_3c37_15f5a0fd2b46["isPrimitiveType"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 85046cfe_6315_ef8a_3c37_15f5a0fd2b46
  6e7c932f_5e2d_52c4_1399_ff365b3858b6["isUseRefType"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 6e7c932f_5e2d_52c4_1399_ff365b3858b6
  bd003dbd_e691_524b_0cf4_50e080ffea94["Identifier"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> bd003dbd_e691_524b_0cf4_50e080ffea94
  21609915_b03a_fd75_b58a_4cb86ef9315b["visitors.ts"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 21609915_b03a_fd75_b58a_4cb86ef9315b
  171a5d22_bb6b_1c99_05a4_6ad897438a35["ReactiveFunctionVisitor"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 171a5d22_bb6b_1c99_05a4_6ad897438a35
  2435b5f8_41a6_0458_ba88_4479b965455f["visitReactiveFunction"]
  4021b024_bc48_5236_4c88_793e93a1cbe0 --> 2435b5f8_41a6_0458_ba88_4479b965455f
  48e6a237_50bb_99d9_4055_59aab6c5ede8["PruneNonReactiveDependencies.ts"]
  48e6a237_50bb_99d9_4055_59aab6c5ede8 --> 4021b024_bc48_5236_4c88_793e93a1cbe0
  style 4021b024_bc48_5236_4c88_793e93a1cbe0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import {
  IdentifierId,
  InstructionId,
  Place,
  PrunedReactiveScopeBlock,
  ReactiveFunction,
  isPrimitiveType,
  isUseRefType,
  Identifier,
} from '../HIR/HIR';
import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors';

class Visitor extends ReactiveFunctionVisitor<Set<IdentifierId>> {
  /*
   * Visitors don't visit lvalues as places by default, but we want to visit all places to
   * check for reactivity
   */
  override visitLValue(
    id: InstructionId,
    lvalue: Place,
    state: Set<IdentifierId>,
  ): void {
    this.visitPlace(id, lvalue, state);
  }

  /*
   * This visitor only infers data dependencies and does not account for control dependencies
   * where a variable may be assigned a different value based on some conditional, eg via two
   * different paths of an if statement.
   */
  override visitPlace(
    _id: InstructionId,
    place: Place,
    state: Set<IdentifierId>,
  ): void {
    if (place.reactive) {
      state.add(place.identifier.id);
    }
  }

  override visitPrunedScope(
    scopeBlock: PrunedReactiveScopeBlock,
    state: Set<IdentifierId>,
  ): void {
    this.traversePrunedScope(scopeBlock, state);

    for (const [id, decl] of scopeBlock.scope.declarations) {
      if (
        !isPrimitiveType(decl.identifier) &&
        !isStableRefType(decl.identifier, state)
      ) {
        state.add(id);
      }
    }
  }
}
function isStableRefType(
  identifier: Identifier,
  reactiveIdentifiers: Set<IdentifierId>,
): boolean {
  return isUseRefType(identifier) && !reactiveIdentifiers.has(identifier.id);
}
/*
 * Computes a set of identifiers which are reactive, using the analysis previously performed
 * in `InferReactivePlaces`.
 */
export function collectReactiveIdentifiers(
  fn: ReactiveFunction,
): Set<IdentifierId> {
  const visitor = new Visitor();
  const state = new Set<IdentifierId>();
  visitReactiveFunction(fn, visitor, state);

  return state;
}

Domain

Subdomains

Classes

Frequently Asked Questions

What does CollectReactiveIdentifiers.ts do?
CollectReactiveIdentifiers.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in CollectReactiveIdentifiers.ts?
CollectReactiveIdentifiers.ts defines 2 function(s): collectReactiveIdentifiers, isStableRefType.
What does CollectReactiveIdentifiers.ts depend on?
CollectReactiveIdentifiers.ts imports 12 module(s): HIR.ts, Identifier, IdentifierId, InstructionId, Place, PrunedReactiveScopeBlock, ReactiveFunction, ReactiveFunctionVisitor, and 4 more.
What files import CollectReactiveIdentifiers.ts?
CollectReactiveIdentifiers.ts is imported by 1 file(s): PruneNonReactiveDependencies.ts.
Where is CollectReactiveIdentifiers.ts in the architecture?
CollectReactiveIdentifiers.ts is located at compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CollectReactiveIdentifiers.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes).

Analyze Your Own Codebase

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

Try Supermodel Free