From c3a947643fae3fbbbda42a676c1b89dfd5d21945 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Thu, 11 Jan 2024 15:54:55 -0800 Subject: [PATCH] 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. --- .../babel-plugin-react-forget/src/Entrypoint/Program.ts | 5 ++--- .../error.component-syntax-ref-gating.flow.expect.md | 2 +- .../fixtures/compiler/error.gating-hoisting.expect.md | 2 +- .../fixtures/compiler/error.gating-use-before-decl.expect.md | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) 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 7611944c3d..be9d61eb5b 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts @@ -646,9 +646,8 @@ function checkFunctionReferencedBeforeDeclarationAtTopLevel( if (scope === null) { errors.pushErrorDetail( new CompilerErrorDetail({ - reason: `Encountered ${fn.name} used before declaration which breaks Forget's gating codegen due to hoisting`, - description: - "Rewrite the reference to not use hoisting to fix this issue", + reason: `Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting`, + description: `Rewrite the reference to ${fn.name} to not rely on hoisting to fix this issue`, loc: fn.loc ?? null, suggestions: null, severity: ErrorSeverity.Invariant, diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md index fdefed1906..94ac0cb5ff 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md @@ -12,7 +12,7 @@ component Foo(ref: React.RefSetter) { ## Error ``` -[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) +[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) ``` \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md index e8769a30f6..7d13a1a39a 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md @@ -14,7 +14,7 @@ function Foo_withRef(props, ref) { ## Error ``` -[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) +[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) ``` \ 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 af223192d0..f3f9512867 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] 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) +[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) ``` \ No newline at end of file