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:
parent
672a58660f
commit
30f93b36a2
@ -119,9 +119,11 @@ export function ArrowFunctionExpression(
|
||||
) {
|
||||
if (
|
||||
(this.format.retainLines || node.async) &&
|
||||
node.loc &&
|
||||
((node.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("(");
|
||||
if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) {
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
async (/** @type {any} */ arg) => {};
|
||||
|
||||
async (arg /* trailing */) => {};
|
||||
|
||||
async (/** @type {any} */ arg /* trailing */) => {};
|
||||
13
packages/babel-generator/test/fixtures/comments/async-arrow-single-param-with-comments/output.js
vendored
Normal file
13
packages/babel-generator/test/fixtures/comments/async-arrow-single-param-with-comments/output.js
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
async (
|
||||
/** @type {any} */
|
||||
arg) => {};
|
||||
|
||||
async (arg
|
||||
/* trailing */
|
||||
) => {};
|
||||
|
||||
async (
|
||||
/** @type {any} */
|
||||
arg
|
||||
/* trailing */
|
||||
) => {};
|
||||
@ -819,7 +819,13 @@ suites.forEach(function (testSuite) {
|
||||
console.log(`New test file created: ${expected.loc}`);
|
||||
fs.writeFileSync(expected.loc, result.code);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user