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.
This commit is contained in:
Lauren Tan
2023-11-08 14:10:18 -05:00
parent 973ec414bd
commit bb92520ba5
4 changed files with 14 additions and 15 deletions
@@ -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(
@@ -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,
})
);
}
@@ -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.
```
@@ -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)
```