import fs from "fs" ; import * as types from "ast-types" ; import { parse } from "./lib/parser" ; import { Printer } from "./lib/printer" ; import { Options } from "./lib/options" ; export { parse , types , } ; /**
 * Traverse and potentially modify an abstract syntax tree using a
 * convenient visitor syntax:
 *
 *   recast.visit(ast, {
 *     names: [],
 *     visitIdentifier: function(path) {
 *       var node = path.value;
 *       this.visitor.names.push(node.name);
 *       this.traverse(path);
 *     }
 *   });
 */ export { visit } from "ast-types" ; /**
 * Options shared between parsing and printing.
 */ export { Options } from "./lib/options" ; /**
 * Reprint a modified syntax tree using as much of the original source
 * code as possible.
 */ export function print ( node , options ? ) { return new Printer ( options ) . print ( node ) ; } /**
 * Print without attempting to reuse any original source code.
 */ export function prettyPrint ( node , options ? ) { return new Printer ( options ) . printGenerically ( node ) ; } /**
 * Convenient command-line interface (see e.g. example/add-braces).
 */ export function run ( transformer , options ? ) { return runFile ( process . argv [ 2 ] , transformer , options ) ; } export interface Transformer { ( ast , callback ) : void ; } export interface RunOptions extends Options { writeback ? ( code ) : void ; } function runFile ( path , transformer , options ? ) { fs . readFile ( path , "utf-8" , function ( err , code ) { if ( err ) { console . error ( err ) ; return ; } runString ( code , transformer , options ) ; } ) ; } function defaultWriteback ( output ) { process . stdout . write ( output ) ; } function runString ( code , transformer , options ? ) { const writeback = options && options . writeback || defaultWriteback ; transformer ( parse ( code , options ) , function ( node ) { writeback ( print ( node , options ) . code ) ; } ) ; }