Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always retain lines for async arrow #11836

Merged
merged 6 commits into from Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/babel-generator/src/generators/methods.js
Expand Up @@ -109,7 +109,8 @@ export function ArrowFunctionExpression(node: Object) {
if (
node.params.length === 1 &&
t.isIdentifier(firstParam) &&
!hasTypes(node, firstParam)
!hasTypes(node, firstParam) &&
!node.async
) {
if (
this.format.retainLines &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move node.async to here

this.format.retainLines || node.async

so we are instructing that if async presents, we try to retain lines and print ( if the function body is in different lines with the async arrow.

Expand Down
@@ -0,0 +1,10 @@
const x = async (
// some comment
a
) => {
return foo(await a);
};

function foo(a) {
return a;
}
@@ -0,0 +1 @@
{}
@@ -0,0 +1,8 @@
const x = async ( // some comment
a) => {
return foo(await a);
};

function foo(a) {
return a;
}