Make string values for config case-insensitive
Fixes a tiny inconsistency with compiler options where one was all uppercase and one all lowercase by normalizing to lowercase regardless of the casing of the user's config. ghstack-source-id: fe60a3259de89a1b3fdd7475950e16e96cc57f6b Pull Request resolved: https://github.com/facebook/react-forget/pull/2832
Lauren Tan committed
Apr 11, 2024 at 10:45 UTC
ec05176fb3950f905f16616934c560d4150130d3
12 files changed
+27
-23
compiler/packages/babel-plugin-react-forget/src/Babel/RunReactForgetBabelPlugin.ts
+1
-1
@@ -18,7 +18,7 @@ export function runReactForgetBabelPlugin(
18
text: string,
19
file: string,
20
language: "flow" | "typescript",
21
- options: PluginOptions | null,
21
+ options: Partial<PluginOptions> | null,
22
includeAst: boolean = false
23
): BabelCore.BabelFileResult {
24
let ast;
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts
+9
-5
@@ -17,15 +17,15 @@ const PanicThresholdOptionsSchema = z.enum([
17
* If Forget is invoked through `ReactForgetBabelPlugin`, this will at the least
18
* skip Forget compilation for the rest of current file.
19
*/
20
- "ALL_ERRORS",
20
+ "all_errors",
21
/*
22
* Panic by throwing an exception only on critical or unrecognized errors.
23
* For all other errors, skip the erroring function without inserting
24
* a Forget-compiled version (i.e. same behavior as noEmit).
25
*/
26
- "CRITICAL_ERRORS",
26
+ "critical_errors",
27
// Never panic by throwing an exception.
28
- "NONE",
28
+ "none",
29
]);
30
31
export type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
@@ -173,7 +173,7 @@ export type Logger = {
173
174
export const defaultOptions: PluginOptions = {
175
compilationMode: "infer",
176
- panicThreshold: "NONE",
176
+ panicThreshold: "none",
177
environment: {},
178
logger: null,
179
gating: null,
@@ -189,7 +189,11 @@ export function parsePluginOptions(obj: unknown): PluginOptions {
189
return defaultOptions;
190
}
191
const parsedOptions = Object.create(null);
192
- for (const [key, value] of Object.entries(obj)) {
192
+ for (let [key, value] of Object.entries(obj)) {
193
+ if (typeof value === "string") {
194
+ // normalize string configs to be case insensitive
195
+ value = value.toLowerCase();
196
+ }
197
if (isCompilerFlag(key)) {
198
parsedOptions[key] = value;
199
}
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+2
-2
@@ -120,8 +120,8 @@ function handleError(
120
}
121
}
122
if (
123
- pass.opts.panicThreshold === "ALL_ERRORS" ||
124
- (pass.opts.panicThreshold === "CRITICAL_ERRORS" && isCriticalError(err)) ||
123
+ pass.opts.panicThreshold === "all_errors" ||
124
+ (pass.opts.panicThreshold === "critical_errors" && isCriticalError(err)) ||
125
isConfigError(err) // Always throws regardless of panic threshold
126
) {
127
throw err;
compiler/packages/babel-plugin-react-forget/src/__tests__/Logger-test.ts
+2
-2
@@ -21,7 +21,7 @@ it("logs succesful compilation", () => {
21
"function Component(props) { return <div>{props}</div> }",
22
"test.js",
23
"flow",
24
- { logger, panicThreshold: "ALL_ERRORS" } as any
24
+ { logger, panicThreshold: "all_errors" }
25
);
26
27
const [filename, event] = logs.at(0)!;
@@ -48,7 +48,7 @@ it("logs failed compilation", () => {
48
"function Component(props) { props.foo = 1; return <div>{props}</div> }",
49
"test.js",
50
"flow",
51
- { logger, panicThreshold: "ALL_ERRORS" } as any
51
+ { logger, panicThreshold: "all_errors" }
52
);
53
}).toThrow();
54
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-retain-source-when-bailout.expect.md
+2
-2
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-// @panicThreshold(NONE)
5
+// @panicThreshold(none)
6
import { useNoAlias } from "shared-runtime";
7
8
const cond = true;
@@ -27,7 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
27
## Code
28
29
```javascript
30
-// @panicThreshold(NONE)
30
+// @panicThreshold(none)
31
import { useNoAlias } from "shared-runtime";
32
33
const cond = true;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-retain-source-when-bailout.js
+1
-1
@@ -1,4 +1,4 @@
1
-// @panicThreshold(NONE)
1
+// @panicThreshold(none)
2
import { useNoAlias } from "shared-runtime";
3
4
const cond = true;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/should-bailout-without-compilation-annotation-mode.expect.md
+2
-2
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-// @gating @panicThreshold(NONE) @compilationMode(annotation)
5
+// @gating @panicThreshold(none) @compilationMode(annotation)
6
let someGlobal = "joe";
7
8
function Component() {
@@ -21,7 +21,7 @@ export const FIXTURE_ENTRYPOINT = {
21
## Code
22
23
```javascript
24
-// @gating @panicThreshold(NONE) @compilationMode(annotation)
24
+// @gating @panicThreshold(none) @compilationMode(annotation)
25
let someGlobal = "joe";
26
27
function Component() {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/should-bailout-without-compilation-annotation-mode.js
+1
-1
@@ -1,4 +1,4 @@
1
-// @gating @panicThreshold(NONE) @compilationMode(annotation)
1
+// @gating @panicThreshold(none) @compilationMode(annotation)
2
let someGlobal = "joe";
3
4
function Component() {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/should-bailout-without-compilation-infer-mode.expect.md
+2
-2
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-// @gating @panicThreshold(NONE) @compilationMode(infer)
5
+// @gating @panicThreshold(none) @compilationMode(infer)
6
let someGlobal = "joe";
7
8
function Component() {
@@ -20,7 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
20
## Code
21
22
```javascript
23
-// @gating @panicThreshold(NONE) @compilationMode(infer)
23
+// @gating @panicThreshold(none) @compilationMode(infer)
24
let someGlobal = "joe";
25
26
function Component() {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/should-bailout-without-compilation-infer-mode.js
+1
-1
@@ -1,4 +1,4 @@
1
-// @gating @panicThreshold(NONE) @compilationMode(infer)
1
+// @gating @panicThreshold(none) @compilationMode(infer)
2
let someGlobal = "joe";
3
4
function Component() {
compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts
+1
-1
@@ -61,7 +61,7 @@ function isReportableDiagnostic(
61
const COMPILER_OPTIONS: Partial<PluginOptions> = {
62
noEmit: true,
63
compilationMode: "infer",
64
- panicThreshold: "CRITICAL_ERRORS",
64
+ panicThreshold: "critical_errors",
65
};
66
67
const rule: Rule.RuleModule = {
compiler/packages/snap/src/compiler.ts
+3
-3
@@ -39,7 +39,7 @@ function makePluginOptions(
39
let enableEmitHookGuards = null;
40
let compilationMode: CompilationMode = "all";
41
let enableUseMemoCachePolyfill = false;
42
- let panicThreshold: PanicThresholdOptions = "ALL_ERRORS";
42
+ let panicThreshold: PanicThresholdOptions = "all_errors";
43
let hookPattern: string | null = null;
44
// TODO(@mofeiZ) rewrite snap fixtures to @validatePreserveExistingMemo:false
45
let validatePreserveExistingMemoizationGuarantees = false;
@@ -93,8 +93,8 @@ function makePluginOptions(
93
if (firstLine.includes("@enableUseMemoCachePolyfill")) {
94
enableUseMemoCachePolyfill = true;
95
}
96
- if (firstLine.includes("@panicThreshold(NONE)")) {
97
- panicThreshold = "NONE";
96
+ if (firstLine.includes("@panicThreshold(none)")) {
97
+ panicThreshold = "none";
98
}
99
100
let eslintSuppressionRules: Array<string> | null = null;