UNPKG

astx

Version:

super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring

43 lines (42 loc) 1.67 kB
import { NodeType, NodePath, Node, Debugger } from '../types'; import * as t from 'ast-types'; import { Backend } from '../backend/Backend'; export declare type RootCompileOptions = { where?: { [captureName: string]: (path: NodePath) => boolean; }; debug?: Debugger; backend: Backend; }; export declare type CompileOptions = { where?: { [captureName: string]: (path: NodePath) => boolean; }; debug: Debugger; backend: Backend; }; export declare type Captures = Record<string, NodePath>; export declare type ArrayCaptures = Record<string, NodePath[]>; export declare type StringCaptures = Record<string, string>; export declare type MatchResult = { captures?: Captures; arrayCaptures?: ArrayCaptures; stringCaptures?: StringCaptures; } | null; export declare function mergeCaptures(...results: MatchResult[]): MatchResult; export declare type PredicateMatcher = { match: (path: NodePath, matchSoFar: MatchResult) => boolean; nodeType?: keyof typeof t.namedTypes | (keyof typeof t.namedTypes)[]; }; export interface CompiledMatcher { pattern: NodePath<Node, Node> | NodePath<Node, Node>[]; optional?: true; placeholder?: string; arrayPlaceholder?: string; restPlaceholder?: string; flag?: '$Ordered' | '$Unordered'; match: (path: NodePath, matchSoFar: MatchResult) => MatchResult; nodeType?: NodeType | NodeType[]; } export declare function convertPredicateMatcher(pattern: NodePath, matcher: PredicateMatcher, { debug }: CompileOptions): CompiledMatcher; export default function compileMatcher(path: NodePath, rootCompileOptions: RootCompileOptions): CompiledMatcher;