From 7db2388fff15a6c66a9b9e96ce596ccd3c98f099 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Sun, 12 Nov 2023 14:44:15 -0500 Subject: [PATCH] [be] tsconfig: useUnknownInCatchVariables --- .../src/Utils/logger.ts | 13 +++++++++++- .../src/__tests__/envConfig-test.ts | 21 ++++++++++--------- .../babel-plugin-react-forget/tsconfig.json | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/Utils/logger.ts b/compiler/packages/babel-plugin-react-forget/src/Utils/logger.ts index 660407e328..446292d1b1 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Utils/logger.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Utils/logger.ts @@ -52,7 +52,18 @@ export function logCodegenFunction(step: string, fn: CodegenFunction): void { const ast = generate(node); printed = ast.code; } catch (e) { - console.log("Error formatting AST: " + e.message); + let errMsg: string; + if ( + typeof e === "object" && + e != null && + "message" in e && + typeof e.message === "string" + ) { + errMsg = e.message.toString(); + } else { + errMsg = "[empty]"; + } + console.log("Error formatting AST: " + errMsg); } if (printed === null) { return; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/envConfig-test.ts b/compiler/packages/babel-plugin-react-forget/src/__tests__/envConfig-test.ts index b0f5eea0df..f194474ec1 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/envConfig-test.ts +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/envConfig-test.ts @@ -5,26 +5,27 @@ * LICENSE file in the root directory of this source tree. */ -import { Effect, ValueKind, validateEnvironmentConfig } from ".."; +import { + CompilerError, + Effect, + ValueKind, + validateEnvironmentConfig, +} from ".."; describe("parseConfigPragma()", () => { it("passing null throws", () => { expect(() => validateEnvironmentConfig(null as any)).toThrow(); }); - // tests that the errror message remains useful + // tests that the error message remains useful it("passing incorrect value throws", () => { - expect.assertions(1); - - try { + expect(() => { validateEnvironmentConfig({ validateHooksUsage: 1, } as any); - } catch (err) { - expect(err.message).toBe( - '[ReactForget] InvalidConfig: Validation error: Expected boolean, received number at "validateHooksUsage". Update Forget config to fix the error' - ); - } + }).toThrowErrorMatchingInlineSnapshot( + `"[ReactForget] InvalidConfig: Validation error: Expected boolean, received number at "validateHooksUsage". Update Forget config to fix the error"` + ); }); it("can parse stringy enums", () => { diff --git a/compiler/packages/babel-plugin-react-forget/tsconfig.json b/compiler/packages/babel-plugin-react-forget/tsconfig.json index 8c40bea321..7d1c691f51 100644 --- a/compiler/packages/babel-plugin-react-forget/tsconfig.json +++ b/compiler/packages/babel-plugin-react-forget/tsconfig.json @@ -14,7 +14,7 @@ "importsNotUsedAsValues": "remove", "noUncheckedIndexedAccess": false, "noUnusedParameters": false, - "useUnknownInCatchVariables": false, + "useUnknownInCatchVariables": true, "target": "ES2015", // ideally turn off only during dev, or on a per-file basis "noUnusedLocals": false,