acorn(1)

🌸 acorn(1) β€” like, the manual page, bestie 🌸

okay so before we even get into it: this is the page for acorn, section 1 of the manual (that's the "user commands" section, iykyk). If you've ever needed to peek inside a JavaScript file and see what the parser actually thinks it is, this is your girl. ✨


πŸ’– NAME πŸ’–

acorn β€” parse a JavaScript file 🌈


✨ SYNOPSIS ✨

acorn [--ecma3 | --ecma5 | --ecma6 | --ecma7 | ... | --ecma2015 |
      --ecma2016] [--tokenize] [--locations] [--allow-hash-bang]
      [--compact] [--silent] [--module] [--help] [--] [infile]

πŸ¦‹ DESCRIPTION πŸ¦‹

acorn is a lil command-line utility that parses a JavaScript file for you. That's it, that's the whole vibe. πŸ’…

You hand it your input file as an argument, and the utility spits out the syntax tree as JSON data. No cap. Straight-up JSON, right there in your terminal, ready to be piped into whatever nonsense you're building. πŸ‘‘


πŸŽ€ OPTIONS πŸŽ€

  • --ecma3, --ecma5, --ecma6, --ecma7, ..., --ecma2015, --ecma2016 β€” picks which ECMAScript version to parse with. The default is version 7, so if you say nothing, you get 7. Iconic default honestly. ⭐
  • --tokenize β€” flips on tokenizer mode of the parser. Not the full tree, just the tokens. πŸ“
  • --locations β€” this one's a baddie fr. It attaches a "loc" object to each node, with "start" and "end" sub-objects, and each of those contains the one-based line and zero-based column numbers, in {line, column} form. Yes bestie, one-based lines but zero-based columns. That's just how it is. πŸ’€
  • --allow-hash-bang β€” if you enable this, it skips the leading hashbang line. For all my script-with-a-#!-on-top girlies. 🫢
  • --compact β€” no whitespace is used in the AST output. Tiny output, zero breathing room, maximum density. πŸ”₯
  • --silent β€” do not output the AST at all. It just returns the exit status. Quiet queen behaviour. 🀫
  • --module β€” tells acorn the code shouldn't be parsed as a script, but as a module instead. Heads up, this actually changes things: it influences global strict mode and the 'import' and 'export' declarations. So like, not a cosmetic flag, it's giving real consequences. πŸ‘€
  • --help β€” prints the usage information and quits. Your lil escape hatch when you're lost. πŸ™ˆ

🧚 lil reminder bestie: there's a bare -- in the synopsis, and it's not decorative β€” use it to mark the end of options before your infile.
πŸ’œ Also: the positional arg is infile, aka the JavaScript file you want parsed. Don't forget to actually give it one.

okay so that's the whole page!! go parse something slay. πŸ’–βœ¨

signing off: this was acorn(1) β€” from the acorn manual, dated 1782392480. mwah, talk later bestie πŸŽ€πŸ’…

πŸ“¦ where this page comes from