Skip to content

Commit ea7fe29

Browse files
committed
[compiler] Filter out disabled errors from being reported
This PR stops error details of severity `ErrorSeverity.Off` from being reported.
1 parent 7985a81 commit ea7fe29

File tree

9 files changed

+30
-29
lines changed

9 files changed

+30
-29
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export class CompilerErrorDetail {
279279
*/
280280
export class CompilerError extends Error {
281281
details: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
282+
disabledDetails: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
282283
printedMessage: string | null = null;
283284

284285
static invariant(
@@ -359,6 +360,7 @@ export class CompilerError extends Error {
359360
super(...args);
360361
this.name = 'ReactCompilerError';
361362
this.details = [];
363+
this.disabledDetails = [];
362364
}
363365

364366
override get message(): string {
@@ -399,10 +401,15 @@ export class CompilerError extends Error {
399401

400402
merge(other: CompilerError): void {
401403
this.details.push(...other.details);
404+
this.disabledDetails.push(...other.disabledDetails);
402405
}
403406

404407
pushDiagnostic(diagnostic: CompilerDiagnostic): void {
405-
this.details.push(diagnostic);
408+
if (diagnostic.severity === ErrorSeverity.Off) {
409+
this.disabledDetails.push(diagnostic);
410+
} else {
411+
this.details.push(diagnostic);
412+
}
406413
}
407414

408415
/**
@@ -423,43 +430,40 @@ export class CompilerError extends Error {
423430
* @deprecated use {@link pushDiagnostic} instead
424431
*/
425432
pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail {
426-
this.details.push(detail);
433+
if (detail.severity === ErrorSeverity.Off) {
434+
this.disabledDetails.push(detail);
435+
} else {
436+
this.details.push(detail);
437+
}
427438
return detail;
428439
}
429440

430-
hasErrors(): boolean {
441+
hasAnyErrors(): boolean {
431442
return this.details.length > 0;
432443
}
433444

434445
asResult(): Result<void, CompilerError> {
435-
return this.hasErrors() ? Err(this) : Ok(undefined);
446+
return this.hasAnyErrors() ? Err(this) : Ok(undefined);
436447
}
437448

438449
/**
439450
* Returns true if any of the error details are of severity Error.
440451
*/
441-
isError(): boolean {
442-
let res = false;
452+
hasErrors(): boolean {
443453
for (const detail of this.details) {
444-
if (detail.severity === ErrorSeverity.Off) {
445-
return false;
446-
}
447454
if (detail.severity === ErrorSeverity.Error) {
448-
res = true;
455+
return true;
449456
}
450457
}
451-
return res;
458+
return false;
452459
}
453460

454461
/**
455462
* Returns true if there are no Errors and there is at least one Warning.
456463
*/
457-
isWarning(): boolean {
464+
hasWarning(): boolean {
458465
let res = false;
459466
for (const detail of this.details) {
460-
if (detail.severity === ErrorSeverity.Off) {
461-
return false;
462-
}
463467
if (detail.severity === ErrorSeverity.Error) {
464468
return false;
465469
}
@@ -470,12 +474,9 @@ export class CompilerError extends Error {
470474
return res;
471475
}
472476

473-
isHint(): boolean {
477+
hasHints(): boolean {
474478
let res = false;
475479
for (const detail of this.details) {
476-
if (detail.severity === ErrorSeverity.Off) {
477-
return false;
478-
}
479480
if (detail.severity === ErrorSeverity.Error) {
480481
return false;
481482
}

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function validateRestrictedImports(
4646
}
4747
},
4848
});
49-
if (error.hasErrors()) {
49+
if (error.hasAnyErrors()) {
5050
return error;
5151
} else {
5252
return null;

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function findDirectivesDynamicGating(
111111
}
112112
}
113113
}
114-
if (errors.hasErrors()) {
114+
if (errors.hasAnyErrors()) {
115115
return Err(errors);
116116
} else if (result.length > 1) {
117117
const error = new CompilerError();
@@ -139,7 +139,7 @@ function findDirectivesDynamicGating(
139139
}
140140

141141
function isError(err: unknown): boolean {
142-
return !(err instanceof CompilerError) || err.isError();
142+
return !(err instanceof CompilerError) || err.hasErrors();
143143
}
144144

145145
function isConfigError(err: unknown): boolean {

compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export function lower(
213213
);
214214
}
215215

216-
if (builder.errors.hasErrors()) {
216+
if (builder.errors.hasAnyErrors()) {
217217
return Err(builder.errors);
218218
}
219219

@@ -2667,7 +2667,7 @@ function lowerExpression(
26672667
* lowerIdentifierForAssignment should have already reported an error if it returned null,
26682668
* we check here just in case
26692669
*/
2670-
if (!builder.errors.hasErrors()) {
2670+
if (!builder.errors.hasAnyErrors()) {
26712671
builder.errors.push({
26722672
reason: `(BuildHIR::lowerExpression) Found an invalid UpdateExpression without a previously reported error`,
26732673
category: ErrorCategory.Invariant,

compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ export function inferMutationAliasingRanges(
568568
}
569569
}
570570

571-
if (errors.hasErrors() && !isFunctionExpression) {
571+
if (errors.hasAnyErrors() && !isFunctionExpression) {
572572
return Err(errors);
573573
}
574574
return Ok(functionEffects);

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ function codegenReactiveFunction(
372372
}
373373
}
374374

375-
if (cx.errors.hasErrors()) {
375+
if (cx.errors.hasAnyErrors()) {
376376
return Err(cx.errors);
377377
}
378378

compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ class Context {
698698
}
699699

700700
hasErrors(): boolean {
701-
return this.#errors.hasErrors();
701+
return this.#errors.hasAnyErrors();
702702
}
703703

704704
throwIfErrorsFound(): void {

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function validateNoDerivedComputationsInEffects(fn: HIRFunction): void {
104104
}
105105
}
106106
}
107-
if (errors.hasErrors()) {
107+
if (errors.hasAnyErrors()) {
108108
throw errors;
109109
}
110110
}

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccessInRender.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ function validateNoRefAccessInRenderImpl(
735735
}
736736
}
737737

738-
if (errors.hasErrors()) {
738+
if (errors.hasAnyErrors()) {
739739
return Err(errors);
740740
}
741741
}

0 commit comments

Comments
 (0)