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..8a4d3d20151c6 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts @@ -271,7 +271,7 @@ const EnvironmentConfigSchema = z.object({ z.array( z.object({ function: ExternalFunctionSchema, - numRequiredArgs: z.number(), + numRequiredArgs: z.number().min(1, 'numRequiredArgs must be > 0'), }), ), ) 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',