Home / File/ DeriveMinimalDependenciesHIR.ts — react Source File

DeriveMinimalDependenciesHIR.ts — react Source File

Architecture documentation for DeriveMinimalDependenciesHIR.ts, a typescript file in the react codebase. 5 imports, 2 dependents.

File typescript MIRInfrastructure HIR 5 imports 2 dependents 6 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  686094a4_f90a_6b2e_949a_aa03f03b5c66["DeriveMinimalDependenciesHIR.ts"]
  e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"]
  686094a4_f90a_6b2e_949a_aa03f03b5c66 --> e96f281e_f381_272d_2359_3e6a091c9a1d
  e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"]
  686094a4_f90a_6b2e_949a_aa03f03b5c66 --> e51fd0d2_bb38_cc97_7763_efe37f300a47
  0423f759_97e0_9101_4634_ed555abc5ca9["index.ts"]
  686094a4_f90a_6b2e_949a_aa03f03b5c66 --> 0423f759_97e0_9101_4634_ed555abc5ca9
  6976a9ee_9d8e_4f16_3016_495f39aff2fd["PrintHIR.ts"]
  686094a4_f90a_6b2e_949a_aa03f03b5c66 --> 6976a9ee_9d8e_4f16_3016_495f39aff2fd
  e7a01d7c_c128_be66_a07d_007952a380da["printIdentifier"]
  686094a4_f90a_6b2e_949a_aa03f03b5c66 --> e7a01d7c_c128_be66_a07d_007952a380da
  76832af2_c0a7_f31c_e448_af5664da4b88["PropagateScopeDependenciesHIR.ts"]
  76832af2_c0a7_f31c_e448_af5664da4b88 --> 686094a4_f90a_6b2e_949a_aa03f03b5c66
  3393f920_76eb_7dd5_b95f_ab92de6cecce["InferEffectDependencies.ts"]
  3393f920_76eb_7dd5_b95f_ab92de6cecce --> 686094a4_f90a_6b2e_949a_aa03f03b5c66
  style 686094a4_f90a_6b2e_949a_aa03f03b5c66 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 {CompilerError} from '../CompilerError';
import {
  DependencyPathEntry,
  GeneratedSource,
  Identifier,
  PropertyLiteral,
  ReactiveScopeDependency,
} from '../HIR';
import {printIdentifier} from '../HIR/PrintHIR';

/**
 * Simpler fork of DeriveMinimalDependencies, see PropagateScopeDependenciesHIR
 * for detailed explanation.
 */
export class ReactiveScopeDependencyTreeHIR {
  /**
   * Paths from which we can hoist PropertyLoads. If an `identifier`,
   * `identifier.path`, or `identifier?.path` is in this map, it is safe to
   * evaluate (non-optional) PropertyLoads from.
   */
  #hoistableObjects: Map<Identifier, HoistableNode & {reactive: boolean}> =
    new Map();
  #deps: Map<Identifier, DependencyNode & {reactive: boolean}> = new Map();

  /**
   * @param hoistableObjects a set of paths from which we can safely evaluate
   * PropertyLoads. Note that we expect these to not contain duplicates (e.g.
   * both `a?.b` and `a.b`) only because CollectHoistablePropertyLoads merges
   * duplicates when traversing the CFG.
   */
  constructor(hoistableObjects: Iterable<ReactiveScopeDependency>) {
    for (const {path, identifier, reactive} of hoistableObjects) {
      let currNode = ReactiveScopeDependencyTreeHIR.#getOrCreateRoot(
        identifier,
        reactive,
        this.#hoistableObjects,
        path.length > 0 && path[0].optional ? 'Optional' : 'NonNull',
      );

      for (let i = 0; i < path.length; i++) {
        const prevAccessType = currNode.properties.get(
          path[i].property,
        )?.accessType;
        const accessType =
          i + 1 < path.length && path[i + 1].optional ? 'Optional' : 'NonNull';
        CompilerError.invariant(
          prevAccessType == null || prevAccessType === accessType,
          {
            reason: 'Conflicting access types',
            loc: GeneratedSource,
          },
        );
        let nextNode = currNode.properties.get(path[i].property);
// ... (318 more lines)

Subdomains

Frequently Asked Questions

What does DeriveMinimalDependenciesHIR.ts do?
DeriveMinimalDependenciesHIR.ts is a source file in the react codebase, written in typescript. It belongs to the MIRInfrastructure domain, HIR subdomain.
What functions are defined in DeriveMinimalDependenciesHIR.ts?
DeriveMinimalDependenciesHIR.ts defines 6 function(s): collectMinimalDependenciesInSubtree, isDependency, isOptional, makeOrMergeProperty, merge, printSubtree.
What does DeriveMinimalDependenciesHIR.ts depend on?
DeriveMinimalDependenciesHIR.ts imports 5 module(s): CompilerError, CompilerError.ts, PrintHIR.ts, index.ts, printIdentifier.
What files import DeriveMinimalDependenciesHIR.ts?
DeriveMinimalDependenciesHIR.ts is imported by 2 file(s): InferEffectDependencies.ts, PropagateScopeDependenciesHIR.ts.
Where is DeriveMinimalDependenciesHIR.ts in the architecture?
DeriveMinimalDependenciesHIR.ts is located at compiler/packages/babel-plugin-react-compiler/src/HIR/DeriveMinimalDependenciesHIR.ts (domain: MIRInfrastructure, subdomain: HIR, directory: compiler/packages/babel-plugin-react-compiler/src/HIR).

Analyze Your Own Codebase

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

Try Supermodel Free