Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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));
like image 546
Cheeso Avatar asked Dec 28 '22 02:12

Cheeso


2 Answers

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

like image 195
Jason Orendorff Avatar answered Dec 29 '22 16:12

Jason Orendorff


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.

like image 39
Ariya Hidayat Avatar answered Dec 29 '22 16:12

Ariya Hidayat