Skip to content

Commit

Permalink
[compiler][ez] Add validation for auto-deps config
Browse files Browse the repository at this point in the history
numRequiredArgs has to be more than 0 and the pass depends on that

--
  • Loading branch information
jbrown215 committed Dec 20, 2024
1 parent e06c72f commit 5954333
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import {Effect, validateEnvironmentConfig} from '..';
import {ValueKind} from '../HIR';
import {inferEffectDependencies} from '../Inference';

describe('parseConfigPragma()', () => {
it('passing null throws', () => {
Expand All @@ -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',
Expand Down

0 comments on commit 5954333

Please sign in to comment.