-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support transforming async generators like @babel/plugin-proposal-async-generator-functions does #2780
Comments
It's interesting to hear that someone actually uses this feature for something. This JavaScript feature is so obscure that I haven't yet found any code that uses it, which is why I haven't implemented this transform yet. I tried bundling the npm package What is your use case for this feature? Can you provide an example of real published code that makes use of this feature? |
The idea is that the zone will propagate across the async generator call, zone.js can't handle native async await because that's hard coded to use the native browser promise and it can't be monkey patched by it. |
Is this just a hypothetical concern? Can you provide an example of production code that uses this language feature? |
You can see an MWE of this here, checkout the main.ts file and the vite config. |
Did you mean to post a link? I'm not sure where "here" is, sorry. |
Oops. Yeah, here is the link: https://stackblitz.com/edit/vitejs-vite-k5ghhm?file=src/main.ts |
Also, you can see the hack used in angular cli to workaround this: https://github.com/angular/angular-cli/blob/67ffa8b40be04b0e671429063810fe5f52b2043a/packages/angular_devkit/build_angular/src/babel/presets/application.ts#L232-L239 |
It looks like you posted a link to some code you just wrote to demonstrate the feature instead of posting a link to real code. So I'm guessing that means that this is just a hypothetical concern. I can try to implement this at some point, but I should also say that the priority of this still seems low given the information in this thread. |
Some real code would be Angular projects, the link I posted shows where angular-cli had to use Babel instead of just esbuild due to this. The real code I tried using Zone.js in, is properitery, which is why I posted a MWE to show the issue instead. I have actually been trying to use Zone.js to propagate async context for logging outside of Angular, with Vite & Vue instead, which is where I stumbled upon this issue. And Zone.js appears to be rather heavyweight so I'm not sure we will actually end up using it in the end. Priority is really up to you, this is just a feature request and there is a workaround using Babel. Thanks for looking into this anyhow 👍 |
For what it's worth, I just arrived here from a real-world use case. I was trying to switch from In many apps something like this would be achieved with the local |
I wanted to target older browser for my Astro project. Esbuild fails while trying to transform the generator functions @evanw. |
Workaround for Vite users: // https://github.com/evanw/esbuild/issues/2780
{
...babel({
babelConfig: {
babelrc: false,
configFile: false,
plugins: [
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-proposal-async-generator-functions"
]
},
filter: /\.(?:jsx?|tsx?|vue)$/,
}),
enforce: "post",
}, |
I'm trying to bundle https://www.npmjs.com/package/streamx with a build. esbuild errors on https://github.com/mafintosh/streamx/blob/49bf57d5b9833736b72a733e92958e0e41225f42/test/async-iterator.js#L84 bypass transforming async iterators? |
I'm using aegir to test ipfs-utils and it has this function: export default async function * globSource (cwd, pattern, options) {
// ...
} it doesn't export it at all, all other functions work properly, so I suppose async default generator function can't work |
FWIW here's an example of some real code (mine) using an async generator. The generator itself: It would be great to be able to use esbuild on my project without refactoring my code to remove the use of this language feature. |
The reasonably popular Would be great to get support for lowering them! |
gpt-tokenizer also fails when building via esbuild |
[mistaken comment; TL;DR forgot to set the target to |
You're asking why this issue was closed, but that's something that GitHub already tells you. For future reference, you can see it right above what you just posted:
|
My bad, I overlooked the close reason, and neglected to set the target environment, so I ended up with the untranspiled async iterator and thought the issue was closed due to lack of use cases. |
It would be nice to be able to have esbuild transform async generators like the babel plugin
@babel/plugin-proposal-async-generator-functions
does when native async support is disabled, that is:Currently using async generator functions with async await disabled results in an error.
This is used as a stopgap by Angular's Zone.JS so they can track async generator functions as they have no way to track native async await in the browser ATM, so they rely on down transpiling them to generators.
See: https://github.com/angular/angular-cli/blob/67ffa8b40be04b0e671429063810fe5f52b2043a/packages/angular_devkit/build_angular/src/babel/presets/application.ts#L232-L239
If esbuild supported this natively, babel wouldn't be needed here.
The text was updated successfully, but these errors were encountered: