1 | import t from "@babel/types";
|
2 | import virtualTypes from "../../lib/path/lib/virtual-types.js";
|
3 | import definitions from "@babel/types/lib/definitions/index.js";
|
4 |
|
5 | export default function generateValidators() {
|
6 | let output = `/*
|
7 | * This file is auto-generated! Do not modify it directly.
|
8 | * To re-generate run 'make build'
|
9 | */
|
10 | import * as t from "@babel/types";
|
11 | import NodePath from "../index";
|
12 |
|
13 | export interface NodePathValidators {
|
14 | `;
|
15 |
|
16 | for (const type of [...t.TYPES].sort()) {
|
17 | output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
|
18 | }
|
19 |
|
20 | for (const type of Object.keys(virtualTypes)) {
|
21 | if (type[0] === "_") continue;
|
22 | if (definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]) {
|
23 | output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
|
24 | } else {
|
25 | output += `is${type}(opts?: object): boolean;`;
|
26 | }
|
27 | }
|
28 |
|
29 | output += `
|
30 | }
|
31 | `;
|
32 |
|
33 | return output;
|
34 | }
|