Search code examples
javascriptreflectionspidermonkey

Is there an engine-agnostic Reflect.parse?


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) {
  ....
}(this));

Solution

  • 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