import astTypes = require("ast-types"); import nodePath = require("ast-types/lib/node-path"); import types = require("ast-types/lib/types"); import Collection = require("../Collection"); type ASTPath = nodePath.NodePath; type RecursiveMatchNode = | (T extends {} ? { [K in keyof T]?: RecursiveMatchNode; } : T) | ((value: T) => boolean); type ASTNode = types.ASTNode; export interface TraversalMethods { /** * Find nodes of a specific type within the nodes of this collection. */ find(type: types.Type, filter?: RecursiveMatchNode): Collection.Collection; /** * Returns a collection containing the paths that create the scope of the * currently selected paths. Dedupes the paths. */ closestScope(): Collection.Collection; /** * Traverse the AST up and finds the closest node of the provided type. */ closest(type: types.Type, filter?: RecursiveMatchNode): Collection.Collection; /** * Finds the declaration for each selected path. Useful for member expressions * or JSXElements. Expects a callback function that maps each path to the name * to look for. * * If the callback returns a falsy value, the element is skipped. */ getVariableDeclarators( nameGetter: (...args: any[]) => any, ): Collection.Collection; } export interface MutationMethods { /** * Simply replaces the selected nodes with the provided node. If a function * is provided it is executed for every node and the node is replaced with the * functions return value. */ replaceWith(nodes: T | T[] | ((path: ASTPath, i: number) => T)): Collection.Collection; /** * Inserts a new node before the current one. */ insertBefore(insert: any): Collection.Collection; /** * Inserts a new node after the current one. */ insertAfter(insert: any): Collection.Collection; remove(): Collection.Collection; } export function register(): void; export {}; // shut off automatic exporting