mozilla/sweet.js — pull request #201 by natefaubion (2014-01-15 02:33:57+00:00)
Title: More compiler options

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](https://github.com/Constellation/escodegen/wiki/API).

### `-b, --better-hygiene`

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:

```js
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:

```js
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](https://github.com/Constellation/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!