Fixed optimization of filters and misoptimizations with changed eval context #476
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I realized that some filters aren't inlined during optimizations. It turned out that this effects all environment and eval context filters. That is because the environment or eval context isn't passed as first but second argument. Therefore the filter function raises an exception and the optimizer skips the node. This one was easy to fix, see the first commit in this PR.
However, now things get funny. With that fix, the tests for the
{% autoescape %}
tag suddenly start to fail. As it turned out the optimizer were agnostic to the eval context, and theas_const()
method created implicitly a new eval context for every node, ignoring{% autoescape %}
tags up the tree. So I fixed this as well, see the second commit in this PR. Therefore optimizer now keeps track of the eval context, and updates it when visitingScopedEvalContextModifier
nodes. To avoid future issues like that and to get rid of dead code, I also made the eval context passed toas_const()
mandatory.