react / wstein / node_modules / browserify / node_modules / module-deps / node_modules / detective / node_modules / escodegen / bin / escodegen.js
80559 views#!/usr/bin/env node1/*2Copyright (C) 2012 Yusuke Suzuki <[email protected]>34Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are met:67* Redistributions of source code must retain the above copyright8notice, this list of conditions and the following disclaimer.9* Redistributions in binary form must reproduce the above copyright10notice, this list of conditions and the following disclaimer in the11documentation and/or other materials provided with the distribution.1213THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"14AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY17DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES18(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;19LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND20ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF22THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/2425/*jslint sloppy:true node:true */2627var fs = require('fs'),28path = require('path'),29root = path.join(path.dirname(fs.realpathSync(__filename)), '..'),30esprima = require('esprima'),31escodegen = require(root),32optionator = require('optionator')({33prepend: 'Usage: escodegen [options] file...',34options: [35{36option: 'config',37alias: 'c',38type: 'String',39description: 'configuration json for escodegen'40}41]42}),43args = optionator.parse(process.argv),44files = args._,45options,46esprimaOptions = {47raw: true,48tokens: true,49range: true,50comment: true51};5253if (files.length === 0) {54console.log(optionator.generateHelp());55process.exit(1);56}5758if (args.config) {59try {60options = JSON.parse(fs.readFileSync(args.config, 'utf-8'));61} catch (err) {62console.error('Error parsing config: ', err);63}64}6566files.forEach(function (filename) {67var content = fs.readFileSync(filename, 'utf-8'),68syntax = esprima.parse(content, esprimaOptions);6970if (options.comment) {71escodegen.attachComments(syntax, syntax.comments, syntax.tokens);72}7374console.log(escodegen.generate(syntax, options));75});76/* vim: set sw=4 ts=4 et tw=80 : */777879