Skip to content

Conversation

@drjayvee
Copy link
Contributor

@drjayvee drjayvee commented Mar 16, 2024

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 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.

For example, a static analysis tool might consider arguments with no explicit default value as non-optional.

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
Copy link
Contributor Author

drjayvee commented Mar 16, 2024

Similar to #4009, this is a prerequisite for a desired static analysis inspection in TwigQI.

I can extend this feature by adding this attribute to every function/macro argument to make it more consistent.

@drjayvee 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
@drjayvee
Copy link
Contributor Author

@fabpot thanks for the review. The latest commit includes all your suggestions.

@drjayvee
Copy link
Contributor Author

@fabpot since you're working on Twig these days, could you please have another look at this PR? 😊

Copy link
Contributor

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

LGTM

@fabpot
Copy link
Contributor

fabpot commented Aug 27, 2024

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
@fabpot
Copy link
Contributor

fabpot commented Aug 27, 2024

Merged.

@fabpot fabpot closed this Aug 27, 2024
@drjayvee drjayvee deleted the implicit-default-value branch August 27, 2024 11:37
drjayvee added a commit to alisqi/TwigQI that referenced this pull request Aug 28, 2024
alizfara112 added a commit to alizfara112/TwigQI that referenced this pull request Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants