[Pkg-javascript-commits] [node-acorn-jsx] 23/484: Add a shell interface

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:19:59 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit 7feb14c0ea3a24af60f8b6c6f108b066023bd36b
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Wed Oct 3 11:04:26 2012 +0200

    Add a shell interface
---
 bin/acorn | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/bin/acorn b/bin/acorn
new file mode 100755
index 0000000..492805d
--- /dev/null
+++ b/bin/acorn
@@ -0,0 +1,40 @@
+#!/usr/bin/env node
+
+var path = require('path');
+var fs = require('fs');
+var acorn = require(path.join(path.dirname(fs.realpathSync(__filename)), "../acorn.js"));
+
+var infile, parsed, options = {}, silent = false, compact = false;
+
+function help(status) {
+  console.log("usage: " + path.basename(process.argv[1]) + " infile [--ecma3|--ecma5] [--strictSemicolons]");
+  console.log("        [--trackComments] [--locations] [--compact] [--silent] [--help]");
+  process.exit(status);
+}
+
+for (var i = 2; i < process.argv.length; ++i) {
+  var arg = process.argv[i];
+  if (arg == "--ecma3") options.ecmaVersion = 3;
+  else if (arg == "--ecma5") options.ecmaVersion = 5;
+  else if (arg == "--strictSemicolons") options.strictSemicolons = true;
+  else if (arg == "--trackComments") options.trackComments = true;
+  else if (arg == "--locations") options.locations = true;
+  else if (arg == "--silent") silent = true;
+  else if (arg == "--compact") compact = true;
+  else if (arg == "--help") help(0);
+  else if (arg[0] == "-") help(1);
+  else infile = arg;
+}
+
+if (!infile) help(1);
+
+try {
+  var code = fs.readFileSync(infile, "utf8");
+  parsed = acorn.parse(code, options);
+} catch(e) {
+  console.log(e.message);
+  process.exit(1);
+}
+
+if (!silent)
+  console.log(JSON.stringify(parsed, null, compact ? null : 2));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list