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
Unary async arrow misprinted as concise async arrow when the binding identifier has leading comments #12500
Comments
Hey @MrEfrem! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
The problem is that Babel doesn't support compiling top-level await to CommonJS or to AMD. You can either compile to SystemJS modules, or use a bundler that supports it. (Bundlers have access to the whole module graph, so they can more easily transform top-level await). |
It isn't the top level await. Above that part of source code I have: /**
* @param {{
req: import('express').Request,
res: import('express').Response,
knex: any,
}} options
*/
const someRoute = async ({ req, res, knex }) => {
...
await knex.transaction(async (/** @type {any} */ trx) => {
...
});
...
}
export default someRoute; And it's the server side source code. I won't use any bundlers for it. I need to keep the original file tree. My workaround is: await knex.transaction(
/** @type {(trx: any) => Promise<void>} */ async (trx) => {
} then compiler doesn't break |
Changed REPL. And check REPL please. There isn't compiling to CommonJS. |
Thanks, this is indeed a bug with async (/** @type {any} */ trx) => {
}
// ->
async
/** @type {any} */
trx => {}; |
No problems. |
Just ran into this myself in the context of introducing Jest to a project - was finally able to trace this back to Babel. If anyone can point me in the right direction, I'd like to try to contribute a fix for this. |
Thanks! The problem is likely in babel/packages/babel-generator/src/generators/methods.ts Lines 115 to 141 in 672a586
If it helps, you can reproduce it with this code: const input = `
fn(async (/* comment */ x) => {})
`;
const ast = parser.parse(input);
console.log(generator.default(ast)); If it is the first time that you contribute to Babel, follow these steps: (you need to have
|
Thanks for the pointers! Excited to make my first contribution to Babel - I opened up a PR at #13136. Re: |
Oh thanks; I never updated those instructions since I wrote them the first time 😅 |
Bug Report
Current behavior
Input Code
is compiled to:
and Node.JS throws so error:
Expected behavior
My source code should be compiled to this one without breaking
async (/** comments */ param) => ...
:Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
babel.config.js
Environment
@babel/cli
Possible Solution
Additional context
I use Typescript JSDoc comments.
The text was updated successfully, but these errors were encountered: