Home / Function/ invariant() — react Function Reference

invariant() — react Function Reference

Architecture documentation for the invariant() function in CompilerError.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"]
  041ca752_10c1_3cda_1f5c_02f44a01310e -->|defined in| e51fd0d2_bb38_cc97_7763_efe37f300a47
  95e65dcd_d1d7_5d80_ec47_fc32c898209f["getRuleForCategory()"]
  95e65dcd_d1d7_5d80_ec47_fc32c898209f -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  7fdb3fec_c4d5_7678_ad85_e8976e3417ad["insertAdditionalFunctionDeclaration()"]
  7fdb3fec_c4d5_7678_ad85_e8976e3417ad -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  77b776cd_a7c8_1d29_ba32_e5a39fa85dd9["insertGatedFunctionDeclaration()"]
  77b776cd_a7c8_1d29_ba32_e5a39fa85dd9 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  e19f561e_cb2d_6161_2ab6_1c6533ed4958["addImportsToProgram()"]
  e19f561e_cb2d_6161_2ab6_1c6533ed4958 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  ade5f434_a213_5611_b4fa_0fdd254474e1["insertNewOutlinedFunctionNode()"]
  ade5f434_a213_5611_b4fa_0fdd254474e1 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  1c9af54b_10e9_8985_e772_1f517e46c560["compileProgram()"]
  1c9af54b_10e9_8985_e772_1f517e46c560 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  78d6080e_8c56_4f2c_6894_efdb15a87a5c["getReactCompilerRuntimeModule()"]
  78d6080e_8c56_4f2c_6894_efdb15a87a5c -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd["suppressionsToCompilerError()"]
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  a4f6bed9_c265_4ac2_4912_8b61d4121efb["validateImportSpecifier()"]
  a4f6bed9_c265_4ac2_4912_8b61d4121efb -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  7ba64864_37b8_333a_82c1_22a93c4b5c66["validateNamespacedImport()"]
  7ba64864_37b8_333a_82c1_22a93c4b5c66 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  505f2e0b_d43c_5972_8865_373d0dd08a6a["assertConsistentIdentifiers()"]
  505f2e0b_d43c_5972_8865_373d0dd08a6a -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  2d5af54d_63a3_470d_02e8_a6c9fbb9f052["validate()"]
  2d5af54d_63a3_470d_02e8_a6c9fbb9f052 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  ce70693f_ea04_ec00_ebf7_471842f5db19["assertTerminalSuccessorsExist()"]
  ce70693f_ea04_ec00_ebf7_471842f5db19 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  style 041ca752_10c1_3cda_1f5c_02f44a01310e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts lines 307–331

  static invariant(
    condition: unknown,
    options: {
      reason: CompilerDiagnosticOptions['reason'];
      description?: CompilerDiagnosticOptions['description'];
      message?: string | null;
      loc: SourceLocation;
    },
  ): asserts condition {
    if (!condition) {
      const errors = new CompilerError();
      errors.pushDiagnostic(
        CompilerDiagnostic.create({
          reason: options.reason,
          description: options.description ?? null,
          category: ErrorCategory.Invariant,
        }).withDetails({
          kind: 'error',
          loc: options.loc,
          message: options.message ?? options.reason,
        }),
      );
      throw errors;
    }
  }

Domain

Subdomains

Called By

Frequently Asked Questions

What does invariant() do?
invariant() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts.
Where is invariant() defined?
invariant() is defined in compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts at line 307.
What does invariant() call?
invariant() calls 3 function(s): create, pushDiagnostic, withDetails.
What calls invariant()?
invariant() is called by 137 function(s): _shrink, addImportsToProgram, addShape, appendAlias, applyEffect, applySignature, assertConsistentIdentifiers, assertNonNull, and 129 more.

Analyze Your Own Codebase

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

Try Supermodel Free