Skip to content

Rename macro variable AST nodes - #4876

Merged
fabpot merged 1 commit into
twigphp:3.xfrom
fabpot:rename-macro-variables
Jul 28, 2026
Merged

Rename macro variable AST nodes#4876
fabpot merged 1 commit into
twigphp:3.xfrom
fabpot:rename-macro-variables

Conversation

@fabpot

@fabpot fabpot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

The current name are just wrong as these classes are only used in the context of macros. They were confusing.

@upsun-dispatch

Copy link
Copy Markdown

📋 PR Summary

This PR renames the macro-related AST node classes TemplateVariableMacroVariable and AssignTemplateVariableAssignMacroVariable, since the old names were misleading (they are only used in macro contexts). The new classes hold the real implementation while the old names become thin @deprecated subclasses that emit trigger_deprecation notices, preserving backward compatibility. All internal call sites (parsers, ImportNode, Parser) are updated to the new names, and tests plus CHANGELOG/docs cover the deprecation path.

Changes
Layer / File(s) Summary
new node classes
src/Node/Expression/Variable/MacroVariable.php New class holding the implementation moved from TemplateVariable (extends TempNameExpression); implements getName/compile identically.
src/Node/Expression/Variable/AssignMacroVariable.php New class holding the implementation moved from AssignTemplateVariable; compiles the $macros assignment.
deprecation shims
src/Node/Expression/Variable/TemplateVariable.php Reduced to a deprecated subclass of MacroVariable that triggers a deprecation in its constructor.
src/Node/Expression/Variable/AssignTemplateVariable.php Reduced to a deprecated final subclass of AssignMacroVariable that triggers a deprecation in its constructor.
call-site updates
src/ExpressionParser/Infix/DotExpressionParser.php Uses MacroVariable instead of TemplateVariable when building MacroReferenceExpression.
src/Node/Expression/MacroReferenceExpression.php Constructor now type-hints MacroVariable; updated a code comment.
src/Node/ImportNode.php Accepts/creates AssignMacroVariable + MacroVariable; legacy branch now wraps the name in a MacroVariable.
src/Parser.php addImportedSymbol and getImportedSymbol now reference AssignMacroVariable/MacroVariable.
src/TokenParser/FromTokenParser.php Builds AssignMacroVariable/MacroVariable for imported symbols.
src/TokenParser/ImportTokenParser.php Builds AssignMacroVariable/MacroVariable for the import target.
docs
CHANGELOG Adds a deprecation entry for TemplateVariable/AssignTemplateVariable.
doc/deprecated.rst Documents the class deprecations as of Twig 3.29.
tests
tests/Node/Expression/MacroReferenceTest.php Switches to MacroVariable and adds a legacy test asserting the deprecation when TemplateVariable is passed.
tests/Node/ImportTest.php Switches to the new classes and adds a legacy test asserting both deprecation messages in order.
tests/Node/ModuleTest.php Updates fixture construction to the new classes.

@fabpot
fabpot merged commit a2a4c1b into twigphp:3.x Jul 28, 2026
54 checks passed
@fabpot
fabpot deleted the rename-macro-variables branch July 28, 2026 10:08
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.

1 participant