Skip to content
Myr

Resolved a regression in 2.9 with macro call scoping

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 3e4ebc8 · Browse files · 2 files+26 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+26 added−1 removed

  • tests:+25 added−0 removed
  • other:+1 added−1 removed

2 files+26 added−1 removed

modified:jinja2/compiler.py+1 added-1 removed
1127 unmodified lines
1128 call_frame, macro_ref = self.macro_body(node, frame)1129 self.writeline('caller = ')1130 self.macro_def(macro_ref, call_frame)1131 self.start_write(frame, node)1132 self.visit_Call(node.call, call_frame, forward_caller=True)1132 self.visit_Call(node.call, frame, forward_caller=True)1133 self.end_write(frame)11341135 def visit_FilterBlock(self, node, frame):1136 filter_frame = frame.inner()
483 unmodified lines
modified:tests/test_regression.py+25 added
385 unmodified lines
386 'child.html': '{% extends "base.html" %}{% set var = 42 %}',387 }))388 t = env.get_template('child.html')389 assert t.render() == '42'390391 def test_caller_scoping(self, env):392 t = env.from_string('''393 {% macro detail(icon, value) -%}394 {% if value -%}395 <p><span class="fa fa-fw fa-{{ icon }}"></span>396 {%- if caller is undefined -%}397 {{ value }}398 {%- else -%}399 {{ caller(value, *varargs) }}400 {%- endif -%}</p>401 {%- endif %}402 {%- endmacro %}403404405 {% macro link_detail(icon, value, href) -%}406 {% call(value, href) detail(icon, value, href) -%}407 <a href="{{ href }}">{{ value }}</a>408 {%- endcall %}409 {%- endmacro %}410 ''')411412 assert t.module.link_detail('circle', 'Index', '/') == (413 '<p><span class="fa fa-fw fa-circle">'414 '</span><a href="/">Index</a></p>')