-
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
Open
genintho
wants to merge
17
commits into
glayzzle:main
Choose a base branch
from
genintho:genintho-prop-hooks-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
8.4 - Property hooks #1143
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1af8906
consistent return value for class property parsing
genintho 140206e
x
genintho 94e57ba
simpler if/else
genintho ea00ff1
Property Hook Getter works
genintho 4b94c20
move getter into dedicated method
genintho 8bb206f
setter 1
genintho e5163cf
setter 2
genintho f165e3b
setter 3
genintho 6167638
default value
genintho f264d74
more tests
genintho 5822e0a
by ref
genintho 17f7d7d
support final on hook
genintho 4ad9385
final + abstract
genintho 3f2cfc3
interfact support
genintho 6b74685
types
genintho 55ea8e5
Extend node instead of statement
genintho 1c46c8d
hooks default to array
genintho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (C) 2024 Glayzzle (BSD3 License) | ||
* @authors https://github.com/glayzzle/php-parser/graphs/contributors | ||
* @url http://glayzzle.com | ||
*/ | ||
"use strict"; | ||
|
||
const Node = require("./node"); | ||
const KIND = "propertyhook"; | ||
|
||
/** | ||
* Defines a class property hook getter & setter | ||
* | ||
* @constructor PropertyHook | ||
* @memberOf module:php-parser | ||
* @extends {Node} | ||
* @property {string} name | ||
* @property {Boolean} isFinal | ||
* @property {Boolean} byref | ||
* @property {Parameter|null} parameter | ||
* @property {Block|Statement} body | ||
*/ | ||
module.exports = Node.extends( | ||
KIND, | ||
function PropertyHook(name, isFinal, byref, parameter, body, docs, location) { | ||
Node.apply(this, [KIND, docs, location]); | ||
this.name = name; | ||
this.byref = byref; | ||
this.parameter = parameter; | ||
this.body = body; | ||
this.isFinal = isFinal; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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
andlocation
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?
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.
Yer not last last, every node has docs and location last, this is automatically populated.
However if 3rd party code is replacing/creating new AST nodes, then this will cause some undefined behavior.