@@ -78,6 +78,9 @@ export type CompilerSuggestion =
78
78
description : string ;
79
79
} ;
80
80
81
+ /**
82
+ * @deprecated use {@link CompilerDiagnosticOptions} instead
83
+ */
81
84
export type CompilerErrorDetailOptions = {
82
85
category : ErrorCategory ;
83
86
reason : string ;
@@ -196,9 +199,11 @@ export class CompilerDiagnostic {
196
199
}
197
200
}
198
201
199
- /*
202
+ /**
200
203
* Each bailout or invariant in HIR lowering creates an {@link CompilerErrorDetail}, which is then
201
204
* aggregated into a single {@link CompilerError} later.
205
+ *
206
+ * @deprecated use {@link CompilerDiagnostic} instead
202
207
*/
203
208
export class CompilerErrorDetail {
204
209
options : CompilerErrorDetailOptions ;
@@ -268,13 +273,18 @@ export class CompilerErrorDetail {
268
273
}
269
274
}
270
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
+ */
271
281
export class CompilerError extends Error {
272
282
details : Array < CompilerErrorDetail | CompilerDiagnostic > = [ ] ;
273
283
printedMessage : string | null = null ;
274
284
275
285
static invariant (
276
286
condition : unknown ,
277
- options : Omit < CompilerErrorDetailOptions , 'severity' | ' category'> ,
287
+ options : Omit < CompilerErrorDetailOptions , 'category' > ,
278
288
) : asserts condition {
279
289
if ( ! condition ) {
280
290
const errors = new CompilerError ( ) ;
@@ -295,7 +305,7 @@ export class CompilerError extends Error {
295
305
}
296
306
297
307
static throwTodo (
298
- options : Omit < CompilerErrorDetailOptions , 'severity' | ' category'> ,
308
+ options : Omit < CompilerErrorDetailOptions , 'category' > ,
299
309
) : never {
300
310
const errors = new CompilerError ( ) ;
301
311
errors . pushErrorDetail (
@@ -308,7 +318,7 @@ export class CompilerError extends Error {
308
318
}
309
319
310
320
static throwInvalidJS (
311
- options : Omit < CompilerErrorDetailOptions , 'severity' | ' category'> ,
321
+ options : Omit < CompilerErrorDetailOptions , 'category' > ,
312
322
) : never {
313
323
const errors = new CompilerError ( ) ;
314
324
errors . pushErrorDetail (
@@ -320,16 +330,14 @@ export class CompilerError extends Error {
320
330
throw errors ;
321
331
}
322
332
323
- static throwInvalidReact (
324
- options : Omit < CompilerErrorDetailOptions , 'severity' > ,
325
- ) : never {
333
+ static throwInvalidReact ( options : CompilerErrorDetailOptions ) : never {
326
334
const errors = new CompilerError ( ) ;
327
335
errors . pushErrorDetail ( new CompilerErrorDetail ( options ) ) ;
328
336
throw errors ;
329
337
}
330
338
331
339
static throwInvalidConfig (
332
- options : Omit < CompilerErrorDetailOptions , 'severity' | ' category'> ,
340
+ options : Omit < CompilerErrorDetailOptions , 'category' > ,
333
341
) : never {
334
342
const errors = new CompilerError ( ) ;
335
343
errors . pushErrorDetail (
@@ -397,6 +405,9 @@ export class CompilerError extends Error {
397
405
this . details . push ( diagnostic ) ;
398
406
}
399
407
408
+ /**
409
+ * @deprecated use {@link pushDiagnostic} instead
410
+ */
400
411
push ( options : CompilerErrorDetailOptions ) : CompilerErrorDetail {
401
412
const detail = new CompilerErrorDetail ( {
402
413
category : options . category ,
@@ -408,6 +419,9 @@ export class CompilerError extends Error {
408
419
return this . pushErrorDetail ( detail ) ;
409
420
}
410
421
422
+ /**
423
+ * @deprecated use {@link pushDiagnostic} instead
424
+ */
411
425
pushErrorDetail ( detail : CompilerErrorDetail ) : CompilerErrorDetail {
412
426
this . details . push ( detail ) ;
413
427
return detail ;
0 commit comments