Home / Class/ CompilerDiagnostic Class — react Architecture

CompilerDiagnostic Class — react Architecture

Architecture documentation for the CompilerDiagnostic class in CompilerError.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042["CompilerDiagnostic"]
  e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|defined in| e96f281e_f381_272d_2359_3e6a091c9a1d
  06231490_89ad_eaa9_37c6_2f754c4cbd27["constructor()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| 06231490_89ad_eaa9_37c6_2f754c4cbd27
  ac13f5c1_be17_dd7a_6bd3_66d91c46aadf["create()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| ac13f5c1_be17_dd7a_6bd3_66d91c46aadf
  4b479bea_2dbf_3d32_0dd9_2f342a75068a["reason()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| 4b479bea_2dbf_3d32_0dd9_2f342a75068a
  ffa1d347_390b_c579_ce63_b76900adb426["description()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| ffa1d347_390b_c579_ce63_b76900adb426
  38825ab8_cd59_a6aa_cbf5_f80ea083ca1e["severity()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| 38825ab8_cd59_a6aa_cbf5_f80ea083ca1e
  d78d3d0e_ed6e_37f0_7608_42d739f2c0eb["suggestions()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| d78d3d0e_ed6e_37f0_7608_42d739f2c0eb
  4723a338_0782_b5c5_9651_a662c0e26e32["category()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| 4723a338_0782_b5c5_9651_a662c0e26e32
  1a2b7047_24c8_62d6_b328_5f07307d27ab["withDetails()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| 1a2b7047_24c8_62d6_b328_5f07307d27ab
  915eda22_ad87_20ae_ed69_dc0bfeb9fb8f["primaryLocation()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| 915eda22_ad87_20ae_ed69_dc0bfeb9fb8f
  e39dece3_8891_8533_6625_5397539eb098["printErrorMessage()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| e39dece3_8891_8533_6625_5397539eb098
  00c689b1_d881_800b_f1df_076ada6a2c75["toString()"]
  0fda7f86_b7a3_c1f2_f0d9_8d13eed4f042 -->|method| 00c689b1_d881_800b_f1df_076ada6a2c75

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts lines 122–221

export class CompilerDiagnostic {
  options: CompilerDiagnosticOptions;

  constructor(options: CompilerDiagnosticOptions) {
    this.options = options;
  }

  static create(
    options: Omit<CompilerDiagnosticOptions, 'details'>,
  ): CompilerDiagnostic {
    return new CompilerDiagnostic({...options, details: []});
  }

  get reason(): CompilerDiagnosticOptions['reason'] {
    return this.options.reason;
  }
  get description(): CompilerDiagnosticOptions['description'] {
    return this.options.description;
  }
  get severity(): ErrorSeverity {
    return getRuleForCategory(this.category).severity;
  }
  get suggestions(): CompilerDiagnosticOptions['suggestions'] {
    return this.options.suggestions;
  }
  get category(): ErrorCategory {
    return this.options.category;
  }

  withDetails(...details: Array<CompilerDiagnosticDetail>): CompilerDiagnostic {
    this.options.details.push(...details);
    return this;
  }

  primaryLocation(): SourceLocation | null {
    const firstErrorDetail = this.options.details.filter(
      d => d.kind === 'error',
    )[0];
    return firstErrorDetail != null && firstErrorDetail.kind === 'error'
      ? firstErrorDetail.loc
      : null;
  }

  printErrorMessage(source: string, options: PrintErrorMessageOptions): string {
    const buffer = [printErrorSummary(this.category, this.reason)];
    if (this.description != null) {
      buffer.push('\n\n', `${this.description}.`);
    }
    for (const detail of this.options.details) {
      switch (detail.kind) {
        case 'error': {
          const loc = detail.loc;
          if (loc == null || typeof loc === 'symbol') {
            continue;
          }
          let codeFrame: string;
          try {
            codeFrame = printCodeFrame(source, loc, detail.message ?? '');
          } catch (e) {
            codeFrame = detail.message ?? '';
          }
          buffer.push('\n\n');
          if (loc.filename != null) {
            const line = loc.start.line;
            const column = options.eslint
              ? loc.start.column + 1
              : loc.start.column;
            buffer.push(`${loc.filename}:${line}:${column}\n`);
          }
          buffer.push(codeFrame);
          break;
        }
        case 'hint': {
          buffer.push('\n\n');
          buffer.push(detail.message);
          break;
        }
        default: {
          assertExhaustive(
            detail,
            `Unexpected detail kind ${(detail as any).kind}`,

Domain

Frequently Asked Questions

What is the CompilerDiagnostic class?
CompilerDiagnostic is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts.
Where is CompilerDiagnostic defined?
CompilerDiagnostic is defined in compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts at line 122.

Analyze Your Own Codebase

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

Try Supermodel Free