BVB Source Codes

reactide Show acorn.js Source code

Return Download reactide: download acorn.js Source code - Download reactide Source code - Type:.js
  1. import {basename} from "path"
  2. import {readFileSync as readFile} from "fs"
  3. import * as acorn from "acorn"
  4.  
  5. let infile, forceFile, silent = false, compact = false, tokenize = false
  6. const options = {}
  7.  
  8. function help(status) {
  9.   const print = (status == 0) ? console.log : console.error
  10.   print("usage: " + basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7]")
  11.   print("        [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]")
  12.   process.exit(status)
  13. }
  14.  
  15. for (let i = 2; i < process.argv.length; ++i) {
  16.   const arg = process.argv[i]
  17.   if ((arg == "-" || arg[0] != "-") && !infile) infile = arg
  18.   else if (arg == "--" && !infile && i + 2 == process.argv.length) forceFile = infile = process.argv[++i]
  19.   else if (arg == "--ecma3") options.ecmaVersion = 3
  20.   else if (arg == "--ecma5") options.ecmaVersion = 5
  21.   else if (arg == "--ecma6") options.ecmaVersion = 6
  22.   else if (arg == "--ecma7") options.ecmaVersion = 7
  23.   else if (arg == "--locations") options.locations = true
  24.   else if (arg == "--allow-hash-bang") options.allowHashBang = true
  25.   else if (arg == "--silent") silent = true
  26.   else if (arg == "--compact") compact = true
  27.   else if (arg == "--help") help(0)
  28.   else if (arg == "--tokenize") tokenize = true
  29.   else if (arg == "--module") options.sourceType = 'module'
  30.   else help(1)
  31. }
  32.  
  33. function run(code) {
  34.   let result
  35.   if (!tokenize) {
  36.     try { result = acorn.parse(code, options) }
  37.     catch(e) { console.error(e.message); process.exit(1) }
  38.   } else {
  39.     result = []
  40.     let tokenizer = acorn.tokenizer(code, options), token
  41.     while (true) {
  42.       try { token = tokenizer.getToken() }
  43.       catch(e) { console.error(e.message); process.exit(1) }
  44.       result.push(token)
  45.       if (token.type == acorn.tokTypes.eof) break
  46.     }
  47.   }
  48.   if (!silent) console.log(JSON.stringify(result, null, compact ? null : 2))
  49. }
  50.  
  51. if (forceFile || infile && infile != "-") {
  52.   run(readFile(infile, "utf8"))
  53. } else {
  54.   let code = ""
  55.   process.stdin.resume()
  56.   process.stdin.on("data", chunk => code += chunk)
  57.   process.stdin.on("end", () => run(code))
  58. }
  59.  
downloadacorn.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top