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

Flow: Fix generating arrow functions with param #4504

Merged
merged 3 commits into from Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions packages/babel-generator/src/generators/methods.js
Expand Up @@ -77,8 +77,14 @@ export function ArrowFunctionExpression(node: Object) {
this.space();
}

if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
this.print(node.params[0], node);
let param;

if (
node.params.length === 1
&& t.isIdentifier(param = node.params[0])
Copy link
Member

Choose a reason for hiding this comment

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

Might be confusing to read to some but makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yeah, idk why I didn't assign it immediately. I've pushed a change for that (and extracted the type checking into a function to be explicit).

&& !(node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments)
) {
this.print(param, node);
} else {
this._params(node);
}
Expand Down
@@ -0,0 +1,7 @@
const bar1 = (x: number): string => {};
const bar2 = (x?) => {};
const bar3 = (x?: string) => {};
const bar4 = x => {};
const bar5 = (x): string => {};
const bar6 = (x: number) => {};
const bar7 = <T>(x) => {};
@@ -0,0 +1,7 @@
const bar1 = (x: number): string => {};
const bar2 = (x?) => {};
const bar3 = (x?: string) => {};
const bar4 = x => {};
const bar5 = (x): string => {};
const bar6 = (x: number) => {};
const bar7 = <T>(x) => {};
@@ -0,0 +1 @@
const x = (foo?) => {}
@@ -0,0 +1 @@
const x = (foo /*:: ?*/) => {};
@@ -0,0 +1 @@
const x = (foo: string) => {};
@@ -0,0 +1 @@
const x = (foo /*: string*/) => {};