fkling

Astexplorer

A web tool to explore the ASTs generated by various parsers.
Under MIT License
By fkling

javascript babel postcss parser ast ast-explorer jscodeshift

AST explorer



Paste or drop code into the editor and inspect the generated AST on https://astexplorer.net/


The AST explorer provides following code parsers:



Experimental / custom syntax

Depending on the parser settings, it not only supports ES5/CSS3 but also



Transforms

Since future syntax is supported, the AST explorer is a useful tool for
developers who want to create AST transforms. In fact, following transformers
are included so you can prototype your own plugins:



More Features

Contributions

I'm happy about any feedback, feature request or PR to make this tool as useful
as possible!

How to add a new parser


  1. Go to website/.

  2. Install the new parser as dependency: yarn add theParser (or npm install -S theParser)

  3. Copy one of the existing examples in src/parsers/{language}.


  4. Adjust the code as necessary:




  5. Update metadata.



  6. Load the right parser (loadParser).

  7. Call the right parsing method with the right/necessary options in parse.

  8. Implement the nodeToRange method (this is for highlighting).

  9. Implement the getNodeName method (this is for quick look through the tree).

  10. Implement opensByDefault method for auto-expansion of specific properties.

  11. Define _ignoredProperties set or implement forEachProperty generator method for filtering.

  12. Provide a renderSettings method if applicable.


How to add a new transformer

  1. Go to website/.

  2. Install the new transformer as dependency.

  3. Copy one of the existing examples in src/parsers/{language}/transformers.


  4. Adjust the code as necessary:




  5. Update metadata and defaultParserID.



  6. Load the right transformer (loadTransformer).

  7. Call the transformation method in transform.

  8. Change sample transformation code in codeExample.txt.


Build your own version for development

  1. Clone the repository.

  2. Go to website/.

  3. Install all dependencies with yarn install (you can run npm install as
    well).


Run yarn run build for the final minimized version.
Run yarn run watch for incremental builds.


Run yarn start to start a simple static webserver.