Clean up previous patch

Issue #100
This commit is contained in:
Marijn Haverbeke
2014-05-15 10:38:28 +02:00
parent 31e77b975e
commit 5dcd50447b

View File

@@ -4,13 +4,10 @@ var path = require("path");
var fs = require("fs");
var acorn = require("../acorn.js");
var infile, infilecount = 0;
var options = {}, silent = false, compact = false;
var parsed;
var infile, parsed, options = {}, silent = false, compact = false;
function help(status) {
// we want to print to stderr, not stdout, on errors.
var print = (status == 0) ? console.out : console.err;
var print = (status == 0) ? console.out : console.error;
print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5] [--strictSemicolons]");
print(" [--locations] [--compact] [--silent] [--help] [--] infile");
process.exit(status);
@@ -18,16 +15,8 @@ function help(status) {
for (var i = 2; i < process.argv.length; ++i) {
var arg = process.argv[i];
if (arg[0] != "-") {
infile = arg;
++infilecount;
continue;
} else if (arg == "--") {
if (i < process.argv.length - 2) help(1); // we have too many remaining `infile`s
infile = process.argv[i + 1]; // we want the *next* argument, not the current one
++infilecount;
break;
}
if (arg[0] != "-" && !infile) infile = arg;
else if (arg == "--" && !infile && i + 2 == process.argv.length) infile = process.argv[++i];
else if (arg == "--ecma3") options.ecmaVersion = 3;
else if (arg == "--ecma5") options.ecmaVersion = 5;
else if (arg == "--strictSemicolons") options.strictSemicolons = true;
@@ -35,12 +24,9 @@ for (var i = 2; i < process.argv.length; ++i) {
else if (arg == "--silent") silent = true;
else if (arg == "--compact") compact = true;
else if (arg == "--help") help(0);
else help(1); // we already took care of all arguments without a starting dash
else help(1);
}
// test against counter: we want exactly 1 file. Any more or less should error.
if (infilecount !== 1) help(1);
try {
var code = fs.readFileSync(infile, "utf8");
parsed = acorn.parse(code, options);