Skip to content

Commit

Permalink
Fix printing of single-param async arrow function with comments (#13136)
Browse files Browse the repository at this point in the history
* Fix printing of async arrow function with a single param and comments

* Add OVERWRITE support to generator tests
  • Loading branch information
nwalters512 committed Apr 12, 2021
1 parent 672a586 commit 30f93b3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/babel-generator/src/generators/methods.ts
Expand Up @@ -119,9 +119,11 @@ export function ArrowFunctionExpression(
) {
if (
(this.format.retainLines || node.async) &&
node.loc &&
node.body.loc &&
node.loc.start.line < node.body.loc.start.line
((node.loc &&
node.body.loc &&
node.loc.start.line < node.body.loc.start.line) ||
firstParam.leadingComments?.length ||
firstParam.trailingComments?.length)
) {
this.token("(");
if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) {
Expand Down
@@ -0,0 +1,5 @@
async (/** @type {any} */ arg) => {};

async (arg /* trailing */) => {};

async (/** @type {any} */ arg /* trailing */) => {};
@@ -0,0 +1,13 @@
async (
/** @type {any} */
arg) => {};

async (arg
/* trailing */
) => {};

async (
/** @type {any} */
arg
/* trailing */
) => {};
8 changes: 7 additions & 1 deletion packages/babel-generator/test/index.js
Expand Up @@ -819,7 +819,13 @@ suites.forEach(function (testSuite) {
console.log(`New test file created: ${expected.loc}`);
fs.writeFileSync(expected.loc, result.code);
} else {
expect(result.code).toBe(expected.code);
try {
expect(result.code).toBe(expected.code);
} catch (e) {
if (!process.env.OVERWRITE) throw e;
console.log(`Updated test file: ${expected.loc}`);
fs.writeFileSync(expected.loc, result.code);
}
}
}
}
Expand Down

0 comments on commit 30f93b3

Please sign in to comment.