Skip to content

Commit edf2c39

Browse files
committed
Add command-line parser for Node.js.
http://code.google.com/p/esprima/issues/detail?id=18
1 parent ab541af commit edf2c39

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

bin/esparse.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
/*
3+
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
* Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
18+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
/*jslint sloppy:true node:true */
27+
28+
var fs = require('fs'),
29+
esprima = require('esprima'),
30+
files = process.argv.splice(2);
31+
32+
if (files.length === 0) {
33+
console.log('Usage:');
34+
console.log(' esparse file.js');
35+
process.exit(1);
36+
}
37+
38+
files.forEach(function (filename) {
39+
var content = fs.readFileSync(filename, 'utf-8');
40+
console.log(JSON.stringify(esprima.parse(content), null, 4));
41+
});

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"description": "ECMAScript parsing infrastructure for multipurpose analysis tool",
44
"homepage": "http://esprima.org",
55
"main": "esprima.js",
6+
"bin": {
7+
"esparse": "./bin/esparse.js"
8+
},
69
"version": "0.0.0",
710
"maintainers": [{
811
"name": "Ariya Hidayat",

0 commit comments

Comments
 (0)