Update hoisting error message to allow error aggregation
Interpolating values into the `reason` field of an error breaks our error aggregation. This PR moves the offending function name into the `description` field which isn't used for aggregation.
Joe Savona committed
Jan 11, 2024 at 15:54 UTC
c3a947643fae3fbbbda42a676c1b89dfd5d21945
4 files changed
+5
-6
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+2
-3
@@ -646,9 +646,8 @@ function checkFunctionReferencedBeforeDeclarationAtTopLevel(
646
if (scope === null) {
647
errors.pushErrorDetail(
648
new CompilerErrorDetail({
649
- reason: `Encountered ${fn.name} used before declaration which breaks Forget's gating codegen due to hoisting`,
650
- description:
651
- "Rewrite the reference to not use hoisting to fix this issue",
649
+ reason: `Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting`,
650
+ description: `Rewrite the reference to ${fn.name} to not rely on hoisting to fix this issue`,
651
loc: fn.loc ?? null,
652
suggestions: null,
653
severity: ErrorSeverity.Invariant,
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md
+1
-1
@@ -12,7 +12,7 @@ component Foo(ref: React.RefSetter<Controls>) {
12
## Error
13
14
```
15
-[ReactForget] Invariant: Encountered Foo_withRef used before declaration which breaks Forget's gating codegen due to hoisting. Rewrite the reference to not use hoisting to fix this issue (2:2)
15
+[ReactForget] Invariant: Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting. Rewrite the reference to Foo_withRef to not rely on hoisting to fix this issue (2:2)
16
```
17
18
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md
+1
-1
@@ -14,7 +14,7 @@ function Foo_withRef(props, ref) {
14
## Error
15
16
```
17
-[ReactForget] Invariant: Encountered Foo_withRef used before declaration which breaks Forget's gating codegen due to hoisting. Rewrite the reference to not use hoisting to fix this issue (3:3)
17
+[ReactForget] Invariant: Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting. Rewrite the reference to Foo_withRef to not rely on hoisting to fix this issue (3:3)
18
```
19
20
\ 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] 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)
17
+[ReactForget] Invariant: Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting. Rewrite the reference to Foo to not rely on hoisting to fix this issue (5:5)
18
```
19
20
\ No newline at end of file