Flow: Fix generating arrow functions with param (#4504)
* transform-flow-comments, single arrow param support #4503 * further tests for printing single arrow func param flow code * cleanup
This commit is contained in:
@@ -77,8 +77,10 @@ export function ArrowFunctionExpression(node: Object) {
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
|
||||
this.print(node.params[0], node);
|
||||
const firstParam = node.params[0];
|
||||
|
||||
if (node.params.length === 1 && t.isIdentifier(firstParam) && !hasTypes(node, firstParam)) {
|
||||
this.print(firstParam, node);
|
||||
} else {
|
||||
this._params(node);
|
||||
}
|
||||
@@ -89,3 +91,7 @@ export function ArrowFunctionExpression(node: Object) {
|
||||
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
function hasTypes(node, param) {
|
||||
return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user