source: trip-planner-front/node_modules/@babel/traverse/scripts/generators/validators.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import t from "@babel/types";
2import virtualTypes from "../../lib/path/lib/virtual-types.js";
3import definitions from "@babel/types/lib/definitions/index.js";
4
5export 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 */
10import * as t from "@babel/types";
11import NodePath from "../index";
12import type { VirtualTypeAliases } from "./virtual-types";
13
14export interface NodePathValidators {
15`;
16
17 for (const type of [...t.TYPES].sort()) {
18 output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
19 }
20
21 for (const type of Object.keys(virtualTypes)) {
22 const { types } = virtualTypes[type];
23 if (type[0] === "_") continue;
24 if (definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]) {
25 output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
26 } else if (types /* in VirtualTypeAliases */) {
27 output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`;
28 } else {
29 // if it don't have types, then VirtualTypeAliases[type] is t.Node
30 // which TS marked as always true
31 // eg. if (path.isBlockScope()) return;
32 // path resolved to `never` here
33 // so we have to return boolean instead of this is NodePath<t.Node> here
34 output += `is${type}(opts?: object): boolean;`;
35 }
36 }
37
38 output += `
39}
40`;
41
42 return output;
43}
Note: See TracBrowser for help on using the repository browser.