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

Return type of arrow func is moved to inside parens with flow comment types #2409

Closed
simonkberg opened this issue Jul 6, 2017 · 5 comments
Closed
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@simonkberg
Copy link

simonkberg commented Jul 6, 2017

Using babylon parser. Flow parser handles the unambiguous examples correctly, and throws a SyntaxError on the ambiguous one, but converts comment types to regular types. playground

Input

// @flow

// Unambiguous
const foo = (arg /*: any */) /*: Promise<any> */ => Promise.resolve(arg)
const foo = (arg) /*: Promise<any> */ => Promise.resolve(arg)

// Ambiguous
const bar = arg /*: Promise<any> */ => Promise.resolve(arg)

Output

// @flow

// Unambiguous
const foo = (arg /*: any */ /*: Promise<any> */) => Promise.resolve(arg);
const foo = (arg /*: Promise<any> */) => Promise.resolve(arg);

// Ambiguous
const bar = (arg /*: Promise<any> */) => Promise.resolve(arg);

Expected

// @flow

// Unambiguous
const foo = (arg /*: any */) /*: Promise<any> */ => Promise.resolve(arg)
const foo = (arg) /*: Promise<any> */ => Promise.resolve(arg)

// Ambiguous
const bar = (arg /*: Promise<any> */) => Promise.resolve(arg) // or throw?
@azz
Copy link
Member

azz commented Jul 6, 2017

Does babylon support flow comment types? @hzoo / @danez

@simonkberg
Copy link
Author

simonkberg commented Jul 6, 2017

Oh, doesn't seem like it: http://astexplorer.net/#/gist/13ff8d141bee632cf0535022c0a76105/cf6bb0fce2a412c616d459df6920da967dc57f38

Is there anything prettier could do here? Since the flow parser converts the comments to regular types, there is currently no safe way to use prettier with the comment syntax.

@vjeux
Copy link
Contributor

vjeux commented Jul 6, 2017

Yeah, there's another issue tracking it.

I think we should attack it from two angles:

  1. Make sure we beef up our comment logic to keep them in places where they don't change meanings
  2. When using the flow parser and if there's one type-comment in the file, then output comments instead of types.

Help is wanted for both

@azz
Copy link
Member

azz commented Jul 6, 2017

Related issues: #204, #719.

@simonkberg
Copy link
Author

Closing in favor of #719 since it already covers this particular issue

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 7, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

3 participants