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:
Dan Harper
2016-09-12 13:27:49 +01:00
committed by Henry Zhu
parent 5249b9d809
commit 41f2bbc104
7 changed files with 26 additions and 2 deletions

View File

@@ -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;
}