Unary async arrow misprinted as concise async arrow when the binding identifier has leading comments
See original GitHub issueBug Report
- I would like to work on a fix!
Current behavior
Input Code
await knex.transaction(async (/** @type {any} */ trx) => {
});
is compiled to:
"use strict";
await knex.transaction(async
/** @type {any} */
trx => {});
and Node.JS throws so error:
SyntaxError: missing ) after argument list at Module._compile (internal/modules/cjs/loader.js:723:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.<anonymous> (/workspace/src/index.js:30:38) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
Expected behavior
My source code should be compiled to this one without breaking async (/** comments */ param) => ...
:
"use strict";
await knex.transaction(async (/** @type {any} */ trx) => {});
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
babel.config.js
{
"presets": [
[
"@babel/env",
{
"targets": {
"node": 10
},
"useBuiltIns": "usage",
"corejs": 3
}
]
]
}
Environment
- Babel version(s): v7.12.10
- Node/npm version: Node 10/yarn 1.22.5
- OS: macOS 11.0.1
- Monorepo: no
- How you are using Babel:
@babel/cli
- Typescript: 4.1.3
Possible Solution
Additional context
I use Typescript JSDoc comments.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Developers - Unary async arrow misprinted as concise ...
Unary async arrow misprinted as concise async arrow when the binding identifier has leading comments.
Read more >Syntax for an async arrow function - javascript
Async arrow functions look like this for multiple arguments passed to it: ... an arrow expression, the function in this answer is not...
Read more >15 ECMAScript Language: Functions and Classes
It is a Syntax Error if BoundNames of FormalParameters contains any duplicate elements. ... 15.9 Async Arrow Function Definitions.
Read more >async function expression - JavaScript - MDN Web Docs
An async function expression can be used as an IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined. See...
Read more >Airbnb JavaScript Style Guide()
Types; References; Objects; Arrays; Destructuring; Strings; Functions; Arrow Functions; Classes & Constructors; Modules; Iterators and Generators ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the pointers! Excited to make my first contribution to Babel - I opened up a PR at #13136.
Re:
yarn && make bootstrap
, it looks likemake bootstrap
already runsyarn install
- it could save a small amount of time for future recipients of these instructions to just have folks runmake bootstrap
🙂Thanks!
The problem is likely in https://github.com/babel/babel/blob/672a58660f0b15691c44582f1f3fdcdac0fa0d2f/packages/babel-generator/src/generators/methods.ts#L115-L141, where we decide how to print the arrow function parameters.
If it helps, you can reproduce it with this code:
If it is the first time that you contribute to Babel, follow these steps: (you need to have
make
andyarn
available on your machine)git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
yarn && make bootstrap
make watch
(ormake build
whenever you change a file)packages/babel-generator/test/fixtures/comments
(onlyinput.js
;output.js
will be automatically generated)yarn jest babel-generator
to run the testsoutput.js
files and run the tests againOVERWRITE=true yarn jest babel-generator
and they will be automatically updated.make test
to run all the testsgit push
and open a PR!