ariya / ama

Ask me anything!
29 stars 1 forks source link

What sparked your interest in learning about parsers and ultimately creating Esprisma? #28

Closed cem2ran closed 8 years ago

cem2ran commented 8 years ago

Alternative title: What was the motivation behind Esprisma?

ariya commented 8 years ago

Necessity is the mother of invention.

Back in 2011, I wanted to perform a static analysis on JavaScript programs using JavaScript. Before I announced Esprima, my choices were pretty limited. I could use JSLint but its parser was (and still is) too intertwined with its linting code. An alternative would be UglifyJS (the old one, not the recent version 2), however its syntax format was essentially "values in array" and it was very hard to work with. Finally there was Reflect.js, but at that time it was not mature enough, failing some real-world libraries I threw at it. There were some other alternatives I have explored but every one of them did not pass my criteria:

This was why Esprima was born. I am not a computer scientist (see #21 for the details) so I just picked a syntax tree format resembling the SpiderMonkey Parser API (now consolidated as ESTree). Performance is important, during Esprima development I investigated and documented a few JavaScript performance tricks, from fixed object structure, profile-guided reordering to trie-like decision speed-up. While it is far from perfect, Esprima is equipped with all kind of tests to ensure its compliance and correctness, from over 1,300 unit tests to various forms of regression tests. And of course, one line item in its release checklist is to verify that the performance does not regress.

In short, I built it because I needed to scratch my own itch.

Thank you @cem2ran!