| | |
| | | import t from "@babel/types"; |
| | | import virtualTypes from "../../lib/path/lib/virtual-types.js"; |
| | | import definitions from "@babel/types/lib/definitions/index.js"; |
| | | |
| | | export default function generateValidators() { |
| | | let output = `/* |
| | |
| | | for (const type of Object.keys(virtualTypes)) { |
| | | const { types } = virtualTypes[type]; |
| | | if (type[0] === "_") continue; |
| | | if (definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]) { |
| | | if (t.NODE_FIELDS[type] || t.FLIPPED_ALIAS_KEYS[type]) { |
| | | output += `is${type}(opts?: object): this is NodePath<t.${type}>;`; |
| | | } else if (types /* in VirtualTypeAliases */) { |
| | | output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`; |
| | | } else if (type === "Pure") { |
| | | output += `isPure(constantsOnly?: boolean): boolean;`; |
| | | } else { |
| | | // if it don't have types, then VirtualTypeAliases[type] is t.Node |
| | | // which TS marked as always true |