The acorn javaScript parser
For some projects it might be required to parse javaScript, often doing so might be a task that is done my a javaScript engine, but sometimes on might want to parse javaScript with javaScript. A popular and well know project for doing just that is acorn.
Getting started
Just like any other node.js project I just created a new folder, did an npm init, and installed the latest version of acorn. As of this writing the latest version of acorn is 5.3.0.
|
|
I then also made a demos folder, and made my first demo called basic.js. It is a usual practice of mine to start out with a demo like that when trying out a project of any kind.
|
|
When calling this script from the command line I end up getting this:
|
|
So acorn will give me an array of objects in a body property that is all the content of my javaScript, broken down into objects that give me useful info like the start, and end character position.