index.d.ts 1.4 KB

12345678910111213141516171819202122232425
  1. import * as t from '@babel/types';
  2. export declare type NodeType<type extends string> = type extends keyof t.Aliases ? t.Aliases[type] : Extract<t.Node, {
  3. type: type;
  4. }>;
  5. export declare type SimpleFunction<TKey extends string, TState> = (node: NodeType<TKey>, state: TState) => void;
  6. export declare type SimpleVisitors<TState = void> = {
  7. [key in keyof t.Aliases | t.Node['type']]?: SimpleFunction<key, TState> | {
  8. enter?: SimpleFunction<key, TState>;
  9. exit?: SimpleFunction<key, TState>;
  10. };
  11. };
  12. export declare function simple<TState = void>(visitors: SimpleVisitors<TState>): (node: t.Node, state: TState) => void;
  13. export declare type AncestorFunction<TKey extends string, TState> = (node: NodeType<TKey>, state: TState, ancestors: t.Node[]) => void;
  14. export declare type AncestorVisitor<TState = void> = {
  15. [key in keyof t.Aliases | t.Node['type']]?: AncestorFunction<key, TState> | {
  16. enter?: AncestorFunction<key, TState>;
  17. exit?: AncestorFunction<key, TState>;
  18. };
  19. };
  20. export declare function ancestor<TState = void>(visitors: AncestorVisitor<TState>): (node: t.Node, state: TState) => void;
  21. export declare type RecursiveVisitors<TState = void> = {
  22. [key in keyof t.Aliases | t.Node['type']]?: (node: NodeType<key>, state: TState, recurse: (node: t.Node) => void) => void;
  23. };
  24. export declare function recursive<TState = void>(visitors: RecursiveVisitors<TState>): (node: t.Node, state: TState) => void;