What does HackerNews think of estree?

The ESTree Spec

#61 in JavaScript
#5 in Parsing
This is a powerful idea! If I understand Monocle's use case, JS has similar AST parsing and code generation tools that are used broadly. There may be some ideas to learn from that community.

JS AST specs: estree [0] and babel's AST [1]

Parsers: babel [2], acorn [3], or espree [4]

Transformers: babel, recast [5], or jscodeshift [6]

Codegen: babel or escodegen [7]

[0] https://github.com/estree/estree

[1] https://babeljs.io/docs/en/babel-parser#output

[2] https://github.com/babel/babel

[3] https://github.com/acornjs/acorn

[4] https://github.com/eslint/espree

[5] https://github.com/benjamn/recast

[6] https://github.com/facebook/jscodeshift

[7] https://github.com/estools/escodegen

Well, you can already commit an AST if you really want to: just serialise the ESTree[0] to JSON and commit that.

But committing unreadable JSON files to version control rather defeats most of the features of version control.

[0] https://github.com/estree/estree

For JavaScript, the Esprima parser [1] converts JavaScript to what appears to be a JSON format. It's formalized by the Estree spec [2]. You can try it out here [3]. JSON is just regular JavaScript data structures (maps and lists). If you want type safety, there are Typescript definitions, but you could ignore that.

Another example: Go has a parser and AST that comes with the standard library, which again is just using regular Go data structures (structs and interfaces). If you wanted to write a macro preprocessor, using the built-in parser seems like a much better idea than string manipulation.

So, I'm wondering if there's anything more to the way Common Lisp does it?

[1] http://esprima.org/ [2] https://github.com/estree/estree [3] http://esprima.org/demo/parse.html

For JavaScript we have https://github.com/estree/estree as our JS AST spec for parsers like esprima, acorn, babylon (under a config flag), etc.

JSCS (https://github.com/jscs-dev/node-jscs) (now merged with ESLint) started a CST project as well https://github.com/cst/cst to help deal with autoformatting by adding whitespace type nodes.

Currently the community has a lot of interest in https://github.com/jlongster/prettier which just simply reprints the file from scratch in a consistent way (posted in https://news.ycombinator.com/item?id=13365470).

We also have https://github.com/benjamn/recast to help source to source transformations and https://github.com/facebook/jscodeshift.

I would like that too! I don't think there have been any features added since the last one with Babel 6 release.

Yeah there's multiple JavaScript parsers: esprima, acorn, shift, babylon (uglify has their own parser I think).

There was an effort to standardize as well in https://github.com/estree/estree.

EDIT:

However, in Babel 6 there were a few (nice) incompatible changes to the AST which was unfortunate for interop and other tools (https://github.com/babel/babel-eslint had to make a lot of changes).

I don't want to speak for him, but I think a lot of the decisions to fork (parser, etc) at the time were most likely made like mentioned above to move faster. And at the time, Sebastian was basically the only one working on it. Maybe more context from his post: https://medium.com/@sebmck/2015-in-review-51ac7035e272#.qcyz...

Tools like acorn[1] and Esprima[2] can parse the JavaScript source and output an ESTree compliant syntax tree.

Then you can traverse it and modify it like any other AST.

[1] https://github.com/ternjs/acorn [2] http://esprima.org/ [3] https://github.com/estree/estree

If the language has a large enough community, someone's bound to come up with an AST format and parser/generator themselves.

JavaScript has https://github.com/estree/estree for example. I've written a (very experimental) S-expression syntax for JavaScript around it here https://github.com/anko/eslisp