@samitouri / QOS-React / commits / 1fef581e1a

[compiler] Deprecate CompilerErrorDetail (#34402)

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. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34402). * #34409 * #34404 * #34403 * __->__ #34402 * #34401

lauren committed Sep 6, 2025 at 12:41 UTC 1fef581e1abcdcbc4aa50a048f9473f85dcb4692
1 file changed +22 -8
compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts
+22 -8
@@ -78,6 +78,9 @@ export type CompilerSuggestion =
78 description: string;
79 };
80
81 +/**
82 + * @deprecated use {@link CompilerDiagnosticOptions} instead
83 + */
84 export type CompilerErrorDetailOptions = {
85 category: ErrorCategory;
86 reason: string;
@@ -196,9 +199,11 @@ export class CompilerDiagnostic {
199 }
200 }
201
199 -/*
202 +/**
203 * Each bailout or invariant in HIR lowering creates an {@link CompilerErrorDetail}, which is then
204 * aggregated into a single {@link CompilerError} later.
205 + *
206 + * @deprecated use {@link CompilerDiagnostic} instead
207 */
208 export class CompilerErrorDetail {
209 options: CompilerErrorDetailOptions;
@@ -268,13 +273,18 @@ export class CompilerErrorDetail {
273 }
274 }
275
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 + */
281 export class CompilerError extends Error {
282 details: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
283 printedMessage: string | null = null;
284
285 static invariant(
286 condition: unknown,
277 - options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
287 + options: Omit<CompilerErrorDetailOptions, 'category'>,
288 ): asserts condition {
289 if (!condition) {
290 const errors = new CompilerError();
@@ -295,7 +305,7 @@ export class CompilerError extends Error {
305 }
306
307 static throwTodo(
298 - options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
308 + options: Omit<CompilerErrorDetailOptions, 'category'>,
309 ): never {
310 const errors = new CompilerError();
311 errors.pushErrorDetail(
@@ -308,7 +318,7 @@ export class CompilerError extends Error {
318 }
319
320 static throwInvalidJS(
311 - options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
321 + options: Omit<CompilerErrorDetailOptions, 'category'>,
322 ): never {
323 const errors = new CompilerError();
324 errors.pushErrorDetail(
@@ -320,16 +330,14 @@ export class CompilerError extends Error {
330 throw errors;
331 }
332
323 - static throwInvalidReact(
324 - options: Omit<CompilerErrorDetailOptions, 'severity'>,
325 - ): never {
333 + static throwInvalidReact(options: CompilerErrorDetailOptions): never {
334 const errors = new CompilerError();
335 errors.pushErrorDetail(new CompilerErrorDetail(options));
336 throw errors;
337 }
338
339 static throwInvalidConfig(
332 - options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>,
340 + options: Omit<CompilerErrorDetailOptions, 'category'>,
341 ): never {
342 const errors = new CompilerError();
343 errors.pushErrorDetail(
@@ -397,6 +405,9 @@ export class CompilerError extends Error {
405 this.details.push(diagnostic);
406 }
407
408 + /**
409 + * @deprecated use {@link pushDiagnostic} instead
410 + */
411 push(options: CompilerErrorDetailOptions): CompilerErrorDetail {
412 const detail = new CompilerErrorDetail({
413 category: options.category,
@@ -408,6 +419,9 @@ export class CompilerError extends Error {
419 return this.pushErrorDetail(detail);
420 }
421
422 + /**
423 + * @deprecated use {@link pushDiagnostic} instead
424 + */
425 pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail {
426 this.details.push(detail);
427 return detail;