Fix Flow generic comment positioning#5290
Merged
j-f1 merged 2 commits intoprettier:masterfrom Oct 25, 2018
Merged
Conversation
j-f1
requested changes
Oct 24, 2018
Member
j-f1
left a comment
There was a problem hiding this comment.
Awesome!
Can you add one more test to make sure calls without arguments work too?
Input:
foo/*:: <bar>*/()Output:
foo/*:: <bar> */();
j-f1
reviewed
Oct 24, 2018
lydell
reviewed
Oct 25, 2018
lydell
approved these changes
Oct 25, 2018
j-f1
approved these changes
Oct 25, 2018
Member
|
Thanks for contributing! |
ikatyang
added a commit
to ikatyang/prettier
that referenced
this pull request
Oct 25, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a bug in Prettier where Flow generic comments get repositioned, breaking Flow's syntax. An example:
Currently, Prettier will rewrite this (source) as:
This PR attempts to fix this behavior. One issue that I ran into was dealing with the Flow parser's AST that it generates from the comment syntax. Code like this:
gets turned into this (source):
I wasn't able to find an easy way to have Prettier reliably traverse the code backward to see if the annotation is inside a comment block. Since it's not in the AST at all (source), the options seem limited, particularly since the comment block could have begun many lines above the type definition. For this reason, this PR only ensures the correct behavior for non-inline type definitions like these for the Babylon parser. The Flow parser's behavior here remains the same as before.
docs/directory)