mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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
This commit is contained in:
@@ -18,7 +18,7 @@ export function runReactForgetBabelPlugin(
|
||||
text: string,
|
||||
file: string,
|
||||
language: "flow" | "typescript",
|
||||
options: PluginOptions | null,
|
||||
options: Partial<PluginOptions> | null,
|
||||
includeAst: boolean = false
|
||||
): BabelCore.BabelFileResult {
|
||||
let ast;
|
||||
|
||||
@@ -17,15 +17,15 @@ const PanicThresholdOptionsSchema = z.enum([
|
||||
* If Forget is invoked through `ReactForgetBabelPlugin`, this will at the least
|
||||
* skip Forget compilation for the rest of current file.
|
||||
*/
|
||||
"ALL_ERRORS",
|
||||
"all_errors",
|
||||
/*
|
||||
* Panic by throwing an exception only on critical or unrecognized errors.
|
||||
* For all other errors, skip the erroring function without inserting
|
||||
* a Forget-compiled version (i.e. same behavior as noEmit).
|
||||
*/
|
||||
"CRITICAL_ERRORS",
|
||||
"critical_errors",
|
||||
// Never panic by throwing an exception.
|
||||
"NONE",
|
||||
"none",
|
||||
]);
|
||||
|
||||
export type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
|
||||
@@ -173,7 +173,7 @@ export type Logger = {
|
||||
|
||||
export const defaultOptions: PluginOptions = {
|
||||
compilationMode: "infer",
|
||||
panicThreshold: "NONE",
|
||||
panicThreshold: "none",
|
||||
environment: {},
|
||||
logger: null,
|
||||
gating: null,
|
||||
@@ -189,7 +189,11 @@ export function parsePluginOptions(obj: unknown): PluginOptions {
|
||||
return defaultOptions;
|
||||
}
|
||||
const parsedOptions = Object.create(null);
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
for (let [key, value] of Object.entries(obj)) {
|
||||
if (typeof value === "string") {
|
||||
// normalize string configs to be case insensitive
|
||||
value = value.toLowerCase();
|
||||
}
|
||||
if (isCompilerFlag(key)) {
|
||||
parsedOptions[key] = value;
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ function handleError(
|
||||
}
|
||||
}
|
||||
if (
|
||||
pass.opts.panicThreshold === "ALL_ERRORS" ||
|
||||
(pass.opts.panicThreshold === "CRITICAL_ERRORS" && isCriticalError(err)) ||
|
||||
pass.opts.panicThreshold === "all_errors" ||
|
||||
(pass.opts.panicThreshold === "critical_errors" && isCriticalError(err)) ||
|
||||
isConfigError(err) // Always throws regardless of panic threshold
|
||||
) {
|
||||
throw err;
|
||||
|
||||
@@ -21,7 +21,7 @@ it("logs succesful compilation", () => {
|
||||
"function Component(props) { return <div>{props}</div> }",
|
||||
"test.js",
|
||||
"flow",
|
||||
{ logger, panicThreshold: "ALL_ERRORS" } as any
|
||||
{ logger, panicThreshold: "all_errors" }
|
||||
);
|
||||
|
||||
const [filename, event] = logs.at(0)!;
|
||||
@@ -48,7 +48,7 @@ it("logs failed compilation", () => {
|
||||
"function Component(props) { props.foo = 1; return <div>{props}</div> }",
|
||||
"test.js",
|
||||
"flow",
|
||||
{ logger, panicThreshold: "ALL_ERRORS" } as any
|
||||
{ logger, panicThreshold: "all_errors" }
|
||||
);
|
||||
}).toThrow();
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @panicThreshold(NONE)
|
||||
// @panicThreshold(none)
|
||||
import { useNoAlias } from "shared-runtime";
|
||||
|
||||
const cond = true;
|
||||
@@ -27,7 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
// @panicThreshold(NONE)
|
||||
// @panicThreshold(none)
|
||||
import { useNoAlias } from "shared-runtime";
|
||||
|
||||
const cond = true;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// @panicThreshold(NONE)
|
||||
// @panicThreshold(none)
|
||||
import { useNoAlias } from "shared-runtime";
|
||||
|
||||
const cond = true;
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @gating @panicThreshold(NONE) @compilationMode(annotation)
|
||||
// @gating @panicThreshold(none) @compilationMode(annotation)
|
||||
let someGlobal = "joe";
|
||||
|
||||
function Component() {
|
||||
@@ -21,7 +21,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
// @gating @panicThreshold(NONE) @compilationMode(annotation)
|
||||
// @gating @panicThreshold(none) @compilationMode(annotation)
|
||||
let someGlobal = "joe";
|
||||
|
||||
function Component() {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// @gating @panicThreshold(NONE) @compilationMode(annotation)
|
||||
// @gating @panicThreshold(none) @compilationMode(annotation)
|
||||
let someGlobal = "joe";
|
||||
|
||||
function Component() {
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @gating @panicThreshold(NONE) @compilationMode(infer)
|
||||
// @gating @panicThreshold(none) @compilationMode(infer)
|
||||
let someGlobal = "joe";
|
||||
|
||||
function Component() {
|
||||
@@ -20,7 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
// @gating @panicThreshold(NONE) @compilationMode(infer)
|
||||
// @gating @panicThreshold(none) @compilationMode(infer)
|
||||
let someGlobal = "joe";
|
||||
|
||||
function Component() {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// @gating @panicThreshold(NONE) @compilationMode(infer)
|
||||
// @gating @panicThreshold(none) @compilationMode(infer)
|
||||
let someGlobal = "joe";
|
||||
|
||||
function Component() {
|
||||
|
||||
@@ -61,7 +61,7 @@ function isReportableDiagnostic(
|
||||
const COMPILER_OPTIONS: Partial<PluginOptions> = {
|
||||
noEmit: true,
|
||||
compilationMode: "infer",
|
||||
panicThreshold: "CRITICAL_ERRORS",
|
||||
panicThreshold: "critical_errors",
|
||||
};
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
|
||||
@@ -39,7 +39,7 @@ function makePluginOptions(
|
||||
let enableEmitHookGuards = null;
|
||||
let compilationMode: CompilationMode = "all";
|
||||
let enableUseMemoCachePolyfill = false;
|
||||
let panicThreshold: PanicThresholdOptions = "ALL_ERRORS";
|
||||
let panicThreshold: PanicThresholdOptions = "all_errors";
|
||||
let hookPattern: string | null = null;
|
||||
// TODO(@mofeiZ) rewrite snap fixtures to @validatePreserveExistingMemo:false
|
||||
let validatePreserveExistingMemoizationGuarantees = false;
|
||||
@@ -93,8 +93,8 @@ function makePluginOptions(
|
||||
if (firstLine.includes("@enableUseMemoCachePolyfill")) {
|
||||
enableUseMemoCachePolyfill = true;
|
||||
}
|
||||
if (firstLine.includes("@panicThreshold(NONE)")) {
|
||||
panicThreshold = "NONE";
|
||||
if (firstLine.includes("@panicThreshold(none)")) {
|
||||
panicThreshold = "none";
|
||||
}
|
||||
|
||||
let eslintSuppressionRules: Array<string> | null = null;
|
||||
|
||||
Reference in New Issue
Block a user