astx
Version:
super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring
95 lines (94 loc) • 5.98 kB
TypeScript
import * as b from '@babel/types';
import * as t from 'ast-types';
import * as k from 'ast-types/gen/kinds';
declare type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;
export declare type Location = {
start?: number | null;
end?: number | null;
startLine?: number | null;
startColumn?: number | null;
endLine?: number | null;
endColumn?: number | null;
};
export interface Debugger {
(formatter: any, ...args: any[]): void;
enabled?: boolean;
}
export interface NodePath<N = Node, V = any> {
value: V;
node: N;
parentPath: NodePath | null;
parent: NodePath | null;
name: string | number | null;
get<K extends keyof V>(key: K): V[K] extends Node ? NodePath<V[K], V[K]> : NodePath<N, V[K]>;
get(...names: (string | number)[]): NodePath;
each(callback: (path: NodePath<N, ArrayElement<V>>) => any, context?: any): void;
map<E>(callback: (path: NodePath<N, ArrayElement<V>>) => E, context?: any): E[];
filter(callback: (path: NodePath<N, ArrayElement<V>>) => boolean, context?: any): NodePath<N, ArrayElement<V>>[];
shift(): ArrayElement<V> | undefined;
unshift(...args: ArrayElement<V>[]): number;
push(...args: ArrayElement<V>[]): number;
pop(): ArrayElement<V> | undefined;
insertAt(index: number, ...args: ArrayElement<V>[]): this;
insertBefore(...args: V[]): NodePath;
insertAfter(...args: V[]): NodePath;
replace(replacement?: V, ...more: V[]): NodePath<N, V>[];
prune(): NodePath | undefined;
}
export declare function pathIs<N, T>(path: NodePath<N>, namedType: {
check: (value: any) => value is T;
}): path is NodePath<N, T>;
export declare type NodeType = keyof typeof t.namedTypes | b.Node['type'] | keyof b.Aliases;
export declare type Node = b.Node | k.NodeKind;
export declare type Comment = b.Comment | k.CommentKind;
export declare type File = b.File | k.FileKind;
export declare type Block = b.Block | k.BlockStatementKind | k.ProgramKind | k.TSModuleBlockKind;
export declare type Expression = b.Expression | k.ExpressionKind;
export declare type Statement = b.Statement | k.StatementKind;
export declare type AssignmentPattern = b.AssignmentPattern | k.AssignmentPatternKind;
export declare type BooleanLiteral = b.BooleanLiteral | k.BooleanLiteralKind;
export declare type CallExpression = b.CallExpression | k.CallExpressionKind;
export declare type ClassDeclaration = b.ClassImplements | k.ClassImplementsKind;
export declare type ClassImplements = b.ClassImplements | k.ClassImplementsKind;
export declare type ClassProperty = b.ClassProperty | k.ClassPropertyKind;
export declare type ExportDeclaration = b.ExportDeclaration | k.ExportDeclarationKind;
export declare type ExportDefaultSpecifier = b.ExportDefaultSpecifier | k.ExportDefaultSpecifierKind;
export declare type ExportNamedDeclaration = b.ExportNamedDeclaration | k.ExportNamedDeclarationKind;
export declare type ExportSpecifier = b.ExportSpecifier | k.ExportSpecifierKind;
export declare type ExpressionStatement = b.ExpressionStatement | k.ExpressionStatementKind;
export declare type FlowType = b.FlowType | k.FlowTypeKind;
export declare type TSType = b.TSType | k.TSTypeKind;
export declare type Function = b.Function | k.FunctionKind;
export declare type FunctionTypeParam = b.FunctionTypeParam | k.FunctionTypeParamKind;
export declare type GenericTypeAnnotation = b.GenericTypeAnnotation | k.GenericTypeAnnotationKind;
export declare type Identifier = b.Identifier | k.IdentifierKind;
export declare type ImportDefaultSpecifier = b.ImportDefaultSpecifier | k.ImportDefaultSpecifierKind;
export declare type ImportDeclaration = b.ImportDeclaration | k.ImportDeclarationKind;
export declare type ImportNamespaceSpecifier = b.ImportNamespaceSpecifier | k.ImportNamespaceSpecifierKind;
export declare type ImportSpecifier = b.ImportSpecifier | k.ImportSpecifierKind;
export declare type JSXAttribute = b.JSXAttribute | k.JSXAttributeKind;
export declare type JSXElement = b.JSXElement | k.JSXElementKind;
export declare type JSXExpressionContainer = b.JSXExpressionContainer | k.JSXExpressionContainerKind;
export declare type JSXIdentifier = b.JSXIdentifier | k.JSXIdentifierKind;
export declare type JSXText = b.JSXText | k.JSXTextKind;
export declare type NumericLiteral = b.NumericLiteral | k.NumericLiteralKind;
export declare type ObjectExpression = b.ObjectExpression | k.ObjectExpressionKind;
export declare type ObjectMethod = b.ObjectMethod | k.ObjectMethodKind;
export declare type ObjectProperty = b.ObjectProperty | k.ObjectPropertyKind | k.PropertyKind;
export declare type ObjectTypeProperty = b.ObjectTypeProperty | k.ObjectTypePropertyKind;
export declare type RegExpLiteral = b.RegExpLiteral | k.RegExpLiteralKind;
export declare type StringLiteral = b.StringLiteral | k.StringLiteralKind;
export declare type SpreadElement = b.SpreadElement | k.SpreadElementKind;
export declare type TemplateLiteral = b.TemplateLiteral | k.TemplateLiteralKind;
export declare type TSExpressionWithTypeArguments = b.TSExpressionWithTypeArguments | k.TSExpressionWithTypeArgumentsKind;
export declare type TSFunctionType = b.TSFunctionType | k.TSFunctionTypeKind;
export declare type TSPropertySignature = b.TSPropertySignature | k.TSPropertySignatureKind;
export declare type TSTypeAnnotation = b.TSTypeAnnotation | k.TSTypeAnnotationKind;
export declare type TSTypeParameter = b.TSTypeParameter | k.TSTypeParameterKind;
export declare type TSTypeReference = b.TSTypeReference | k.TSTypeReferenceKind;
export declare type TypeAnnotation = b.TypeAnnotation | k.TypeAnnotationKind;
export declare type TypeParameter = b.TypeParameter | k.TypeParameterKind;
export declare type TypeParameterInstantiation = b.TypeParameterInstantiation | k.TypeParameterInstantiationKind;
export declare type VariableDeclarator = b.VariableDeclarator | k.VariableDeclaratorKind;
export declare type VariableDeclaration = b.VariableDeclaration | k.VariableDeclarationKind;
export {};