summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmy <leiamy12@gmail.com>2020-06-22 15:27:18 -0400
committerAmy <leiamy12@gmail.com>2021-03-26 16:44:36 -0400
commitfed1b24d5fda4547725c31df3493a6dfdb170884 (patch)
treed0c5cd68c1af43f2fe6388dd957e218de814c37b /src
parent94ccd028ef1f3cd9eaec862d6a1d646d02a242bc (diff)
downloadjinja2-fed1b24d5fda4547725c31df3493a6dfdb170884.tar.gz
allow scoped blocks to access loop vars
Diffstat (limited to 'src')
-rw-r--r--src/jinja2/compiler.py9
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