Created by: natefaubion
This PR adds some more compiler options that I hope will be useful:
-a, --ast
This will output a JSON blob of the expanded AST. Likewise, you can get just the AST back from sweet.compile
by passing in ast: true
.
--format-indent=NUM
Pass in the number of spaces you want to use for formatting. You can control escodegen's output by passing in escodegen: { ... }
to sweet.compile
. You can find escodegen's options here.
-r, --readable-names
This is a neat experimental compiler pass that takes the globally unique identifiers sweet generates, and makes them unique per scope. This means that the hygienic tags can mostly be removed, except for cases where a var is shadowed, which then get a simpler tag based on its scope. So instead of this:
var i$793 = 1;
function foo1$794() {
var i$801 = 2;
function foo2$802() {
var i$803 = 3;
}
}
function bar1$795() {
var i$804 = 2;
}
You get this:
var i = 1;
function foo1() {
var i$2 = 2;
function foo2() {
var i$3 = 3;
}
}
function bar1() {
var i$2 = 2;
}
Uniqueness is preserved, and as far as I know, this is a totally safe, cosmetic transformation. The caveat is that it only works for ES5 code for now. That's because 98% of the work happens in escope and it doesn't support some ES6 stuff yet (arrow functions, yield expressions). So if you want to see better ES6 support, be sure to contribute back to it! Again this comes with a big fat USE AT YOUR OWN RISK disclaimer, but it seems to work pretty well for me.
Special thanks to @Constellation for making such a badass library!