From bb92520ba5639fcf81dbf3189a68703b34459a9d Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Wed, 8 Nov 2023 14:10:18 -0500 Subject: [PATCH] Some existing InvalidConfig errors should be invariants Now that we have validation of the compiler config, these old errors weren't categorized correctly. Readjusted them to be invariants instead. --- .../src/Entrypoint/Imports.ts | 23 +++++++++---------- .../src/Entrypoint/Program.ts | 2 +- ...gen-error-on-conflicting-imports.expect.md | 2 +- .../error.gating-use-before-decl.expect.md | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Imports.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Imports.ts index 9098f17ca6..5eff1a0f70 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Imports.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Imports.ts @@ -23,22 +23,21 @@ export function addImportsToProgram( * Codegen currently does not rename import specifiers, so we do additional * validation here */ - if (identifiers.has(importSpecifierName)) { - CompilerError.throwInvalidConfig({ - reason: `Encountered conflicting import specifier for ${importSpecifierName} in Forget config.`, - description: null, - loc: GeneratedSource, - suggestions: null, - }); - } - if (path.scope.hasBinding(importSpecifierName)) { - CompilerError.throwInvalidConfig({ + CompilerError.invariant(identifiers.has(importSpecifierName) === false, { + reason: `Encountered conflicting import specifier for ${importSpecifierName} in Forget config.`, + description: null, + loc: GeneratedSource, + suggestions: null, + }); + CompilerError.invariant( + path.scope.hasBinding(importSpecifierName) === false, + { reason: `Encountered conflicting import specifiers for ${importSpecifierName} in generated program.`, description: null, loc: GeneratedSource, suggestions: null, - }); - } + } + ); identifiers.add(importSpecifierName); const importSpecifierNameList = getOrInsertDefault( diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts index 2b66d10576..ba43dfd2d8 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -666,7 +666,7 @@ function checkFunctionReferencedBeforeDeclarationAtTopLevel( "Rewrite the reference to not use hoisting to fix this issue", loc: fn.loc ?? null, suggestions: null, - severity: ErrorSeverity.InvalidConfig, + severity: ErrorSeverity.Invariant, }) ); } diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.codegen-error-on-conflicting-imports.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.codegen-error-on-conflicting-imports.expect.md index 14ad376efd..26d1319404 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.codegen-error-on-conflicting-imports.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.codegen-error-on-conflicting-imports.expect.md @@ -15,7 +15,7 @@ function useFoo(props) { ## Error ``` -[ReactForget] InvalidConfig: Encountered conflicting import specifiers for makeReadOnly in generated program. +[ReactForget] Invariant: Encountered conflicting import specifiers for makeReadOnly in generated program. ``` \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-use-before-decl.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-use-before-decl.expect.md index 64b88139e0..af223192d0 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-use-before-decl.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-use-before-decl.expect.md @@ -14,7 +14,7 @@ function Foo() {} ## Error ``` -[ReactForget] InvalidConfig: Encountered Foo used before declaration which breaks Forget's gating codegen due to hoisting. Rewrite the reference to not use hoisting to fix this issue (5:5) +[ReactForget] Invariant: Encountered Foo used before declaration which breaks Forget's gating codegen due to hoisting. Rewrite the reference to not use hoisting to fix this issue (5:5) ``` \ No newline at end of file