@samitouri / QOS-React / commits / 78992521a8

[compiler] Filter out disabled errors from being reported (#34409)

This PR stops error details of severity `ErrorSeverity.Off` from being reported. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34409). * __->__ #34409 * #34404

lauren committed Sep 6, 2025 at 13:07 UTC 78992521a83325edec17a0dc0bb47092cc5accaa
9 files changed +30 -29
compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts
+20 -19
@@ -279,6 +279,7 @@ export class CompilerErrorDetail {
279 */
280 export class CompilerError extends Error {
281 details: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
282 + disabledDetails: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
283 printedMessage: string | null = null;
284
285 static invariant(
@@ -359,6 +360,7 @@ export class CompilerError extends Error {
360 super(...args);
361 this.name = 'ReactCompilerError';
362 this.details = [];
363 + this.disabledDetails = [];
364 }
365
366 override get message(): string {
@@ -399,10 +401,15 @@ export class CompilerError extends Error {
401
402 merge(other: CompilerError): void {
403 this.details.push(...other.details);
404 + this.disabledDetails.push(...other.disabledDetails);
405 }
406
407 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 + }
413 }
414
415 /**
@@ -423,43 +430,40 @@ export class CompilerError extends Error {
430 * @deprecated use {@link pushDiagnostic} instead
431 */
432 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 + }
438 return detail;
439 }
440
430 - hasErrors(): boolean {
441 + hasAnyErrors(): boolean {
442 return this.details.length > 0;
443 }
444
445 asResult(): Result<void, CompilerError> {
435 - return this.hasErrors() ? Err(this) : Ok(undefined);
446 + return this.hasAnyErrors() ? Err(this) : Ok(undefined);
447 }
448
449 /**
450 * Returns true if any of the error details are of severity Error.
451 */
441 - isError(): boolean {
442 - let res = false;
452 + hasErrors(): boolean {
453 for (const detail of this.details) {
444 - if (detail.severity === ErrorSeverity.Off) {
445 - return false;
446 - }
454 if (detail.severity === ErrorSeverity.Error) {
448 - res = true;
455 + return true;
456 }
457 }
451 - return res;
458 + return false;
459 }
460
461 /**
462 * Returns true if there are no Errors and there is at least one Warning.
463 */
457 - isWarning(): boolean {
464 + hasWarning(): boolean {
465 let res = false;
466 for (const detail of this.details) {
460 - if (detail.severity === ErrorSeverity.Off) {
461 - return false;
462 - }
467 if (detail.severity === ErrorSeverity.Error) {
468 return false;
469 }
@@ -470,12 +474,9 @@ export class CompilerError extends Error {
474 return res;
475 }
476
473 - isHint(): boolean {
477 + hasHints(): boolean {
478 let res = false;
479 for (const detail of this.details) {
476 - if (detail.severity === ErrorSeverity.Off) {
477 - return false;
478 - }
480 if (detail.severity === ErrorSeverity.Error) {
481 return false;
482 }
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Imports.ts
+1 -1
@@ -46,7 +46,7 @@ export function validateRestrictedImports(
46 }
47 },
48 });
49 - if (error.hasErrors()) {
49 + if (error.hasAnyErrors()) {
50 return error;
51 } else {
52 return null;
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts
+2 -2
@@ -111,7 +111,7 @@ function findDirectivesDynamicGating(
111 }
112 }
113 }
114 - if (errors.hasErrors()) {
114 + if (errors.hasAnyErrors()) {
115 return Err(errors);
116 } else if (result.length > 1) {
117 const error = new CompilerError();
@@ -139,7 +139,7 @@ function findDirectivesDynamicGating(
139 }
140
141 function isError(err: unknown): boolean {
142 - return !(err instanceof CompilerError) || err.isError();
142 + return !(err instanceof CompilerError) || err.hasErrors();
143 }
144
145 function isConfigError(err: unknown): boolean {
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
+2 -2
@@ -213,7 +213,7 @@ export function lower(
213 );
214 }
215
216 - if (builder.errors.hasErrors()) {
216 + if (builder.errors.hasAnyErrors()) {
217 return Err(builder.errors);
218 }
219
@@ -2667,7 +2667,7 @@ function lowerExpression(
2667 * lowerIdentifierForAssignment should have already reported an error if it returned null,
2668 * we check here just in case
2669 */
2670 - if (!builder.errors.hasErrors()) {
2670 + if (!builder.errors.hasAnyErrors()) {
2671 builder.errors.push({
2672 reason: `(BuildHIR::lowerExpression) Found an invalid UpdateExpression without a previously reported error`,
2673 category: ErrorCategory.Invariant,
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts
+1 -1
@@ -568,7 +568,7 @@ export function inferMutationAliasingRanges(
568 }
569 }
570
571 - if (errors.hasErrors() && !isFunctionExpression) {
571 + if (errors.hasAnyErrors() && !isFunctionExpression) {
572 return Err(errors);
573 }
574 return Ok(functionEffects);
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts
+1 -1
@@ -372,7 +372,7 @@ function codegenReactiveFunction(
372 }
373 }
374
375 - if (cx.errors.hasErrors()) {
375 + if (cx.errors.hasAnyErrors()) {
376 return Err(cx.errors);
377 }
378
compiler/packages/babel-plugin-react-compiler/src/Transform/TransformFire.ts
+1 -1
@@ -698,7 +698,7 @@ class Context {
698 }
699
700 hasErrors(): boolean {
701 - return this.#errors.hasErrors();
701 + return this.#errors.hasAnyErrors();
702 }
703
704 throwIfErrorsFound(): void {
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects.ts
+1 -1
@@ -104,7 +104,7 @@ export function validateNoDerivedComputationsInEffects(fn: HIRFunction): void {
104 }
105 }
106 }
107 - if (errors.hasErrors()) {
107 + if (errors.hasAnyErrors()) {
108 throw errors;
109 }
110 }
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccessInRender.ts
+1 -1
@@ -735,7 +735,7 @@ function validateNoRefAccessInRenderImpl(
735 }
736 }
737
738 - if (errors.hasErrors()) {
738 + if (errors.hasAnyErrors()) {
739 return Err(errors);
740 }
741 }