Skip to content
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

transforming for await loop not supported for browser that supports it #1930

Closed
thepassle opened this issue Jan 12, 2022 · 4 comments
Closed

Comments

@thepassle
Copy link

I noticed esbuild doesnt transform for-await loops for build target safari11:

✘ [ERROR] Transforming for-await loops to the configured target environment ("safari11") is not supported yet

    app.js:3:6:
      3 │   for await (const i of a) {
        ╵       ~~~~~

However, according to both caniuse and mdn, safari11 does support for-await loops.

It made me wonder if there is a particular reason esbuild doesnt currently handle it that I might be unaware of, or is this an oversight?

Reproduction:
https://stackblitz.com/edit/node-3gwvxg?file=index.js
image

@evanw
Copy link
Owner

evanw commented Jan 12, 2022

It made me wonder if there is a particular reason esbuild doesnt currently handle it that I might be unaware of, or is this an oversight?

The reason is that it's a very obscure feature that almost no one uses and it's non-trivial to implement. I think you're the first person to ask about it. In all my time writing JavaScript professionally I've seen exactly one use of for await and it was easily replaced by a for loop containing an await inside it.

However, according to both caniuse and mdn, safari11 does support for-await loops.

My source for browser compatibility data says that they are supported in Safari 12+. I just checked Safari 11.1 on BrowserStack and for await can't even be parsed, so my compatibility data appears to be correct and MDN/Caniuse appears to be wrong. Here's a screenshot:

SyntaxError: Unexpected identifier 'await'. Expected '(' to start a for-loop header.

The simplest workaround for you is probably to just use a for loop with an await in it instead of using a for await loop.

@thepassle
Copy link
Author

The reason is that it's a very obscure feature that almost no one uses and it's non-trivial to implement. I think you're the first person to ask about it. In all my time writing JavaScript professionally I've seen exactly one use of for await and it was easily replaced by a for loop containing an await inside it.

Yeah, I definitely agree that the code that uses it could(/should) be refactored to not use a for-await loop, but unfortunately the code is not directly under our maintenance.

Interesting that both caniuse and mdn are off on this one, thanks for confirming that indeed safari11 does not support for await loops.

Thanks for the detailed and swift answer 🙂 I'll close this issue then

@LarsDenBakker
Copy link

@evanw would you consider adding an option to let these pass through uncompiled? Then at least the rest of the code could be compiled to a certain target or browser.

@evanw
Copy link
Owner

evanw commented Jan 12, 2022

Why would you want to do that? Then the code still wouldn't work in the target browser. You could run another tool (e.g. Babel/TypeScript/SWC) after esbuild to post-process the code for the target browser, but then why not have that other tool transform other syntax too? If you want to use esbuild transform away the newest syntax that your other tools don't yet support, you can still use --target=es2018 with esbuild and continue to use for await.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants