diff options
author | Amy <leiamy12@gmail.com> | 2020-06-22 15:27:18 -0400 |
---|---|---|
committer | Amy <leiamy12@gmail.com> | 2021-03-26 16:44:36 -0400 |
commit | fed1b24d5fda4547725c31df3493a6dfdb170884 (patch) | |
tree | d0c5cd68c1af43f2fe6388dd957e218de814c37b /src | |
parent | 94ccd028ef1f3cd9eaec862d6a1d646d02a242bc (diff) | |
download | jinja2-fed1b24d5fda4547725c31df3493a6dfdb170884.tar.gz |
allow scoped blocks to access loop vars
Diffstat (limited to 'src')
-rw-r--r-- | src/jinja2/compiler.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/jinja2/compiler.py b/src/jinja2/compiler.py index df6fa37..67918cd 100644 --- a/src/jinja2/compiler.py +++ b/src/jinja2/compiler.py @@ -1008,9 +1008,12 @@ class CodeGenerator(NodeVisitor): # try to figure out if we have an extended loop. An extended loop # is necessary if the loop is in recursive mode if the special loop - # variable is accessed in the body. - extended_loop = node.recursive or "loop" in find_undeclared( - node.iter_child_nodes(only=("body",)), ("loop",) + # variable is accessed in the body if the body is a scoped block. + extended_loop = ( + node.recursive + or "loop" + in find_undeclared(node.iter_child_nodes(only=("body",)), ("loop",)) + or any(block.scoped for block in node.find_all(nodes.Block)) ) loop_ref = None |