Fix printing of single-param async arrow function with comments (#13136)

* Fix printing of async arrow function with a single param and comments

* Add OVERWRITE support to generator tests
This commit is contained in:
Nathan Walters 2021-04-12 07:10:02 -07:00 committed by GitHub
parent 672a58660f
commit 30f93b36a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 4 deletions

View File

@ -119,9 +119,11 @@ export function ArrowFunctionExpression(
) { ) {
if ( if (
(this.format.retainLines || node.async) && (this.format.retainLines || node.async) &&
node.loc && ((node.loc &&
node.body.loc && node.body.loc &&
node.loc.start.line < node.body.loc.start.line node.loc.start.line < node.body.loc.start.line) ||
firstParam.leadingComments?.length ||
firstParam.trailingComments?.length)
) { ) {
this.token("("); this.token("(");
if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) { if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) {

View File

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

View File

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

View File

@ -819,7 +819,13 @@ suites.forEach(function (testSuite) {
console.log(`New test file created: ${expected.loc}`); console.log(`New test file created: ${expected.loc}`);
fs.writeFileSync(expected.loc, result.code); fs.writeFileSync(expected.loc, result.code);
} else { } 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);
}
} }
} }
} }