[compiler] Filter out disabled errors from being reported

This PR stops error details of severity `ErrorSeverity.Off` from being reported.
This commit is contained in:
Lauren Tan
2025-09-06 12:59:26 -04:00
parent 7985a81ef6
commit ea7fe29bd8
9 changed files with 30 additions and 29 deletions
@@ -279,6 +279,7 @@ export class CompilerErrorDetail {
*/
export class CompilerError extends Error {
details: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
disabledDetails: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
printedMessage: string | null = null;
static invariant(
@@ -359,6 +360,7 @@ export class CompilerError extends Error {
super(...args);
this.name = 'ReactCompilerError';
this.details = [];
this.disabledDetails = [];
}
override get message(): string {
@@ -399,10 +401,15 @@ export class CompilerError extends Error {
merge(other: CompilerError): void {
this.details.push(...other.details);
this.disabledDetails.push(...other.disabledDetails);
}
pushDiagnostic(diagnostic: CompilerDiagnostic): void {
this.details.push(diagnostic);
if (diagnostic.severity === ErrorSeverity.Off) {
this.disabledDetails.push(diagnostic);
} else {
this.details.push(diagnostic);
}
}
/**
@@ -423,43 +430,40 @@ export class CompilerError extends Error {
* @deprecated use {@link pushDiagnostic} instead
*/
pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail {
this.details.push(detail);
if (detail.severity === ErrorSeverity.Off) {
this.disabledDetails.push(detail);
} else {
this.details.push(detail);
}
return detail;
}
hasErrors(): boolean {
hasAnyErrors(): boolean {
return this.details.length > 0;
}
asResult(): Result<void, CompilerError> {
return this.hasErrors() ? Err(this) : Ok(undefined);
return this.hasAnyErrors() ? Err(this) : Ok(undefined);
}
/**
* Returns true if any of the error details are of severity Error.
*/
isError(): boolean {
let res = false;
hasErrors(): boolean {
for (const detail of this.details) {
if (detail.severity === ErrorSeverity.Off) {
return false;
}
if (detail.severity === ErrorSeverity.Error) {
res = true;
return true;
}
}
return res;
return false;
}
/**
* Returns true if there are no Errors and there is at least one Warning.
*/
isWarning(): boolean {
hasWarning(): boolean {
let res = false;
for (const detail of this.details) {
if (detail.severity === ErrorSeverity.Off) {
return false;
}
if (detail.severity === ErrorSeverity.Error) {
return false;
}
@@ -470,12 +474,9 @@ export class CompilerError extends Error {
return res;
}
isHint(): boolean {
hasHints(): boolean {
let res = false;
for (const detail of this.details) {
if (detail.severity === ErrorSeverity.Off) {
return false;
}
if (detail.severity === ErrorSeverity.Error) {
return false;
}
@@ -46,7 +46,7 @@ export function validateRestrictedImports(
}
},
});
if (error.hasErrors()) {
if (error.hasAnyErrors()) {
return error;
} else {
return null;
@@ -111,7 +111,7 @@ function findDirectivesDynamicGating(
}
}
}
if (errors.hasErrors()) {
if (errors.hasAnyErrors()) {
return Err(errors);
} else if (result.length > 1) {
const error = new CompilerError();
@@ -139,7 +139,7 @@ function findDirectivesDynamicGating(
}
function isError(err: unknown): boolean {
return !(err instanceof CompilerError) || err.isError();
return !(err instanceof CompilerError) || err.hasErrors();
}
function isConfigError(err: unknown): boolean {
@@ -213,7 +213,7 @@ export function lower(
);
}
if (builder.errors.hasErrors()) {
if (builder.errors.hasAnyErrors()) {
return Err(builder.errors);
}
@@ -2667,7 +2667,7 @@ function lowerExpression(
* lowerIdentifierForAssignment should have already reported an error if it returned null,
* we check here just in case
*/
if (!builder.errors.hasErrors()) {
if (!builder.errors.hasAnyErrors()) {
builder.errors.push({
reason: `(BuildHIR::lowerExpression) Found an invalid UpdateExpression without a previously reported error`,
category: ErrorCategory.Invariant,
@@ -568,7 +568,7 @@ export function inferMutationAliasingRanges(
}
}
if (errors.hasErrors() && !isFunctionExpression) {
if (errors.hasAnyErrors() && !isFunctionExpression) {
return Err(errors);
}
return Ok(functionEffects);
@@ -372,7 +372,7 @@ function codegenReactiveFunction(
}
}
if (cx.errors.hasErrors()) {
if (cx.errors.hasAnyErrors()) {
return Err(cx.errors);
}
@@ -698,7 +698,7 @@ class Context {
}
hasErrors(): boolean {
return this.#errors.hasErrors();
return this.#errors.hasAnyErrors();
}
throwIfErrorsFound(): void {
@@ -104,7 +104,7 @@ export function validateNoDerivedComputationsInEffects(fn: HIRFunction): void {
}
}
}
if (errors.hasErrors()) {
if (errors.hasAnyErrors()) {
throw errors;
}
}
@@ -735,7 +735,7 @@ function validateNoRefAccessInRenderImpl(
}
}
if (errors.hasErrors()) {
if (errors.hasAnyErrors()) {
return Err(errors);
}
}