-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Mark implicit macro argument default values as such with an attribute in AST #4010
Closed
Conversation
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 change causes no difference to compiled templates or to macro argument semantics. Consider the following macro: ```twig {% macro marco(po, lo = null) %}{% endmacro %} ``` With this change, the `ConstantExpression` for argument `po` will have an attribute `isImplicit`, whose value will be `true`. (Note that `lo` will not have that attribute.) This allows node visitors to distinguish between arguments that do and those that do not have explicit default values even if the value is `null`. This is useful for [static code analysis](twigphp#4003). For example, a static analysis tool might consider arguments with no explicit default value as non-optional.
drjayvee
changed the title
Mark implicit macro argument default values as such with an attribute
Mark implicit macro argument default values as such with an attribute in AST
Aug 16, 2024
fabpot
reviewed
Aug 19, 2024
@fabpot thanks for the review. The latest commit includes all your suggestions. |
@fabpot since you're working on Twig these days, could you please have another look at this PR? 😊 |
fabpot
requested changes
Aug 27, 2024
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.
LGTM
Thank you @drjayvee. |
fabpot
added a commit
that referenced
this pull request
Aug 27, 2024
…h an attribute in AST (drjayvee) This PR was squashed before being merged into the 3.x branch. Discussion ---------- Mark implicit macro argument default values as such with an attribute in AST This change causes no difference to compiled templates or to macro argument semantics. Consider the following macro: ```twig {% macro marco(po, lo = null) %}{% endmacro %} ``` With this change, the `ConstantExpression` for argument `po` will have an attribute `is_implicit`, whose value will be `true`. (Note that `lo` will not have that attribute.) This allows node visitors to distinguish between arguments that do and those that do not have explicit default values even if the value is `null`. This is useful for [static code analysis](#4003). For example, a static analysis tool might consider arguments with no explicit default value as non-optional. Commits ------- e83a802 Mark implicit macro argument default values as such with an attribute in AST
Merged. |
drjayvee
added a commit
to alisqi/TwigQI
that referenced
this pull request
Aug 28, 2024
To preview twigphp/Twig#4010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change causes no difference to compiled templates or to macro argument semantics.
Consider the following macro:
With this change, the
ConstantExpression
for argumentpo
will have an attributeis_implicit
, whose value will betrue
. (Note thatlo
will not have that attribute.)This allows node visitors to distinguish between arguments that do and those that do not have explicit default values even if the value is
null
.This is useful for static code analysis.
For example, a static analysis tool might consider arguments with no explicit default value as non-optional.