-
Notifications
You must be signed in to change notification settings - Fork 72
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
8.4 - Property hooks #1143
base: main
Are you sure you want to change the base?
8.4 - Property hooks #1143
Conversation
@cseufert I would love your feedback on this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very close, thanks for getting this working.
I noticed a couple of things, the major one being making the hooks an empty list rather than null, and having the constructor param last, rather than in-between existing params.
{ | ||
parser: { | ||
version: "8.1", | ||
suppressErrors: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because the array of error added to the AST is just gibberish. Only the first error is relevant: once the parser get confused/lost then it just create noise. It is very distracting/confusing when working on thigs and trying to understand what test fails and why.
"kind": "program", | ||
} | ||
`; | ||
exports[`Test classes Test that readonly method parameters are throwing errors 1`] = `"readonly properties can be used only on class constructor on line 3"`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to the change you commented in the class.test file https://github.com/glayzzle/php-parser/pull/1143/files#r1865229710
Instead of letting the parser getting lost and generate gibberish errors, the exception is fired and serialized, using toThrowErrorMatchingSnapshot
.
@@ -28,6 +29,7 @@ module.exports = Statement.extends( | |||
readonly, | |||
nullable, | |||
type, | |||
hooks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably make sense to put hooks last as this would be less breaking of a change for existing code. Also making the default [] would make the type signature simpler, and reduce ambiguity between an empty list and null, as an empty property list is not valid syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the hooks
parameter at the end of the list would be inconsistent with how things have been done so far.
The PR introducing support for typed class constant added type "in the middle". https://github.com/glayzzle/php-parser/pull/1136/files#diff-33d9ef64a624f7abad7378a94559475184322ac87b7c864326beea672657adbcR34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cseufert I do not think it is possible to put hooks as the last parameters: when we create a node, the parameter docs
and location
are passed in by some other layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@czosel any opinion on this?
Fixes #1142
RFC - https://wiki.php.net/rfc/property-hooks
Official documentation - https://www.php.net/manual/en/language.oop5.property-hooks.php