FunctionSource, Your Source for Developer News

Esprima: JavaScript Parser in JavaScript

Posted by Dion Almaer about a year ago on javascript parser

Ariya Hidayat has created an educational and highly performance JavaScript parser written in JavaScript itself (turtles!) called Esprima:

Like any complex parser, unit testing is an integral part of the development. To ensure faithful compatibility with Mozilla Parser API, hundreds of its tests have been imported as well. All in all, there are over a thousand tests. In addition, there is a benchmarks suite, it consists of most common JavaScript libraries out there. The performance of various web browsers running the benchmarks suite is depicted in the following chart (shorter is better). The test machine is an iMac from late 2010, with 3 GHz Intel Core i3.

The best way to try Esprima is right in the browser via the online syntax parser demo. Type in your code, and voila! Esprima will show you the corresponding syntax tree almost right away. There is also the operator precedence demo, inspired by previously similar demo.