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

Transforms async: async in objects to shorthand async for old platforms #3910

Open
jorenbroekema opened this issue Sep 12, 2024 · 2 comments

Comments

@jorenbroekema
Copy link

jorenbroekema commented Sep 12, 2024

function foo(async) {
  const obj = { async: async };
  return obj;
}
foo(5);

The above pattern should not be transformed at all.

Actual behavior:

function foo(async) {
  const obj = { async };
  return obj;
}
foo(5);

Reproduce (after creating a foo.js file locally): npx esbuild foo.js --outfile=_foo.js --target=es6

Real world use case: https://github.com/microsoft/tslib/blob/main/tslib.js#L359
TS helper that gets injected in many many bundles, so when transpiling it with ESBuild this should remain intact, else it does not work in old JavaScript sandboxes such as the one that is used by Figma Plugins.

This issue is very specific to the "async" keyword, which isn't technically a reserved keyword in the same way that "await" is, because its meaning (async) can always be determined by its context to whether it's a variable or keyword. It's a bit "special" in that sense, and I'm guessing this is why in old JS engines it creates the error:
Screenshot 2024-09-12 at 14 09 34

@evanw
Copy link
Owner

evanw commented Sep 12, 2024

this is why in old JS engines it creates the error

Please be specific. What specific JS engine (name and version)? If you're using an unusual JS engine that esbuild doesn't support, you can turn off support for this shorthand syntax with --supported:object-extensions=false.

I thought Figma plugins used QuickJS, but QuickJS appears to work fine. At least (function foo(async) { return {async} })(5) works fine on http://numcalc.com/ which is linked from https://bellard.org/quickjs/ as an online demo of QuickJS.

@jorenbroekema
Copy link
Author

Please be specific. What specific JS engine (name and version)?

I'm not exactly sure, all I know is that it needs me to transpile to es6 and that it gives super cryptic errors when it's running something that it doesn't support 😓 I haven't been able to find more information on this sandboxed env that they use, so your guess is as good as mine. I'll try to ask around and see if they can point me to more specifics about what they're using.

Thanks for the tip on --supported:object-extensions=false, I'll try that!

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

2 participants