3 var path = require('path');
4 var fs = require('fs');
5 var acorn = require('./acorn.js');
7 var infile, forceFile, silent = false, compact = false, tokenize = false;
10 function help(status) {
11 var print = (status === 0) ? console.log : console.error;
12 print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]");
13 print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]");
17 for (var i = 2; i < process.argv.length; ++i) {
18 var arg = process.argv[i];
19 if ((arg === "-" || arg[0] !== "-") && !infile) { infile = arg; }
20 else if (arg === "--" && !infile && i + 2 === process.argv.length) { forceFile = infile = process.argv[++i]; }
21 else if (arg === "--locations") { options.locations = true; }
22 else if (arg === "--allow-hash-bang") { options.allowHashBang = true; }
23 else if (arg === "--silent") { silent = true; }
24 else if (arg === "--compact") { compact = true; }
25 else if (arg === "--help") { help(0); }
26 else if (arg === "--tokenize") { tokenize = true; }
27 else if (arg === "--module") { options.sourceType = "module"; }
29 var match = arg.match(/^--ecma(\d+)$/);
31 { options.ecmaVersion = +match[1]; }
41 result = acorn.parse(code, options);
44 var tokenizer = acorn.tokenizer(code, options), token;
46 token = tokenizer.getToken();
48 } while (token.type !== acorn.tokTypes.eof)
51 console.error(infile && infile !== "-" ? e.message.replace(/\(\d+:\d+\)$/, function (m) { return m.slice(0, 1) + infile + " " + m.slice(1); }) : e.message);
54 if (!silent) { console.log(JSON.stringify(result, null, compact ? null : 2)); }
57 if (forceFile || infile && infile !== "-") {
58 run(fs.readFileSync(infile, "utf8"));
61 process.stdin.resume();
62 process.stdin.on("data", function (chunk) { return code += chunk; });
63 process.stdin.on("end", function () { return run(code); });