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

Conversation

danharper
Copy link
Member

Q A
Bug fix? yes
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes
Fixed tickets #4503, #4211
License MIT
Doc PR -

Fixes:

# const x = (foo: string) => {};
- const x = foo => {};
+ const x = (foo /*: string*/) => {};
# const x = (foo?) => {};
- const x = foo => {};
+ const x = (foo /*:: ?*/) => {};

I also found just using syntax-flow wouldn't print out types/optionals for arrow functions with a single param. e.g. all of these:

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) => {};

(only when they have a single param) output:

const bar1 = x => {};
const bar2 = x => {};
const bar3 = x => {};
const bar4 = x => {};
const bar5 = x => {};
const bar6 = x => {};
const bar7 = x => {};

The output now correctly matches the input.

@codecov-io
Copy link

codecov-io commented Sep 12, 2016

Current coverage is 88.32% (diff: 100%)

Merging #4504 into master will increase coverage by <.01%

@@             master      #4504   diff @@
==========================================
  Files           194        194          
  Lines         13609      13612     +3   
  Methods        1426       1427     +1   
  Messages          0          0          
  Branches       3145       3146     +1   
==========================================
+ Hits          12020      12023     +3   
  Misses         1589       1589          
  Partials          0          0          

Powered by Codecov. Last update d2d34ba...cc5ef50


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).

@hzoo
Copy link
Member

hzoo commented Sep 12, 2016

Awesome

@hzoo hzoo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Sep 12, 2016
@hzoo hzoo added this to the Next Patch milestone Sep 12, 2016
@danez
Copy link
Member

danez commented Sep 12, 2016

👍 Thanks alot

@hzoo hzoo merged commit 41f2bbc into babel:master Sep 12, 2016
@hzoo
Copy link
Member

hzoo commented Sep 12, 2016

🎉 great stuff

panagosg7 pushed a commit to panagosg7/babel that referenced this pull request Jan 17, 2017
* transform-flow-comments, single arrow param support babel#4503

* further tests for printing single arrow func param flow code

* cleanup
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants