sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.58k stars 208 forks source link

Updating codegen #742

Open disnet opened 7 years ago

disnet commented 7 years ago

I have a PR to add async/await support #741 and @slotik is working on adding type nodes to sweet's AST sweet-js/sweet-spec#4. Both of these efforts require some way of doing codegen but at the moment we are relying on shift-codegen which only supports ES2016 (no async/await). Shift-codegen will be updated to ES2017 soon but it is unlikely to get support for type annotations so what should we do?

There are a few options I can see.

  1. Fork shift-codgen and add type annotation support ourselves. This involves also forking shift-spec and shift-reducer.
  2. Write our own sweet-codegen using sweet-spec.
  3. Convert our AST to a babel AST (which supports type nodes) after expansion and let babel do our codegen.

At the moment I'm leaning towards the babel option since I think it's the least amount of work for us and often you want to use babel as a backend anyway. Arguably writing our own codgen is the best long-term since that give us the most flexibility (and it would allow us to do things like rendering syntax declarations syntax m = ctx => ...).

Thoughts? Am I forgetting an option?

/cc @gabejohnson

gabejohnson commented 7 years ago

I'd be in favor of the Babel option. Perhaps even better would be to do an AST transform instead. Then handoff to Babel. See #515 and https://github.com/shapesecurity/shift-spidermonkey-converter-js/issues/16