Abstract Syntax Tree.. I always heard that compile to SpiderMonkey AST on Github.
So, is that a actual standard of JS syntax tree? And there's V8, is V8 using the same kind of AST?
How can I play with that?
An AST is the result of parsing code. For JavaScript, an AST is a JavaScript object containing a tree representation of your source. Before we use it, we have to create it. Depending on the code we are parsing, we choose the appropriate parser. Here since the code is ES5-compatible, we can choose the acorn parser.
To build an ast from code stored as a string, use ast. parse() . To turn the ast into executable code, pass it to compile() (which can also compile a string directly).
A web tool to explore the ASTs generated by various parsers. Syntax highlighting. Code Parser.
The AST is a data structure to represent the structure of your source file in a format readable by machines. Indeed, if I throw the above example in the TypeScript AST Viewer I get immediate access to the AST.
1.You can take a look at AST explorer. An online tool to explore the ASTs generated by more than 10 parsers. It is a good tool to learn AST tree of a language.
AST explorer source at Github.com.
2.Also you can paste your js code into JavaScript AST visualizer and click "show ast" button, you will see the AST visully.
demo js code:
function foo(d) { d += 3; return d+999 } function bar(d) { return d*100 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With