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

8.4 - Property hooks #1143

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

genintho
Copy link
Collaborator

@genintho genintho commented Dec 1, 2024

@genintho genintho changed the title [WIP] - 8.4 Property hooks 8.4 Property hooks Dec 2, 2024
@genintho genintho changed the title 8.4 Property hooks 8.4 - Property hooks Dec 2, 2024
@genintho
Copy link
Collaborator Author

genintho commented Dec 2, 2024

@cseufert I would love your feedback on this PR.

@genintho genintho marked this pull request as ready for review December 2, 2024 04:48
Copy link
Collaborator

@cseufert cseufert left a 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be changed?

Copy link
Collaborator Author

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.

types.d.ts Outdated Show resolved Hide resolved
"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"`;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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,
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

@genintho genintho requested review from cseufert and czosel December 4, 2024 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8.4: property hooks
2 participants