mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* Gulpfile.ts * fix * chore: remove ts-node and patch interpret The patched version now recognizes the gulp config `Gulpfile.mts` and the built in node type stripping will then kick in. * fix --------- Co-authored-by: Huáng Jùnliàng <[email protected]>
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
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 Options<Obj> = Partial<{
|
|
[Prop in Exclude<keyof Obj, "type">]: 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}(this: NodePath<t.Node | null>): this is NodePath<t.${type}>;`;
|
|
output += `is${type}<Opts extends Options<t.${type}>>(this: NodePath<t.Node | null>, opts: Opts): this is NodePath<t.${type} & Opts>;`;
|
|
}
|
|
|
|
output += `
|
|
}
|
|
|
|
export interface NodePathValidators
|
|
extends Omit<BaseNodePathValidators, keyof VirtualTypeNodePathValidators>,
|
|
VirtualTypeNodePathValidators {}
|
|
`;
|
|
|
|
return output;
|
|
}
|