js-parser-discussions icon indicating copy to clipboard operation
js-parser-discussions copied to clipboard

Key Differences Between Acorn / Esprima

Open xjamundx opened this issue 9 years ago • 5 comments

I found this quote from nicholas zakas pretty interesting about why eslint couldn't use acorn directly: https://github.com/eslint/espree#frequently-asked-questions

Acorn is a great JavaScript parser that produces an AST that is compatible with Esprima. Unfortunately, ESLint relies on more than just the AST to do its job. It relies on Esprima's tokens and comment attachment features to get a complete picture of the source code. We investigated switching to Acorn, but the inconsistencies between Esprima and Acorn created too much work for a project like ESLint.

We are building on top of Acorn, however, so that we can contribute back and help make Acorn even better.

This repo should try to highlight clearly what differences exist between the various parsers, most of all of which share the same AST structure and basic API.

xjamundx avatar Sep 13 '16 20:09 xjamundx

ESTree is the standard Acorn and Esprima use. It has no notion of tokens. We had some discussions around a CST that didn't really go all that far.

mikesherov avatar Sep 13 '16 21:09 mikesherov

@mikesherov was jscs using esprima directly the whole time?

xjamundx avatar Sep 13 '16 21:09 xjamundx

Until 3.0. But a CST module was created that intelligently combined the tree with the tokens for easy manipulation, whitespace changes.

mikesherov avatar Sep 13 '16 21:09 mikesherov

This is helpful. Describes the differences between babylon and estree: https://github.com/babel/babylon#output

xjamundx avatar Sep 13 '16 21:09 xjamundx

I plan to write something for #5, I think that should help normalizing the understanding.

ariya avatar Sep 13 '16 23:09 ariya