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

Inline comments include line break #155

Open
mgrip opened this issue Apr 26, 2018 · 9 comments
Open

Inline comments include line break #155

mgrip opened this issue Apr 26, 2018 · 9 comments
Labels
enhancement good first issue minor Minor issue - does not impact the parser too much (edge cases) question
Milestone

Comments

@mgrip
Copy link

mgrip commented Apr 26, 2018

Seems like when inline comments are parsed they include the line break - both in the comment.value and the comment.loc.end

image

@ichiriac
Copy link
Member

Not sure that's a bug as the original PHP token used for inline comments also includes the line break. The fix would be counter intuitive, to be clean it should be changed from the tokeniser.

How does it breaks something on prettier ?

@mgrip
Copy link
Author

mgrip commented Apr 26, 2018

We got around it for now by manually stripping out the line break and updating the end location (here). For reference this is the same thing in the JS parser: https://astexplorer.net/ - you can see it doesn't include the new line. Basically it throws off how core prettier assigns comments. It thinks its a leading comment for the newline instead of a trailing comment for the actual line it was written on

@mgrip
Copy link
Author

mgrip commented Apr 26, 2018

I'm fine keeping as is for now since our workaround seems pretty safe and not all that complicated. Just wanted to flag in case its something you think should actually be changed in the parser

@ichiriac
Copy link
Member

Ok, got it. In fact I try to stick to original PHP behavior, and sometimes they make strange decisions.

BTW, don't forget to strip mac & windows returns, just add another check after the first if over "\r" - so you will handle "\n", "\r\n", "\r"

I'll try to look if I can do something directly into the AST even if it would be inconsistent with tokens.

@mgrip
Copy link
Author

mgrip commented Apr 26, 2018

Ooh good call, I'll update that. And sounds good, thanks for looking into it!

@ichiriac ichiriac added enhancement good first issue minor Minor issue - does not impact the parser too much (edge cases) and removed investigating labels Jan 7, 2019
@ichiriac ichiriac added this to the 3.1.0 milestone Jan 7, 2019
@ichiriac
Copy link
Member

ichiriac commented Jan 6, 2020

Hi @mgrip - does it fixed ? If not, it may introduce breaking changes ? If yes, it should be released on 3.0.0

@mgrip
Copy link
Author

mgrip commented Jan 6, 2020

Thanks for following up @ichiriac! I've since stepped back from the prettier php project, I'll defer to @evilebottnawi or @czosel!

@czosel
Copy link
Collaborator

czosel commented Jan 6, 2020

I tried following up on this a little, but can't report anything conclusive. As far as I can tell, we're ok with the way things are currently handled, so I wouldn't prioritize this for 3.0.0.

@ichiriac
Copy link
Member

ichiriac commented Jan 8, 2020

ok @czosel, thx for the feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue minor Minor issue - does not impact the parser too much (edge cases) question
Projects
None yet
Development

No branches or pull requests

3 participants