Closed hawkrives closed 6 years ago
Ugh this is a tough one - the problem is around the locations of the different nodes. Although they are all correct, they break the assumption made in prettier core that all "child nodes" are exclusive and don't contain one another. So in this case, the new
node has 3 children, 2 arguments
(kind = propertylookup) and one what
(kind = class). Technically the class node encloses the 2 property lookup nodes. However, the comment functionality in prettier core makes the assumption that all child nodes of new
are exclusive, and once it sees that the // body of member function of anonymous class
comment comes after the first propertylookup
node, it also assumes it comes after the class
node (because the class
node technically starts before the propertylookup
node). Not really sure what the approach should be for this one...
Some potential options
new
arguments
loc
functions, to specifically look for anonymous classes and bump the start offset back. This would probably mean updating prettier core as well, since we would need path
to get at the parent new
node, and currently the loc
function just accepts a node
(with no way to access the parent)Wow, that really sounds tough. I’m surprised though - is this really the first time we have overlapping node locations? If yes, do you think it’ll be the only time?
I think so. Off the top of my head I don't know of anything similar to the new anonymous class syntax (and apparently javascript never has this problem)
Ok Its not pretty but I think I managed to get something along the lines of this working
or updating our loc functions, to specifically look for anonymous classes and bump the start offset back.
I'll try and post a PR at some point today
PHP: 7.0 Node: 9 prettier-php: 26c6262 prettier:
d676188
I apologize for this code, but it's in my codebase, and prettier-php told me to report it.
test.php
The problem: None of the comments within the anonymous class are printed. (The outer two comments are printed, so they're fine.)