diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts index fa581d8ed8d81..28bbedebca97b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts @@ -271,13 +271,28 @@ const EnvironmentConfigSchema = z.object({ z.array( z.object({ function: ExternalFunctionSchema, - numRequiredArgs: z.number(), + numRequiredArgs: z.number().min(1, 'numRequiredArgs must be > 0'), }), ), ) .default(null), /** + * Enables inference of effect dependencies for the given list of functions. Takes in an array of + * configurable module and import pairs to allow for user-land experimentation. For example, + * [ + * { + * module: 'react', + * imported: 'useEffect', + * numRequiredArgs: 1, + * },{ + * module: ' + * }), + * ), + *) + *.default(null), + * + * /** * Enables inlining ReactElement object literals in place of JSX * An alternative to the standard JSX transform which replaces JSX with React's jsxProd() runtime * Currently a prod-only optimization, requiring Fast JSX dependencies diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/envConfig-test.ts b/compiler/packages/babel-plugin-react-compiler/src/__tests__/envConfig-test.ts index 02715601bdc63..b90c9d9175057 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/envConfig-test.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/envConfig-test.ts @@ -7,6 +7,7 @@ import {Effect, validateEnvironmentConfig} from '..'; import {ValueKind} from '../HIR'; +import {inferEffectDependencies} from '../Inference'; describe('parseConfigPragma()', () => { it('passing null throws', () => { @@ -24,6 +25,24 @@ describe('parseConfigPragma()', () => { ); }); + it('effect autodeps config must have at least 1 required argument', () => { + expect(() => { + validateEnvironmentConfig({ + inferEffectDependencies: [ + { + function: { + source: 'react', + importSpecifierName: 'useEffect', + }, + numRequiredArgs: 0, + }, + ], + } as any); + }).toThrowErrorMatchingInlineSnapshot( + `"InvalidConfig: Could not validate environment config. Update React Compiler config to fix the error. Validation error: numRequiredArgs must be > 0 at "inferEffectDependencies[0].numRequiredArgs""`, + ); + }); + it('can parse stringy enums', () => { const stringyHook = { effectKind: 'freeze',