Skip to content

Commit 5954333

Browse files
committed
[compiler][ez] Add validation for auto-deps config
numRequiredArgs has to be more than 0 and the pass depends on that --
1 parent e06c72f commit 5954333

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const EnvironmentConfigSchema = z.object({
271271
z.array(
272272
z.object({
273273
function: ExternalFunctionSchema,
274-
numRequiredArgs: z.number(),
274+
numRequiredArgs: z.number().min(1, 'numRequiredArgs must be > 0'),
275275
}),
276276
),
277277
)

compiler/packages/babel-plugin-react-compiler/src/__tests__/envConfig-test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import {Effect, validateEnvironmentConfig} from '..';
99
import {ValueKind} from '../HIR';
10+
import {inferEffectDependencies} from '../Inference';
1011

1112
describe('parseConfigPragma()', () => {
1213
it('passing null throws', () => {
@@ -24,6 +25,24 @@ describe('parseConfigPragma()', () => {
2425
);
2526
});
2627

28+
it('effect autodeps config must have at least 1 required argument', () => {
29+
expect(() => {
30+
validateEnvironmentConfig({
31+
inferEffectDependencies: [
32+
{
33+
function: {
34+
source: 'react',
35+
importSpecifierName: 'useEffect',
36+
},
37+
numRequiredArgs: 0,
38+
},
39+
],
40+
} as any);
41+
}).toThrowErrorMatchingInlineSnapshot(
42+
`"InvalidConfig: Could not validate environment config. Update React Compiler config to fix the error. Validation error: numRequiredArgs must be > 0 at "inferEffectDependencies[0].numRequiredArgs""`,
43+
);
44+
});
45+
2746
it('can parse stringy enums', () => {
2847
const stringyHook = {
2948
effectKind: 'freeze',

0 commit comments

Comments
 (0)