Twig icon indicating copy to clipboard operation
Twig copied to clipboard

FilterExpression's attributes are changed by the compiler

Open ericmorand opened this issue 2 years ago • 0 comments

While using TwigPHP to parse a Twig template and apply some changes to the AST before it is sent to the compiler, we discovered that the compiler changes somes attributes of FilterExpression:

https://github.com/twigphp/Twig/blob/51cfad80391c8c2f3a6d1be3f273c3cc4c115a0d/src/Node/Expression/FilterExpression.php#L30

This is a violation of the purpose of a compiler: a compiler compiles an AST as-is without changing it. Would the AST needs to be changed, it must be done before it is sent to the compiler

This violation creates an obvious issue where changing the attributes of a FilterExpression node is reverted by the compiler - defeating the purpose of having an AST to begin with.

I'm not sure how spread this pattern is in TwigPHP code base. Hopefully not too much.

ericmorand avatar Oct 21 '23 12:10 ericmorand