UNPKG

astx

Version:

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

33 lines (32 loc) 1.34 kB
import { Node, File, Statement, Expression } from '@babel/types'; import { Backend } from '../backend/Backend'; import { ParserOptions } from '@babel/parser'; import * as defaultTypes from '@babel/types'; import * as defaultGenerator from '@babel/generator'; import * as AstTypes from 'ast-types'; import { Comment, Location } from '../types'; interface Parser { parse(code: string, parserOpts?: ParserOptions): File; parseExpression(code: string, parserOpts?: ParserOptions): Expression; } declare type Generate = (node: Node) => { code: string; }; export default class BabelBackend extends Backend<Node> { readonly t: typeof AstTypes; readonly parse: (code: string) => Node; readonly parseExpression: (code: string) => Expression; readonly parseStatements: (code: string) => Statement[]; readonly generator: typeof defaultGenerator; readonly generate: Generate; readonly location: (node: Node) => Location; readonly comments: (node: Node, kind?: 'leading' | 'inner' | 'trailing') => Iterable<Comment>; constructor({ parser, parserOptions, generator, types, preserveFormat, }?: { parser?: Parser; parserOptions?: ParserOptions; generator?: typeof defaultGenerator; types?: typeof defaultTypes; preserveFormat?: 'generatorHack'; }); } export {};