diff options
author | Adrian Moennich <adrian@planetcoding.net> | 2017-08-22 22:59:57 +0200 |
---|---|---|
committer | Adrian Moennich <adrian@planetcoding.net> | 2017-08-22 23:12:09 +0200 |
commit | cde2a54b87876bd02b283db2f52aca3d9272a92c (patch) | |
tree | 2cce6a0e6958fdb7d6c34cb9012f5216c2ab7d21 /jinja2/compiler.py | |
parent | d117425f5ed3f542100f20d3bf700ae7bc54039f (diff) | |
download | jinja2-2.9-maintenance.tar.gz |
Compile `elif` tag to `elif` instead of `else: if`2.9-maintenance
This avoids deep nesting in case of many `{% elif .. %}` blocks (which
would fail during execution) and also deep recursion (which may fail
during compilation)
fixes #759
Diffstat (limited to 'jinja2/compiler.py')
-rw-r--r-- | jinja2/compiler.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/jinja2/compiler.py b/jinja2/compiler.py index b2ab6fe..30826f3 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -1129,6 +1129,13 @@ class CodeGenerator(NodeVisitor): self.indent() self.blockvisit(node.body, if_frame) self.outdent() + for elif_ in node.elif_: + self.writeline('elif ', elif_) + self.visit(elif_.test, if_frame) + self.write(':') + self.indent() + self.blockvisit(elif_.body, if_frame) + self.outdent() if node.else_: self.writeline('else:') self.indent() |