Twig icon indicating copy to clipboard operation
Twig copied to clipboard

Introduce a CorrectnessNodeVisitor to validate that templates are semantically correct

Open fabpot opened this issue 1 year ago • 2 comments

This PR addresses several issues around the correctness of templates. Being able to parse and compile a template does not mean that it is semantically correct. To enforce correctness, we currently have several places where we deal with it:

  • Parser::filterBodyNodes(): This method is a mix of ensuring the correctness of a template, but it also changes the body node of a child template (something that is always needed and not part of the correctness checks)
  • ExtendsTokenParser: It checks that an extend tag is not embedded into a block or a macro. The extend tag is not the only one that must be at the root of a template

This PR introduces a new CorrectnessNodeVisitor that has the responsibility to check that a template is semantically correct. It's the continuation of work that started a long time ago in #2687 (where I mentioned the weirdness of some supported templates like those mentioned in #3926 and deprecated by this PR).

Closes #3698: Having a use tag embedded in another tag (like if in the mentioned PR) is deprecated and will not be possible in 4.0.

fabpot avatar Sep 09 '24 20:09 fabpot

@fabpot what is the state of this PR ? Do you plan to fix it or to abandon it ?

stof avatar Oct 14 '24 12:10 stof

@fabpot what is the state of this PR ? Do you plan to fix it or to abandon it ?

I plan to still work on this (soon).

fabpot avatar Oct 14 '24 12:10 fabpot