Skip to content

WIP: feat: basic async await support

username-removed-498219 requested to merge dariocravero/buble:async-await into master

Have you guys considered supporting async await? I figured that I'd kickstart the conversation with some code :). It's a very naive initial take at it that already works. I'd like to follow an approach like kneden compiling async/await to promises. Thoughts?

EDIT: Just submitted a second pass at it which supports multi-line functions mixing await and regular statements.

@Rich-Harris there's a weird thing going on with the output of the last test case:

input: `async function f() { await a(); thing(); await a2(); stuff(); await a3(); await a4(); }`,
     output: `function f() { return Promise.resolve().then(function() { return a(); }) .then(function() { thing(); }) .then(function() { return a2(); }) .then(function() { stuff(); }) .then(function() { return a3(); }) .then(function() { return a4(); }).then(function() {}) }`
   }

For some reason, the output adds a space before the next .then. I.e., return a(); }) .then(function() { thing(); }) should read return a(); }).then(function() { thing(); }).

The final statement is still valid though but it's just odd to have that space there :/. Any thoughts on why that might be happening?

Merge request reports