Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bin.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. var path = require('path');
  3. var fs = require('fs');
  4. var acorn = require('./acorn.js');
  5. function _interopNamespaceDefault(e) {
  6. var n = Object.create(null);
  7. if (e) {
  8. Object.keys(e).forEach(function (k) {
  9. if (k !== 'default') {
  10. var d = Object.getOwnPropertyDescriptor(e, k);
  11. Object.defineProperty(n, k, d.get ? d : {
  12. enumerable: true,
  13. get: function () { return e[k]; }
  14. });
  15. }
  16. });
  17. }
  18. n.default = e;
  19. return Object.freeze(n);
  20. }
  21. var acorn__namespace = /*#__PURE__*/_interopNamespaceDefault(acorn);
  22. var inputFilePaths = [], forceFileName = false, fileMode = false, silent = false, compact = false, tokenize = false;
  23. var options = {};
  24. function help(status) {
  25. var print = (status === 0) ? console.log : console.error;
  26. print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]");
  27. print(" [--tokenize] [--locations] [--allow-hash-bang] [--allow-await-outside-function] [--compact] [--silent] [--module] [--help] [--] [<infile>...]");
  28. process.exit(status);
  29. }
  30. for (var i = 2; i < process.argv.length; ++i) {
  31. var arg = process.argv[i];
  32. if (arg[0] !== "-" || arg === "-") { inputFilePaths.push(arg); }
  33. else if (arg === "--") {
  34. inputFilePaths.push.apply(inputFilePaths, process.argv.slice(i + 1));
  35. forceFileName = true;
  36. break
  37. } else if (arg === "--locations") { options.locations = true; }
  38. else if (arg === "--allow-hash-bang") { options.allowHashBang = true; }
  39. else if (arg === "--allow-await-outside-function") { options.allowAwaitOutsideFunction = true; }
  40. else if (arg === "--silent") { silent = true; }
  41. else if (arg === "--compact") { compact = true; }
  42. else if (arg === "--help") { help(0); }
  43. else if (arg === "--tokenize") { tokenize = true; }
  44. else if (arg === "--module") { options.sourceType = "module"; }
  45. else {
  46. var match = arg.match(/^--ecma(\d+)$/);
  47. if (match)
  48. { options.ecmaVersion = +match[1]; }
  49. else
  50. { help(1); }
  51. }
  52. }
  53. function run(codeList) {
  54. var result = [], fileIdx = 0;
  55. try {
  56. codeList.forEach(function (code, idx) {
  57. fileIdx = idx;
  58. if (!tokenize) {
  59. result = acorn__namespace.parse(code, options);
  60. options.program = result;
  61. } else {
  62. var tokenizer = acorn__namespace.tokenizer(code, options), token;
  63. do {
  64. token = tokenizer.getToken();
  65. result.push(token);
  66. } while (token.type !== acorn__namespace.tokTypes.eof)
  67. }
  68. });
  69. } catch (e) {
  70. console.error(fileMode ? e.message.replace(/\(\d+:\d+\)$/, function (m) { return m.slice(0, 1) + inputFilePaths[fileIdx] + " " + m.slice(1); }) : e.message);
  71. process.exit(1);
  72. }
  73. if (!silent) { console.log(JSON.stringify(result, null, compact ? null : 2)); }
  74. }
  75. if (fileMode = inputFilePaths.length && (forceFileName || !inputFilePaths.includes("-") || inputFilePaths.length !== 1)) {
  76. run(inputFilePaths.map(function (path) { return fs.readFileSync(path, "utf8"); }));
  77. } else {
  78. var code = "";
  79. process.stdin.resume();
  80. process.stdin.on("data", function (chunk) { return code += chunk; });
  81. process.stdin.on("end", function () { return run([code]); });
  82. }