Repository navigation
Description
Right now there are a few ways to use (non-native) async in Babel:
- Babel + regenerator: https://github.com/facebook/regenerator
- Babel + kneden: https://github.com/babel/kneden
- Babel + async-to-gen: https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-to-generator
We also had a module called async-to-module-method but it seemed weird to make it separate so I just merged that as an option in the other async plugin.
I'd like to propose we just merge everything into 1 plugin?
So in v7 it would be called @babel/plugin-async-functions and it would have an option to compile using generators (async-to-gen) and promises (using a port of this plugin + kneden).
I'd like this because regenerator has to have a runtime, it's large, and still under the BSD+Patents by FB (waiting for them to change it). If in the meantime we can get this working I'm cool with just switching it out by default and other people can opt-in to using regenerator if they want but it would be outside of our repo.
Would that be desirable? Basically for this new plugin I would want everything in fast-async that is related to compiling async to promises but nothing else (so don't need the logic for generators, or any non-spec behavior that is in nodent). Let me know if that would be cool, or if we can get someone else in the community to do this if you are busy
So the new version wouldn't need all of https://github.com/MatAtBread/nodent or https://github.com/MatAtBread/nodent-runtime or the options
Activity
matAtWork commentedon Nov 14, 2017
That would be reasonably easy to do - basically invoke nodent with the options preset to those you require (fast-async already only uses
Promises, and has thespecoption which disables any extensions and uses default semantics).hzoo commentedon Nov 14, 2017
Ok great, then we can deprecate https://github.com/babel/kneden and just add tests to make this happen. Do you want to make the PR?
I was thinking we just rename https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-to-generator to
transform-async-functionsand then add a promise optionhzoo commentedon Nov 14, 2017
And the promise only version has no runtime right? Basically I would want the plugin to be a straight translation from async functions to native promises?
This would definetely lead to a lot more usage so will probably expect some more issue reports to Babel 😛 , I can add you as collab to assign if you want as well!
matAtWork commentedon Nov 14, 2017
If you specify the option
noRuntime.specoption sets the ones you want. See https://github.com/MatAtBread/fast-async/blob/master/plugin.js#L67A lot of the plugin code will disappear if you don't want to support the various options at all, including the runtime. Transpilation itself is not very quick (unlike runtime), so it's worth leaving in the test for whether
asyncorawaitare actually in the AST.The requirement to avoid a runtime is a common one (which is one reason there's an option in nodent), but the code generated can be quite a bit bigger and sometimes a little slower. The nodent runtime is pretty small (150 lines un-minified) and in a separate repo/npm (see https://github.com/MatAtBread/nodent-runtime) and so can easily be
required without much hassle by the generated code, or injected by the transpiler. Much as I understand the attraction of a "pure" transpiler, avoiding the runtime has some real penalties.I might have some time to at least get this up and running. Do you have a repo within the babel project I can contribute to?
hzoo commentedon Nov 14, 2017
We would move it into the monorepo but I can make a repo in the org if you want. We can support adding it to babel-runtime or polyfill if it's better too (same as regenerator-runtime in that case).
https://github.com/babel/kneden was the old repo that was transferred.
matAtWork commentedon Nov 14, 2017
Your choice. Just let me know where you want to code to live.
hzoo commentedon Nov 14, 2017
Eventually I want it to be in https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-async-to-generator as an option so if you want to just make a PR there that would work. Let me know if you have trouble setting up the repo or you can join our slack slack.babeljs.io, or i'l make a new repo
https://github.com/babel/babel/blob/9ae23639ad12898e3bf2dff7b1d1a9fbd2be15fe/packages/babel-plugin-transform-async-to-generator/src/index.js#L8
Could just make an option and do
if (promise)and runhzoo commentedon Nov 14, 2017
And can we only use just the transform part? We want native promise, no built-in modification (Function.prototype), pure transform
I think we only need the parts in https://github.com/MatAtBread/nodent-compiler/blob/master/lib/arboriculture.js because we won't need to reparse or reprint? Also in order to handle new proposals correctly we would need this modification
tannerlinsley commentedon Nov 14, 2017
This would be the greatest thing ever.
hzoo commentedon Nov 14, 2017
Hmm yeah looking into the code more, would that be cool to just port https://github.com/MatAtBread/nodent-compiler/blob/master/lib/arboriculture.js into a standalone babel plugin since we don't need any of the options (specificallly we hardcode to
spec: truewhich iswrapAwait,noRuntimeandpromisesandes6targetsince we don't need the arrow function transform or the parser/generator parts.We can start with just the basic thing as you said (just use those options) but not sure that is the most viable for us long term
MatAtBread commentedon Nov 15, 2017
I might look into refactoring the code so the generator mode is in a separate file (you'll notice it's a small amount of code as async to generator is trivial), however I don't think I'll maintain a fork that diverges significantly from the base compiler as I have a large number of users who don't use Babel or fast-async, and when issues do arise, fixing complex transforms in two projects is an unnecessary burden.
With a bit of work i can probably work it so you
require('nodent/arboriculture'), avoiding all the options, CLI, parsing and output code. How does that fit?matAtWork commentedon Nov 15, 2017
...or if I get that far create a new module
nodent-transformerwhich you can reference.hzoo commentedon Nov 15, 2017
We can definitely maintain the fork transform if it's just the the transform code, but ya the separate file/pkg can probably work fine as a start! I think we'll have the opposite problem eventually if we do try to make this default since we have a lot of users that would want this 😛, especially if this can become a regenerator replacement
matAtWork commentedon Nov 15, 2017
Leave it with me - I'll slice up the code so you can require the minimal bits you want. I should get a chance to have a look this week.
MatAtBread commentedon Nov 16, 2017
@hzoo Just took a look at the code (it's been a while...), and the current implementation needs access to:
Are these components available to plugins? Where would I find out about the API?
18 remaining items
matAtWork commentedon Nov 30, 2017
Well, that's the beauty of open source, you don't have to "allow" anyone anything, and they don't have to ask permission.
Looking at that issue, I can't quite work out what the status is - should I add the requirement there, or create a new ticket?
Do you have any thoughts on how you want this to be (finally) packaged? Be aware that I'm not really a Babel user, so I don't know what fits in with your user base.
matAtWork commentedon Dec 1, 2017
Just running my tests against old Nodes, and in v0.10, babylon fails:
I presume
make bootstrapdid the compilation of babylon (and the other packages), but seems to have left this ES6 construct in place?To be clear - I've made no changes to any Babel source files, this is straight from the monorepo.
hzoo commentedon Dec 1, 2017
Oh I think it's since we started compiling babylon against node 4 since Node 0.10/0.12 are dropped in Babel 7.
matAtWork commentedon Dec 2, 2017
@hzoo - how do you want this to be integrated into babel. As a package in the monorepo? An independent plugin?
hzoo commentedon Dec 2, 2017
The ideal eventually is a package in the monorepo, I was thinking we would make a package called
@babel/plugin-transform-async-functionswith some options, one being promises and another generators (the current plugin which is named async-to- generators), so if you want to start with a separate repo that's fine but yeah would be good as a PR to the existing pluginmatAtWork commentedon Dec 11, 2017
@hzoo - I'm 99% done and have some test harness code that works fine with 7.0.0-beta34. My final 'decision' is whether to fork
arboriculture.js, leaving one innodent-compilerand a new one inbabel-transform-async-to-promises, or move it into a new module (nodent-transform) so it can berequired from both modules.The pros and cons for me are simple, but might conflict with your medium-term goals.
acornand it's own helper routines which are small/simple with no external dependancy.Do you have a preference?
ljharb commentedon Dec 11, 2017
It seems like a shared module is much better; babel could always fork that later if it becomes necessary.
hzoo commentedon Dec 12, 2017
Ok let's go with the shared/separate module for now, I agree with ljharb. Not really sure what to think until it works and people are using it etc I think?
matAtWork commentedon Dec 13, 2017
That's fine. The real question is whether you think anyone in Babel will want to put in the time and effort to migrate to the core Babel functions and migrate any fixes. If yes, a fork is what you want to enable those changes (which I won't make in the original as it create an unnecessary dependency on babel-core, babylon. generate), if no, you'll benefit for any fixes I make in the future. You can of course fork it at any point in the future.
MatAtBread commentedon Dec 19, 2017
Finally got around to forking Babel and adding the new transform (see https://github.com/MatAtBread/babel/tree/nodent-transform-async/packages/babel-plugin-transform-async-to-promises)
I'm having an issue with the name resolution:
....works, but
...does not (it does with transform-async-to-generators). Is there some other reference to the plugin name I'm not aware of that makes the path resolution work?
MatAtBread commentedon Dec 19, 2017
@hzoo - Any ideas on the issue above ^^ ?
hzoo commentedon Dec 19, 2017
Hmm it should link correctly.. although if the other one works I would be ok with PRing the existing plugin and renaming it to
transform-async-functionsOh well the folder name is hyphened and it's fine. It should be ok with the test format so no need to worry?
hzoo commentedon Dec 19, 2017
I would just make the pr and we can work from there?
MatAtBread commentedon Dec 20, 2017
@hzoo - here you go babel/babel#7076
...let's continue the conversation there.