Ohm-Management - Projektarbeit B-ME
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 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. var path = require('path');
  3. var fs = require('fs');
  4. var acorn = require('./acorn.js');
  5. var infile;
  6. var forceFile;
  7. var silent = false;
  8. var compact = false;
  9. var tokenize = false;
  10. var options = {};
  11. function help(status) {
  12. var print = (status === 0) ? console.log : console.error;
  13. print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]");
  14. print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]");
  15. process.exit(status);
  16. }
  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"; }
  28. else {
  29. var match = arg.match(/^--ecma(\d+)$/);
  30. if (match)
  31. { options.ecmaVersion = +match[1]; }
  32. else
  33. { help(1); }
  34. }
  35. }
  36. function run(code) {
  37. var result;
  38. try {
  39. if (!tokenize) {
  40. result = acorn.parse(code, options);
  41. } else {
  42. result = [];
  43. var tokenizer$$1 = acorn.tokenizer(code, options), token;
  44. do {
  45. token = tokenizer$$1.getToken();
  46. result.push(token);
  47. } while (token.type !== acorn.tokTypes.eof)
  48. }
  49. } catch (e) {
  50. console.error(e.message);
  51. process.exit(1);
  52. }
  53. if (!silent) { console.log(JSON.stringify(result, null, compact ? null : 2)); }
  54. }
  55. if (forceFile || infile && infile !== "-") {
  56. run(fs.readFileSync(infile, "utf8"));
  57. } else {
  58. var code = "";
  59. process.stdin.resume();
  60. process.stdin.on("data", function (chunk) { return code += chunk; });
  61. process.stdin.on("end", function () { return run(code); });
  62. }