@samitouri / QOS-React-1 / commits / bb92520ba5

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.

Lauren Tan committed Nov 8, 2023 at 14:10 UTC bb92520ba5639fcf81dbf3189a68703b34459a9d
4 files changed +14 -15
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Imports.ts
+11 -12
@@ -23,22 +23,21 @@ export function addImportsToProgram(
23 * Codegen currently does not rename import specifiers, so we do additional
24 * validation here
25 */
26 - if (identifiers.has(importSpecifierName)) {
27 - CompilerError.throwInvalidConfig({
28 - reason: `Encountered conflicting import specifier for ${importSpecifierName} in Forget config.`,
29 - description: null,
30 - loc: GeneratedSource,
31 - suggestions: null,
32 - });
33 - }
34 - if (path.scope.hasBinding(importSpecifierName)) {
35 - CompilerError.throwInvalidConfig({
26 + CompilerError.invariant(identifiers.has(importSpecifierName) === false, {
27 + reason: `Encountered conflicting import specifier for ${importSpecifierName} in Forget config.`,
28 + description: null,
29 + loc: GeneratedSource,
30 + suggestions: null,
31 + });
32 + CompilerError.invariant(
33 + path.scope.hasBinding(importSpecifierName) === false,
34 + {
35 reason: `Encountered conflicting import specifiers for ${importSpecifierName} in generated program.`,
36 description: null,
37 loc: GeneratedSource,
38 suggestions: null,
40 - });
41 - }
39 + }
40 + );
41 identifiers.add(importSpecifierName);
42
43 const importSpecifierNameList = getOrInsertDefault(
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+1 -1
@@ -666,7 +666,7 @@ function checkFunctionReferencedBeforeDeclarationAtTopLevel(
666 "Rewrite the reference to not use hoisting to fix this issue",
667 loc: fn.loc ?? null,
668 suggestions: null,
669 - severity: ErrorSeverity.InvalidConfig,
669 + severity: ErrorSeverity.Invariant,
670 })
671 );
672 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.codegen-error-on-conflicting-imports.expect.md
+1 -1
@@ -15,7 +15,7 @@ function useFoo(props) {
15 ## Error
16
17 ```
18 -[ReactForget] InvalidConfig: Encountered conflicting import specifiers for makeReadOnly in generated program.
18 +[ReactForget] Invariant: Encountered conflicting import specifiers for makeReadOnly in generated program.
19 ```
20
21
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-use-before-decl.expect.md
+1 -1
@@ -14,7 +14,7 @@ function Foo() {}
14 ## Error
15
16 ```
17 -[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)
17 +[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)
18 ```
19
20
\ No newline at end of file