diff options
author | Michaël Zasso <targos@protonmail.com> | 2019-01-31 08:36:48 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2019-02-08 15:34:10 +0100 |
commit | 582c12260ed99ebe7710894c2dab29435b1bebdc (patch) | |
tree | f5168c77fd86c471951f9a68ac9cb0cfb8812003 /deps/acorn/acorn/dist/bin.js | |
parent | 39171d755d3e81f03ac0fd716cd80c2e20882fb6 (diff) | |
download | android-node-v8-582c12260ed99ebe7710894c2dab29435b1bebdc.tar.gz android-node-v8-582c12260ed99ebe7710894c2dab29435b1bebdc.tar.bz2 android-node-v8-582c12260ed99ebe7710894c2dab29435b1bebdc.zip |
deps: update acorn to 6.0.7
acorn and acorn-walk are now published as two different packages. Put
them both in subdirectories of `deps/acorn`.
Adapt the REPL's recoverable error detection to use the new API for
extending acorn parsers.
PR-URL: https://github.com/nodejs/node/pull/25844
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'deps/acorn/acorn/dist/bin.js')
-rw-r--r-- | deps/acorn/acorn/dist/bin.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/deps/acorn/acorn/dist/bin.js b/deps/acorn/acorn/dist/bin.js new file mode 100644 index 0000000000..f8961ce87e --- /dev/null +++ b/deps/acorn/acorn/dist/bin.js @@ -0,0 +1,68 @@ +'use strict'; + +var path = require('path'); +var fs = require('fs'); +var acorn = require('./acorn.js'); + +var infile; +var forceFile; +var silent = false; +var compact = false; +var tokenize = false; +var options = {}; + +function help(status) { + var print = (status === 0) ? console.log : console.error; + print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]"); + print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]"); + process.exit(status); +} + +for (var i = 2; i < process.argv.length; ++i) { + var arg = process.argv[i]; + if ((arg === "-" || arg[0] !== "-") && !infile) { infile = arg; } + else if (arg === "--" && !infile && i + 2 === process.argv.length) { forceFile = infile = process.argv[++i]; } + else if (arg === "--locations") { options.locations = true; } + else if (arg === "--allow-hash-bang") { options.allowHashBang = true; } + 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 if (arg === "--module") { options.sourceType = "module"; } + else { + var match = arg.match(/^--ecma(\d+)$/); + if (match) + { options.ecmaVersion = +match[1]; } + else + { help(1); } + } +} + +function run(code) { + var result; + try { + if (!tokenize) { + result = acorn.parse(code, options); + } else { + result = []; + var tokenizer$$1 = acorn.tokenizer(code, options), token; + do { + token = tokenizer$$1.getToken(); + result.push(token); + } while (token.type !== acorn.tokTypes.eof) + } + } catch (e) { + console.error(e.message); + process.exit(1); + } + if (!silent) { console.log(JSON.stringify(result, null, compact ? null : 2)); } +} + +if (forceFile || infile && infile !== "-") { + run(fs.readFileSync(infile, "utf8")); +} else { + var code = ""; + process.stdin.resume(); + process.stdin.on("data", function (chunk) { return code += chunk; }); + process.stdin.on("end", function () { return run(code); }); +} |