estree-toolkit
Version:
Traverser, scope tracker, and more tools for working with ESTree AST
27 lines (26 loc) • 1.23 kB
TypeScript
import { BaseNode, Node, ParentsOf } from './helpers';
import * as a from './assert';
type NodeKeys<N> = Exclude<keyof N, keyof BaseNode>;
export type DefinitionIndex<T> = T extends true ? number | [builderIndex: number | false, visitIndex: number | false] : false | [builderIndex: number | false, visitIndex: false];
export type DefinitionField<N, V> = {
default?: V | ((node: N) => V);
validate: a.ValidateFn<Exclude<V, undefined | RegExp>>;
type?: string;
};
export type Definition<N extends Node = Node> = {
indices: {
[K in NodeKeys<N>]: DefinitionIndex<N[K] extends Node | (Node | null)[] | undefined | null ? true : false>;
};
fields: {
[F in NodeKeys<N>]: DefinitionField<N, N[F]>;
};
finalValidate?: a.ValidateFn<N>;
insertionValidate?: (node: N, key: string | number, listKey: string | null, parent: ParentsOf<N>) => string | null;
};
export type Definitions = {
[N in Node as `${N['type']}`]: Definition<N>;
};
export declare const definitions: Definitions;
export declare const getFieldsOf: ({ indices }: Definition, type: "builder" | "visitor") => string[];
export declare const visitorKeys: Readonly<Record<string, readonly string[] | undefined>>;
export {};