[regression?] macro parameters are missing from declared variable

Created on 15 January 2025, 7 days ago

Problem/Motivation

It seems macro parameters are not counted as "declared" variables (anymore? I guess it was the case before).

For example:

{% macro generate_link(label, url, modifier, display_label) %}
  {% set attributes = create_attribute().addClass('fr-pagination__link', 'fr-pagination__link--' ~ modifier) %}
  {% set attributes = url ? attributes.setAttribute('href', url) : attributes.setAttribute('aria-disabled', 'true').setAttribute('role', 'link') %}
  {% set attributes = display_label ? attributes.addClass('fr-pagination__link--lg-label') : attributes %}
  <li>
    <a{{ attributes }}>{{ label }}</a>
  </li>
{% endmacro %}

Raises those unexpected errors:

  • Unknown variable: `modifier`.
  • Unknown variable: `url`.
  • Unknown variable: `label`.
  • Unknown variable: `display_label`.

Proposed resolution

2 proposals

  • the easy one I guess:
    • add macro parameters to the pool of declared variable, joining slots, props, "attributes", variables declared on templates...
  • trickier but better:
    • remove variables used in the macros from the pool of used variables
    • remove variables declared in the macros from the pool of declared variables
    • create a declared variables pool by macro with the variables from the macro parameters and the local set variables
    • create a used variables pool by macro with the variables locally used
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024