MatAtBread / fast-async

605 stars 21 forks source link

Use Promise from babel-transform-runtime? #44

Closed trusktr closed 6 years ago

trusktr commented 6 years ago

babel-transform-runtime transpiles Promise in source code to _Promise which is ultimately the Promise polyfill from core-js.

Is it possible to make fast-async use transform-runtime promises?

Currently, when I set the fast-async option compiler.promises to true, it result in Promise appearing in the output.

Then, I thought that if I change the ordering of plugins so that fast-async runs before transform-runtime, that transform-runtime would handle these Promises, but this isn't the case. transform-runtime is leaving those in the output unpolyfilled. If I try swapping the order of the two plugins, no luck.

If I set compiler.promises to false, then I see Nodent's Promise polyfill included (which is extra duplication).


A possible workaround could be that I can have a separate Babel step using only fast-async to convert async functions on first pass with promises: true, then the second pass of Babel would catch those Promises. This will obviously take more time, but the output will be better (I think?).

trusktr commented 6 years ago

Alright, I got it to work by having a first babel pass compile async functions with fast-async, then the second pass ponyfills the Promises with transform-runtime.

However, the Zousan promise polyfill is still in the code base. I suppose I might as well use it then.

Would be great if you could figure a way to trim out the unused polyfill and use the one Babel already provides!

trusktr commented 6 years ago

babel 440ms - 1.8x slower

Nevermind! I'll take Nodent's then.

matAtWork commented 6 years ago

I could create an option to allow you to specify the global symbol to be used instead of "Promise", but I've not had a realistic use-case to date where it matters. Zousan is pretty fast anyway :)

matAtWork commented 6 years ago

Closing as no action to take. Please re-open if you have a recommendation on how to progress this.