fix(match): Support empty lines and comments in match expressions (closes #1956) #2201
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.
What does this do
trailingCommaPHP
option, though the tests for comments don't use that option, so there's no test coverage for itCurrent behavior on
main
<comment>
" was not printed. Please report this error!"Hi, I've been using
prettier/plugin-php
for years, but this is my first contribution. I have no idea if I have completed all PR requirements, nor if my solution is following all of the idioms,, so please let me know and I'll glady update this.This was a pretty easy to change once I learned how the parser and printer everything fit together. The upstream parser was already including comments in the AST for
match
, but the printer was not making use of them. I tried to support empty lines and comments as they are handled for function params, and I was mostly successful. The only part that I couldn't get is comments that are followed by an empty line:Thank you!
Example 1: no comments
Input
Output
Current behavior on
main
Example 2: with comments
Input
Output
Current behavior on
main