Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Oct 24, 2022
1 parent 43f826f commit bf82944
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions packages/babel-generator/src/generators/methods.ts
Expand Up @@ -184,7 +184,7 @@ export function ArrowFunctionExpression(
!this.format.retainLines &&
node.params.length === 1 &&
isIdentifier((firstParam = node.params[0])) &&
!hasTypes(node, firstParam)
!hasTypesOrComments(node, firstParam)
) {
this.print(firstParam, node);
this._noLineTerminator = _noLineTerminator;
Expand All @@ -205,7 +205,7 @@ export function ArrowFunctionExpression(
this.print(node.body, node);
}

function hasTypes(
function hasTypesOrComments(
node: t.ArrowFunctionExpression,
param: t.Identifier,
): boolean {
Expand All @@ -214,6 +214,9 @@ function hasTypes(
node.returnType ||
node.predicate ||
param.typeAnnotation ||
param.optional
param.optional ||
// Flow does not support `foo /*: string*/ => {};`
param.leadingComments?.length ||
param.trailingComments?.length
);
}
@@ -1,3 +1,3 @@
async /** @type {any} */arg => {};
async arg /* trailing */ => {};
async /** @type {any} */arg /* trailing */ => {};
async ( /** @type {any} */arg) => {};
async (arg /* trailing */) => {};
async ( /** @type {any} */arg /* trailing */) => {};
@@ -1,6 +1,6 @@
const x = async
/* some comment*/
a => {
const x = async (
// some comment
a) => {
return foo(await a);
};
function foo(a) {
Expand Down

0 comments on commit bf82944

Please sign in to comment.