About one year ago, I talked with +Hajime Morrita
and I said "The closure-compiler is very cool. But writing pass in Java & construct own compiler require a lot of time... If we can write pass in JS and re-construct own JS compiler by script, this is very exciting".
After that, I dreamed creating minimum modules and constructing JS AOT compiler with them.
At the end of last year, #Esprima
was created by +Ariya Hidayat http://esprima.org/
And I created #Escodegen
, ECMAScript code generator as backend.
GitHub is a very interesting spot... Thanks to contributions by a lot of ECMAScripters, #Escodegen
has a minifying option.https://github.com/Constellation/escodegen
Now above tools are used widely as ECMAScript transpiler infrastructure. For example,
- LLJS: new language targeting JS from Mozillahttp://mbebenita.github.com/LLJS/
- sweet.js: macro system on JS from Mozillahttps://github.com/mozilla/sweet.js
- istanbul: code coverage tool from Yahoohttps://github.com/yahoo/istanbul
- CoffeeScriptRedux: new coffee-script compiler projecthttps://github.com/michaelficarra/CoffeeScriptRedux
as their ECMAScript backend.
NOTE: blog entry about writing new programming language on the top of them (entry written in Japanese) http://blog.64p.org/entry/2012/09/08/090729
And thanks to Michael Ficarra, #Escodegen
can recognize location information attached to AST and generate source-map.
As the result, new coffee-script compiler using #Escodegcan
as backend can generate source-map.http://ryanflorence.com/2012/coffeescript-source-maps/
Finally, I created #Esmangle
: ECMAScript mangler, minifier & optimizer.
This consists of a lot of simple passes applied to AST.
We can easily write new original pass and apply it to JS AST.
Optimizer resolves fixed point of AST by iterative approach.
preserves location information correctly, we can get source-map from mangled & optimized script to original code, such as coffee-script.http://constellation.github.com/esmangle/
And I also created #Doctrine
JSDoc parser to parse JSDoc structurally. It is necessary to recognize JSDoc in AST.
I'm planning to create advanced optimization passes or type warning pass by using it.http://constellation.github.com/doctrine/demo/index.html
We almost reach JS AOT compiler written in JS. It's time to construct your own compiler in JS!