
Show HN: Kneden – Transpile ES7 Async/await to ES6 Promise Chains (Babel Plugin) - marten-de-vries
https://github.com/marten-de-vries/kneden
======
callahad
If your target environment has promises _and_ generators available, I'm fond
of using Babel's first-party `transform-async-to-generator` plugin, which
barely alters your code's syntax: [https://babeljs.io/docs/plugins/transform-
async-to-generator...](https://babeljs.io/docs/plugins/transform-async-to-
generator/)

~~~
marten-de-vries
Author of Kneden here. If generators are avaiable, you should probably indeed
be using this.

If they are not though, Kneden will generate code that's probably more
readable and smaller (no polyfill except for a Promise implementation).

~~~
david-given
Is Babel's generator transpiling support good enough to allow this to be
transpiled down to ES5?

~~~
s986s
If your looking for es5 promises are much easier to polyfill and much more
competitive than generators

~~~
wging
Can you clarify what you mean by 'competitive'? Are you talking about
performance, or some other measure of quality?

------
emergentcypher
This is why the JS ecosystem frustrates me. We're talking about an ES7 -> ES6
transpilation, which I will then have to transpile again to ES5. And that's
before we even hit the VM/JIT.

~~~
krisdol
Or don't use undeveloped language features until they're available. I'm very
happy with the subset of ES6 available on node, but I never shared the
complaints many people have of "callback hell". It's really not difficult to
deal with and adding promises doesn't magically make it better, I've seen my
share of promise hell.

~~~
jey
Yes, except that the asynchronous hells finally go away when you start using
async/await. Makes code easy to read, write, and reason about.

------
Hurtak
The last time I tried async/await with Babel I had huge problem that my code
was very hard to debug. When runtime error occurred it did not show any useful
information, like error line number, and thanks to transforming and
regenarator-runtime wrapping of my code, it was nearly impossible to step
through the code in any meaningful way, so I had to fallback to console log
driven development.

Maybe something changed since the last time I tried, or perhaps i mis-
configured something? How are error messages and debugging with this plugin?

~~~
marten-de-vries
The end result is more comprehendable than the regenerator output, but the
code is still modified quite a bit to fit into a Promise chain structure. Some
statement types (like loops) more than others (like a simple function call). I
haven't paid special attention to source maps and the like yet apart from what
Babel itself generates (which is quite a bit), so there's probably still quite
a bit to gain here.

------
thomasjonas
I really hope it won't happen and we've learned from the past, but is it
possible we'll soon be transpiling for different browsers and using
conditional comments for loading the right version?

