Skip to content

Commit 064609a

Browse files
committed
[compiler] Deprecate CompilerErrorDetail
Now that we have a new CompilerDiagnostic type (which the CompilerError aggregate can hold), the old CompilerErrorDetail type can be marked as deprecated. Eventually we should migrate everything to the new CompilerDiagnostic type.
1 parent 151808c commit 064609a

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export type CompilerSuggestion =
7878
description: string;
7979
};
8080

81+
/**
82+
* @deprecated use {@link CompilerDiagnosticOptions} instead
83+
*/
8184
export type CompilerErrorDetailOptions = {
8285
category: ErrorCategory;
8386
reason: string;
@@ -196,9 +199,11 @@ export class CompilerDiagnostic {
196199
}
197200
}
198201

199-
/*
202+
/**
200203
* Each bailout or invariant in HIR lowering creates an {@link CompilerErrorDetail}, which is then
201204
* aggregated into a single {@link CompilerError} later.
205+
*
206+
* @deprecated use {@link CompilerDiagnostic} instead
202207
*/
203208
export class CompilerErrorDetail {
204209
options: CompilerErrorDetailOptions;
@@ -268,13 +273,18 @@ export class CompilerErrorDetail {
268273
}
269274
}
270275

276+
/**
277+
* An aggregate of {@link CompilerDiagnostic}. This allows us to aggregate all issues found by the
278+
* compiler into a single error before we throw. Where possible, prefer to push diagnostics into
279+
* the error aggregate instead of throwing immediately.
280+
*/
271281
export class CompilerError extends Error {
272282
details: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
273283
printedMessage: string | null = null;
274284

275285
static invariant(
276286
condition: unknown,
277-
options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
287+
options: Omit<CompilerErrorDetailOptions, 'category'>,
278288
): asserts condition {
279289
if (!condition) {
280290
const errors = new CompilerError();
@@ -295,7 +305,7 @@ export class CompilerError extends Error {
295305
}
296306

297307
static throwTodo(
298-
options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
308+
options: Omit<CompilerErrorDetailOptions, 'category'>,
299309
): never {
300310
const errors = new CompilerError();
301311
errors.pushErrorDetail(
@@ -308,7 +318,7 @@ export class CompilerError extends Error {
308318
}
309319

310320
static throwInvalidJS(
311-
options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
321+
options: Omit<CompilerErrorDetailOptions, 'category'>,
312322
): never {
313323
const errors = new CompilerError();
314324
errors.pushErrorDetail(
@@ -320,16 +330,14 @@ export class CompilerError extends Error {
320330
throw errors;
321331
}
322332

323-
static throwInvalidReact(
324-
options: Omit<CompilerErrorDetailOptions, 'severity'>,
325-
): never {
333+
static throwInvalidReact(options: CompilerErrorDetailOptions): never {
326334
const errors = new CompilerError();
327335
errors.pushErrorDetail(new CompilerErrorDetail(options));
328336
throw errors;
329337
}
330338

331339
static throwInvalidConfig(
332-
options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
340+
options: Omit<CompilerErrorDetailOptions, 'category'>,
333341
): never {
334342
const errors = new CompilerError();
335343
errors.pushErrorDetail(
@@ -397,6 +405,9 @@ export class CompilerError extends Error {
397405
this.details.push(diagnostic);
398406
}
399407

408+
/**
409+
* @deprecated use {@link pushDiagnostic} instead
410+
*/
400411
push(options: CompilerErrorDetailOptions): CompilerErrorDetail {
401412
const detail = new CompilerErrorDetail({
402413
category: options.category,
@@ -408,6 +419,9 @@ export class CompilerError extends Error {
408419
return this.pushErrorDetail(detail);
409420
}
410421

422+
/**
423+
* @deprecated use {@link pushDiagnostic} instead
424+
*/
411425
pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail {
412426
this.details.push(detail);
413427
return detail;

0 commit comments

Comments
 (0)