Home / Function/ suppressionsToCompilerError() — react Function Reference

suppressionsToCompilerError() — react Function Reference

Architecture documentation for the suppressionsToCompilerError() function in Suppression.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd["suppressionsToCompilerError()"]
  f3160d78_61c2_0ad9_2d19_6daf9a63b386["Suppression.ts"]
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd -->|defined in| f3160d78_61c2_0ad9_2d19_6daf9a63b386
  b463b9d1_ce95_79dd_d7b2_7be04016ee66["tryCompileFunction()"]
  b463b9d1_ce95_79dd_d7b2_7be04016ee66 -->|calls| d31deb45_fb36_194b_4bb5_e81a98b6c9bd
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  02303def_636f_c5b3_a751_1cf138fcea69["pushDiagnostic()"]
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd -->|calls| 02303def_636f_c5b3_a751_1cf138fcea69
  ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"]
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd -->|calls| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf
  1a2b7047_24c8_62d6_b328_5f07307d27ab["withDetails()"]
  d31deb45_fb36_194b_4bb5_e81a98b6c9bd -->|calls| 1a2b7047_24c8_62d6_b328_5f07307d27ab
  style d31deb45_fb36_194b_4bb5_e81a98b6c9bd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Suppression.ts lines 161–218

export function suppressionsToCompilerError(
  suppressionRanges: Array<SuppressionRange>,
): CompilerError {
  CompilerError.invariant(suppressionRanges.length !== 0, {
    reason: `Expected at least suppression comment source range`,
    loc: GeneratedSource,
  });
  const error = new CompilerError();
  for (const suppressionRange of suppressionRanges) {
    if (
      suppressionRange.disableComment.start == null ||
      suppressionRange.disableComment.end == null
    ) {
      continue;
    }
    let reason, suggestion;
    switch (suppressionRange.source) {
      case 'Eslint':
        reason =
          'React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled';
        suggestion =
          'Remove the ESLint suppression and address the React error';
        break;
      case 'Flow':
        reason =
          'React Compiler has skipped optimizing this component because one or more React rule violations were reported by Flow';
        suggestion = 'Remove the Flow suppression and address the React error';
        break;
      default:
        assertExhaustive(
          suppressionRange.source,
          'Unhandled suppression source',
        );
    }
    error.pushDiagnostic(
      CompilerDiagnostic.create({
        reason: reason,
        description: `React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. Found suppression \`${suppressionRange.disableComment.value.trim()}\``,
        category: ErrorCategory.Suppression,
        suggestions: [
          {
            description: suggestion,
            range: [
              suppressionRange.disableComment.start,
              suppressionRange.disableComment.end,
            ],
            op: CompilerSuggestionOperation.Remove,
          },
        ],
      }).withDetails({
        kind: 'error',
        loc: suppressionRange.disableComment.loc ?? null,
        message: 'Found React rule suppression',
      }),
    );
  }
  return error;
}

Domain

Subdomains

Frequently Asked Questions

What does suppressionsToCompilerError() do?
suppressionsToCompilerError() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Suppression.ts.
Where is suppressionsToCompilerError() defined?
suppressionsToCompilerError() is defined in compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Suppression.ts at line 161.
What does suppressionsToCompilerError() call?
suppressionsToCompilerError() calls 5 function(s): assertExhaustive, create, invariant, pushDiagnostic, withDetails.
What calls suppressionsToCompilerError()?
suppressionsToCompilerError() is called by 1 function(s): tryCompileFunction.

Analyze Your Own Codebase

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

Try Supermodel Free