react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / node_modules / commoner / node_modules / recast / main.js
81164 viewsvar types = require("./lib/types");1var parse = require("./lib/parser").parse;2var Printer = require("./lib/printer").Printer;34function print(node, options) {5return new Printer(options).print(node);6}78function prettyPrint(node, options) {9return new Printer(options).printGenerically(node);10}1112function run(transformer, options) {13return runFile(process.argv[2], transformer, options);14}1516function runFile(path, transformer, options) {17require("fs").readFile(path, "utf-8", function(err, code) {18if (err) {19console.error(err);20return;21}2223runString(code, transformer, options);24});25}2627function defaultWriteback(output) {28process.stdout.write(output);29}3031function runString(code, transformer, options) {32var writeback = options && options.writeback || defaultWriteback;33transformer(parse(code, options), function(node) {34writeback(print(node, options).code);35});36}3738Object.defineProperties(exports, {39/**40* Parse a string of code into an augmented syntax tree suitable for41* arbitrary modification and reprinting.42*/43parse: {44enumerable: true,45value: parse46},4748/**49* Traverse and potentially modify an abstract syntax tree using a50* convenient visitor syntax:51*52* recast.visit(ast, {53* names: [],54* visitIdentifier: function(path) {55* var node = path.value;56* this.visitor.names.push(node.name);57* this.traverse(path);58* }59* });60*/61visit: {62enumerable: true,63value: types.visit64},6566/**67* Reprint a modified syntax tree using as much of the original source68* code as possible.69*/70print: {71enumerable: true,72value: print73},7475/**76* Print without attempting to reuse any original source code.77*/78prettyPrint: {79enumerable: false,80value: prettyPrint81},8283/**84* Customized version of require("ast-types").85*/86types: {87enumerable: false,88value: types89},9091/**92* Convenient command-line interface (see e.g. example/add-braces).93*/94run: {95enumerable: false,96value: run97}98});99100101