[be] tsconfig: useUnknownInCatchVariables
Mofei Zhang committed
Nov 12, 2023 at 14:44 UTC
7db2388fff15a6c66a9b9e96ce596ccd3c98f099
3 files changed
+24
-12
compiler/packages/babel-plugin-react-forget/src/Utils/logger.ts
+12
-1
@@ -52,7 +52,18 @@ export function logCodegenFunction(step: string, fn: CodegenFunction): void {
52
const ast = generate(node);
53
printed = ast.code;
54
} catch (e) {
55
- console.log("Error formatting AST: " + e.message);
55
+ let errMsg: string;
56
+ if (
57
+ typeof e === "object" &&
58
+ e != null &&
59
+ "message" in e &&
60
+ typeof e.message === "string"
61
+ ) {
62
+ errMsg = e.message.toString();
63
+ } else {
64
+ errMsg = "[empty]";
65
+ }
66
+ console.log("Error formatting AST: " + errMsg);
67
}
68
if (printed === null) {
69
return;
compiler/packages/babel-plugin-react-forget/src/__tests__/envConfig-test.ts
+11
-10
@@ -5,26 +5,27 @@
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
-import { Effect, ValueKind, validateEnvironmentConfig } from "..";
8
+import {
9
+ CompilerError,
10
+ Effect,
11
+ ValueKind,
12
+ validateEnvironmentConfig,
13
+} from "..";
14
15
describe("parseConfigPragma()", () => {
16
it("passing null throws", () => {
17
expect(() => validateEnvironmentConfig(null as any)).toThrow();
18
});
19
15
- // tests that the errror message remains useful
20
+ // tests that the error message remains useful
21
it("passing incorrect value throws", () => {
17
- expect.assertions(1);
18
-
19
- try {
22
+ expect(() => {
23
validateEnvironmentConfig({
24
validateHooksUsage: 1,
25
} as any);
23
- } catch (err) {
24
- expect(err.message).toBe(
25
- '[ReactForget] InvalidConfig: Validation error: Expected boolean, received number at "validateHooksUsage". Update Forget config to fix the error'
26
- );
27
- }
26
+ }).toThrowErrorMatchingInlineSnapshot(
27
+ `"[ReactForget] InvalidConfig: Validation error: Expected boolean, received number at "validateHooksUsage". Update Forget config to fix the error"`
28
+ );
29
});
30
31
it("can parse stringy enums", () => {
compiler/packages/babel-plugin-react-forget/tsconfig.json
+1
-1
@@ -14,7 +14,7 @@
14
"importsNotUsedAsValues": "remove",
15
"noUncheckedIndexedAccess": false,
16
"noUnusedParameters": false,
17
- "useUnknownInCatchVariables": false,
17
+ "useUnknownInCatchVariables": true,
18
"target": "ES2015",
19
// ideally turn off only during dev, or on a per-file basis
20
"noUnusedLocals": false,