Home / File/ utils.ts — react Source File

utils.ts — react Source File

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

File typescript BabelCompiler Validation 1 imports 52 dependents 14 functions

Entity Profile

Dependency Diagram

graph LR
  eb9d33f9_42c1_205c_93e6_8e1365a31839["utils.ts"]
  ceff537f_04b5_ea96_fed3_19a0a7315bc6["traverse"]
  eb9d33f9_42c1_205c_93e6_8e1365a31839 --> ceff537f_04b5_ea96_fed3_19a0a7315bc6
  e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"]
  e96f281e_f381_272d_2359_3e6a091c9a1d --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  2a7e50cd_6171_085d_277c_6ced6ddd7148["Imports.ts"]
  2a7e50cd_6171_085d_277c_6ced6ddd7148 --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  4828f3cc_e6ac_9239_d7f7_c05f7f60419c["Options.ts"]
  4828f3cc_e6ac_9239_d7f7_c05f7f60419c --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  9aa4477d_960b_1ea1_b6d9_36076aaa70bd["Program.ts"]
  9aa4477d_960b_1ea1_b6d9_36076aaa70bd --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  4b6a2a26_9073_8d0b_6c3b_1cbce53fd41c["Reanimated.ts"]
  4b6a2a26_9073_8d0b_6c3b_1cbce53fd41c --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  f3160d78_61c2_0ad9_2d19_6daf9a63b386["Suppression.ts"]
  f3160d78_61c2_0ad9_2d19_6daf9a63b386 --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  93f3a2c7_a7ce_3c94_87fe_ee7d66d9b64b["ValidateNoUntransformedReferences.ts"]
  93f3a2c7_a7ce_3c94_87fe_ee7d66d9b64b --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  1fccc28d_09ce_cbd9_cc1b_5224a1b90f93["TypeUtils.ts"]
  1fccc28d_09ce_cbd9_cc1b_5224a1b90f93 --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  912702ee_f06e_77d9_d237_a41c50607cdf["Types.ts"]
  912702ee_f06e_77d9_d237_a41c50607cdf --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  e04c04d6_37a7_1dc3_7fae_7d07660d0af9["BuildHIR.ts"]
  e04c04d6_37a7_1dc3_7fae_7d07660d0af9 --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  53e05ed1_ffb1_8db2_8573_ef5a3fb99c72["CollectHoistablePropertyLoads.ts"]
  53e05ed1_ffb1_8db2_8573_ef5a3fb99c72 --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  1b971013_8a90_0d8d_1fcc_f31581cd66aa["Environment.ts"]
  1b971013_8a90_0d8d_1fcc_f31581cd66aa --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  a8683125_42ac_e9cd_3e85_739b8a5c0c4c["FindContextIdentifiers.ts"]
  a8683125_42ac_e9cd_3e85_739b8a5c0c4c --> eb9d33f9_42c1_205c_93e6_8e1365a31839
  style eb9d33f9_42c1_205c_93e6_8e1365a31839 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 {NodePath} from '@babel/traverse';

/*
 * Trigger an exhaustivess check in TypeScript and throw at runtime.
 *
 * Example:
 *
 * ```ts
 * enum ErrorCode = {
 *    E0001 = "E0001",
 *    E0002 = "E0002"
 * }
 *
 * switch (code) {
 *    case ErrorCode.E0001:
 *      // ...
 *    default:
 *      assertExhaustive(code, "Unhandled error code");
 * }
 * ```
 */
export function assertExhaustive(_: never, errorMsg: string): never {
  throw new Error(errorMsg);
}

// Modifies @param array in place, retaining only the items where the predicate returns true.
export function retainWhere<T>(
  array: Array<T>,
  predicate: (item: T, index: number) => boolean,
): void {
  let writeIndex = 0;
  for (let readIndex = 0; readIndex < array.length; readIndex++) {
    const item = array[readIndex];
    if (predicate(item, readIndex) === true) {
      array[writeIndex++] = item;
    }
  }
  array.length = writeIndex;
}

export function retainWhere_Set<T>(
  items: Set<T>,
  predicate: (item: T) => boolean,
): void {
  for (const item of items) {
    if (!predicate(item)) {
      items.delete(item);
    }
  }
}

export function getOrInsertWith<U, V>(
  m: Map<U, V>,
// ... (127 more lines)

Domain

Subdomains

Dependencies

  • traverse

Imported By

Frequently Asked Questions

What does utils.ts do?
utils.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 utils.ts?
utils.ts defines 14 function(s): Iterable_some, Set_equal, Set_filter, Set_intersect, Set_isSuperset, Set_union, assertExhaustive, getOrInsertDefault, getOrInsertWith, hasNode, and 4 more.
What does utils.ts depend on?
utils.ts imports 1 module(s): traverse.
What files import utils.ts?
utils.ts is imported by 52 file(s): AlignReactiveScopesToBlockScopesHIR.ts, AnalyseFunctions.ts, BuildHIR.ts, BuildReactiveFunction.ts, CodegenReactiveFunction.ts, CollectHoistablePropertyLoads.ts, CompilerError.ts, DeadCodeElimination.ts, and 44 more.
Where is utils.ts in the architecture?
utils.ts is located at compiler/packages/babel-plugin-react-compiler/src/Utils/utils.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/babel-plugin-react-compiler/src/Utils).

Analyze Your Own Codebase

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

Try Supermodel Free