-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
validators.js
36 lines (29 loc) 路 922 Bytes
/
validators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as t from "@babel/types";
export default function generateValidators() {
let output = `/*
* This file is auto-generated! Do not modify it directly.
* To re-generate run 'make build'
*/
import type * as t from "@babel/types";
import type NodePath from "../index";
import type { VirtualTypeNodePathValidators } from "../lib/virtual-types-validator";
type Opts<Obj> = Partial<{
[Prop in keyof Obj]: Obj[Prop] extends t.Node
? t.Node
: Obj[Prop] extends t.Node[]
? t.Node[]
: Obj[Prop];
}>;
interface BaseNodePathValidators {
`;
for (const type of [...t.TYPES].sort()) {
output += `is${type}<T extends t.Node>(this: NodePath<T>, opts?: Opts<t.${type}>): this is NodePath<T & t.${type}>;`;
}
output += `
}
export interface NodePathValidators
extends Omit<BaseNodePathValidators, keyof VirtualTypeNodePathValidators>,
VirtualTypeNodePathValidators {}
`;
return output;
}