Skip to content

Commit

Permalink
fix single-arg async arrows when retainLines=true (#8868)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-mars authored and nicolo-ribaudo committed Oct 30, 2018
1 parent e4929e1 commit de80aef
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/babel-generator/src/generators/methods.js
Expand Up @@ -111,7 +111,23 @@ export function ArrowFunctionExpression(node: Object) {
t.isIdentifier(firstParam) &&
!hasTypes(node, firstParam)
) {
this.print(firstParam, node);
if (
this.format.retainLines &&
node.loc.start.line < node.body.loc.start.line
) {
this.token("(");
if (firstParam.loc.start.line > node.loc.start.line) {
this.indent();
this.print(firstParam, node);
this.dedent();
this._catchUp("start", node.body.loc);
} else {
this.print(firstParam, node);
}
this.token(")");
} else {
this.print(firstParam, node);
}
} else {
this._params(node);
}
Expand Down
@@ -0,0 +1,11 @@
var fn = async (
arg
) => {}

async (x)
=> {}

async x => {}

async (x
) => {};
@@ -0,0 +1,3 @@
{
"retainLines": true
}
@@ -0,0 +1,11 @@
var fn = async (
arg
) => {};

async (x) =>
{};

async x => {};

async (x) =>
{};

0 comments on commit de80aef

Please sign in to comment.