Home / Function/ validateDependencies() — react Function Reference

validateDependencies() — react Function Reference

Architecture documentation for the validateDependencies() function in ValidateExhaustiveDependencies.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  b42a89d6_3831_7611_0620_5df011ebe6ba["validateDependencies()"]
  6bd4cea3_f214_b2ef_722d_79dc0c7aa5d2["ValidateExhaustiveDependencies.ts"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|defined in| 6bd4cea3_f214_b2ef_722d_79dc0c7aa5d2
  ab1c1404_144d_7383_ba84_656d601467ca["validateExhaustiveDependencies()"]
  ab1c1404_144d_7383_ba84_656d601467ca -->|calls| b42a89d6_3831_7611_0620_5df011ebe6ba
  54d623b1_ac7c_dd74_8b03_de9e93a36587["invariant()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 54d623b1_ac7c_dd74_8b03_de9e93a36587
  8e8a61aa_e576_d019_dc7e_b32d5e42e7f0["retainWhere()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 8e8a61aa_e576_d019_dc7e_b32d5e42e7f0
  8d9beda0_4a74_6daf_e797_b6ba44bfc11a["isEqualTemporary()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 8d9beda0_4a74_6daf_e797_b6ba44bfc11a
  6dd3b317_40c0_299f_aba0_a14aed85c55f["printManualMemoDependency()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 6dd3b317_40c0_299f_aba0_a14aed85c55f
  5c9af03e_3575_cadc_ba97_5ef443ad56ef["printInferredDependency()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 5c9af03e_3575_cadc_ba97_5ef443ad56ef
  5f694d00_db22_ca76_929e_f1ed21313ce8["push()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 5f694d00_db22_ca76_929e_f1ed21313ce8
  60c6f006_c4d9_de56_041a_d71a8fb3ad7b["isOptionalDependency()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 60c6f006_c4d9_de56_041a_d71a8fb3ad7b
  ddb6839c_af0a_d059_ec10_3c2b4af91b52["createDiagnostic()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| ddb6839c_af0a_d059_ec10_3c2b4af91b52
  74a94732_eaa0_4ef6_8347_8518c71b78b8["withDetails()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 74a94732_eaa0_4ef6_8347_8518c71b78b8
  28a3684c_b5a5_8d21_af43_08e51dda5f53["map()"]
  b42a89d6_3831_7611_0620_5df011ebe6ba -->|calls| 28a3684c_b5a5_8d21_af43_08e51dda5f53
  style b42a89d6_3831_7611_0620_5df011ebe6ba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateExhaustiveDependencies.ts lines 221–495

function validateDependencies(
  inferred: Array<InferredDependency>,
  manualDependencies: Array<ManualMemoDependency>,
  reactive: Set<IdentifierId>,
  manualMemoLoc: SourceLocation | null,
  category:
    | ErrorCategory.MemoDependencies
    | ErrorCategory.EffectExhaustiveDependencies,
  exhaustiveDepsReportMode: 'all' | 'missing-only' | 'extra-only',
): CompilerDiagnostic | null {
  // Sort dependencies by name and path, with shorter/non-optional paths first
  inferred.sort((a, b) => {
    if (a.kind === 'Global' && b.kind == 'Global') {
      return a.binding.name.localeCompare(b.binding.name);
    } else if (a.kind == 'Local' && b.kind == 'Local') {
      CompilerError.invariant(
        a.identifier.name != null &&
          a.identifier.name.kind === 'named' &&
          b.identifier.name != null &&
          b.identifier.name.kind === 'named',
        {
          reason: 'Expected dependencies to be named variables',
          loc: a.loc,
        },
      );
      if (a.identifier.id !== b.identifier.id) {
        return a.identifier.name.value.localeCompare(b.identifier.name.value);
      }
      if (a.path.length !== b.path.length) {
        // if a's path is shorter this returns a negative, sorting a first
        return a.path.length - b.path.length;
      }
      for (let i = 0; i < a.path.length; i++) {
        const aProperty = a.path[i];
        const bProperty = b.path[i];
        const aOptional = aProperty.optional ? 0 : 1;
        const bOptional = bProperty.optional ? 0 : 1;
        if (aOptional !== bOptional) {
          // sort non-optionals first
          return aOptional - bOptional;
        } else if (aProperty.property !== bProperty.property) {
          return String(aProperty.property).localeCompare(
            String(bProperty.property),
          );
        }
      }
      return 0;
    } else {
      const aName =
        a.kind === 'Global' ? a.binding.name : a.identifier.name?.value;
      const bName =
        b.kind === 'Global' ? b.binding.name : b.identifier.name?.value;
      if (aName != null && bName != null) {
        return aName.localeCompare(bName);
      }
      return 0;
    }
  });
  // remove redundant inferred dependencies
  retainWhere(inferred, (dep, ix) => {
    const match = inferred.findIndex(prevDep => {
      return (
        isEqualTemporary(prevDep, dep) ||
        (prevDep.kind === 'Local' &&
          dep.kind === 'Local' &&
          prevDep.identifier.id === dep.identifier.id &&
          isSubPath(prevDep.path, dep.path))
      );
    });
    // only retain entries that don't have a prior match
    return match === -1 || match >= ix;
  });
  // Validate that all manual dependencies belong there
  if (DEBUG) {
    console.log('manual');
    console.log(
      manualDependencies
        .map(x => '  ' + printManualMemoDependency(x))
        .join('\n'),
    );
    console.log('inferred');

Domain

Subdomains

Frequently Asked Questions

What does validateDependencies() do?
validateDependencies() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateExhaustiveDependencies.ts.
Where is validateDependencies() defined?
validateDependencies() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateExhaustiveDependencies.ts at line 221.
What does validateDependencies() call?
validateDependencies() calls 10 function(s): createDiagnostic, invariant, isEqualTemporary, isOptionalDependency, map, printInferredDependency, printManualMemoDependency, push, and 2 more.
What calls validateDependencies()?
validateDependencies() is called by 1 function(s): validateExhaustiveDependencies.

Analyze Your Own Codebase

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

Try Supermodel Free