From 501cf92f1e06cf88e4f0f2b49099f36568e794a5 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 15 Jun 2023 15:13:37 -0400 Subject: [PATCH] Unify UnsafeInput and InvalidInput --- .../src/CompilerError.ts | 15 --------------- .../src/Entrypoint/Program.ts | 4 ++-- ...rror.invalid-sketchy-code-use-forget.expect.md | 2 +- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/CompilerError.ts b/compiler/forget/packages/babel-plugin-react-forget/src/CompilerError.ts index b102d618d8..4df8f101cd 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/CompilerError.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/CompilerError.ts @@ -16,12 +16,6 @@ export enum ErrorSeverity { * Unexpected syntax or input that may not be safe to compile. */ InvalidInput = "InvalidInput", - /** - * User code contains unsafe React patterns that might not be safe to compile, but does not mean - * the compiler has bugs. This typically means we can skip over the affected files, but other - * files without these errors can still be compiled. - */ - UnsafeInput = "UnsafeInput", /** * Unhandled syntax that we don't support yet. */ @@ -51,8 +45,6 @@ function mapSeverityToErrorCtor(severity: ErrorSeverity): CompilerErrorKind { return TodoError; case ErrorSeverity.Invariant: return InvariantError; - case ErrorSeverity.UnsafeInput: - return UnsafeInputError; default: assertExhaustive(severity, `Unhandled severity level: ${severity}`); } @@ -75,12 +67,6 @@ class InvariantError extends Error { this.name = `${ErrorSeverity.Invariant}Error`; } } -class UnsafeInputError extends Error { - constructor(message: string) { - super(message); - this.name = `${ErrorSeverity.UnsafeInput}Error`; - } -} export function tryPrintCodeFrame( options: CompilerErrorOptions @@ -240,7 +226,6 @@ export class CompilerError extends Error { case ErrorSeverity.InvalidInput: return true; case ErrorSeverity.Todo: - case ErrorSeverity.UnsafeInput: return false; default: assertExhaustive(detail.severity, "Unhandled error severity"); diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts b/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts index 54b2e7d750..14eb51b01b 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -13,10 +13,10 @@ import { ErrorSeverity, } from "../CompilerError"; import { GeneratedSource } from "../HIR"; +import { getOrInsertDefault } from "../Utils/utils"; import { addInstrumentForget } from "./Instrumentation"; import { ExternalFunction, PluginOptions, parsePluginOptions } from "./Options"; import { compileFn } from "./Pipeline"; -import { getOrInsertDefault } from "../Utils/utils"; export type CompilerPass = { opts: PluginOptions; @@ -207,7 +207,7 @@ export function compileProgram( new CompilerErrorDetail({ reason, description: violation.value.trim(), - severity: ErrorSeverity.UnsafeInput, + severity: ErrorSeverity.InvalidInput, codeframe: null, loc: violation.loc ?? null, }) diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-sketchy-code-use-forget.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-sketchy-code-use-forget.expect.md index 7bfdcd523a..8ce36bd3ab 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-sketchy-code-use-forget.expect.md +++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-sketchy-code-use-forget.expect.md @@ -16,7 +16,7 @@ function lowercasecomponent() { ## Error ``` -[ReactForget] UnsafeInput: One or more React eslint rules is disabled. eslint-disable react-hooks/rules-of-hooks (1:1) +[ReactForget] InvalidInput: One or more React eslint rules is disabled. eslint-disable react-hooks/rules-of-hooks (1:1) ``` \ No newline at end of file