Take the 2-minute tour ×

Mozilla have delivered an API for parsing a Javascript module to generate an abstract syntax tree. They call it Reflect.parse.

Is there a Reflect.parse, or something similar, written as a standalone module in Javascript? something I could run on any ES5 engine to produce a syntax tree? Failing that is there a standalone tool in C++ that does this for me? Or a service?

I tried doctorjs.org for a really simple self-evaluating anonymous function and it choked. Am I doing it wrong?

(function (scope) {
share|improve this question
BTW, this has nothing whatever to do with scope. In the code snippet above, the variable scope will reference the this object of the execution context calling the (anonymous) function, which could be any object at all, or null or undefined in ES5 strict mode. It seems to be global code, so scope will reference the global object and therefore would be much better named global or GLOBAL or similar (or perhaps window, but that supposes a browser-like environment, which may not be appropriate). –  RobG Apr 24 '12 at 5:15
I'm aware, thanks Rob. –  Cheeso Apr 24 '12 at 5:18

4 Answers 4

up vote 4 down vote accepted

Check out Esprima: http://esprima.org/

A separate project that generates a similar abstract syntax tree is here: http://boshi.inimino.org/3box/PanPG/build/js_ast.html

share|improve this answer
Esprima looks very interesting. –  Cheeso Apr 24 '12 at 20:25

Try Esprima (esprima.org), a project I have started few months ago. Its AST output is compatible with Mozilla Reflect.parse, it runs almost everywhere from IE 6 to Node.js, the parser is extremely fast (the fastest among its competitor), heavily unit tested (500+ and growing) with 100% code coverage.

Esprima is ES5 compliant (including strict mode), there is even WIP for ES6 (and Harmony) features support. It is known to parse tons of JavaScript out there, from standard library such jQuery to million-lines web apps code, without any problem.

share|improve this answer
I am trying that now and it's working pretty well. –  Cheeso Apr 27 '12 at 16:24

JS.js (a Javascript interpreter written in Javascript) probably has a Javascript parser as a component, but I don't know how easy it is to get access to or use from the outside.

share|improve this answer


You can get the source and build the SpiderMonkey JavaScript standalone shell (the JS engine in Mozilla's Firefox), which will have Reflect.parse built-in, so you can make a little script wrapping SpiderMonkey's functionality that would be usable as a tool.

share|improve this answer

Your Answer


