[Pkg-javascript-commits] [node-acorn-jsx] 376/484: Add support for running just the tokenizer to the bin/acorn script.
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:58 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 af0debc8499c0e2521610e7ad67ec7d47058d0c7
Author: Nick Fitzgerald <fitzgen at gmail.com>
Date: Fri Jan 2 16:07:03 2015 -0800
Add support for running just the tokenizer to the bin/acorn script.
---
bin/acorn | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/bin/acorn b/bin/acorn
index 2a226da..ca6e32a 100755
--- a/bin/acorn
+++ b/bin/acorn
@@ -4,12 +4,12 @@ var path = require("path");
var fs = require("fs");
var acorn = require("../acorn.js");
-var infile, parsed, options = {}, silent = false, compact = false;
+var infile, parsed, tokens, options = {}, silent = false, compact = false, tokenize = false;
function help(status) {
var print = (status == 0) ? console.log : console.error;
print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6] [--strictSemicolons]");
- print(" [--locations] [--compact] [--silent] [--help] [--] infile");
+ print(" [--tokenize] [--locations] [--compact] [--silent] [--help] [--] infile");
process.exit(status);
}
@@ -25,16 +25,29 @@ 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 if (arg == "--tokenize") tokenize = true;
else help(1);
}
try {
var code = fs.readFileSync(infile, "utf8");
- parsed = acorn.parse(code, options);
+
+ if (!tokenize)
+ parsed = acorn.parse(code, options);
+ else {
+ var get = acorn.tokenize(code, options);
+ tokens = [];
+ while (true) {
+ var token = get();
+ tokens.push(token);
+ if (token.type.type == "eof")
+ break;
+ }
+ }
} catch(e) {
console.log(e.message);
process.exit(1);
}
if (!silent)
- console.log(JSON.stringify(parsed, null, compact ? null : 2));
+ console.log(JSON.stringify(tokenize ? tokens : 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