Twig
Twig copied to clipboard
Mark implicit macro argument default values as such with an attribute
This change causes no difference to compiled templates or to macro argument semantics.
Consider the following macro:
{% 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.
For example, a static analysis tool might consider arguments with no explicit default value as non-optional.
Similar to #4009, this is a prerequisite for a desired static analysis inspection in TwigStan.
I can extend this feature by adding this attribute to every function/macro argument to make it more consistent.
@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? 😊
Thank you @drjayvee.
Merged.