Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S sweet-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 62
    • Issues 62
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • sweet-js
  • sweet-core
  • Merge requests
  • !201

More compiler options

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/natefaubion/compiler-opts into master Jan 15, 2014
  • Overview 8
  • Commits 2
  • Pipelines 0
  • Changes 4

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!

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/natefaubion/compiler-opts