mirror of
https://gitee.com/openharmony/third_party_jinja2
synced 2024-11-23 15:19:46 +00:00
exclude globals from find_undeclared_variables
This commit is contained in:
parent
c5f1fd328b
commit
f7b110cbd0
@ -19,6 +19,8 @@ unreleased
|
||||
- Allow ``{%+`` syntax (with NOP behavior) when
|
||||
``lstrip_blocks == False`` (`#748`_)
|
||||
- Added a ``default`` parameter for the ``map`` filter. (`#557`_)
|
||||
- Exclude environment globals from
|
||||
:func:`meta.find_undeclared_variables`. #931
|
||||
|
||||
.. _#557: https://github.com/pallets/jinja/issues/557
|
||||
.. _#765: https://github.com/pallets/jinja/issues/765
|
||||
|
@ -29,7 +29,7 @@ class TrackingCodeGenerator(CodeGenerator):
|
||||
"""Remember all undeclared identifiers."""
|
||||
CodeGenerator.enter_frame(self, frame)
|
||||
for _, (action, param) in iteritems(frame.symbols.loads):
|
||||
if action == 'resolve':
|
||||
if action == 'resolve' and param not in self.environment.globals:
|
||||
self.undeclared_identifiers.add(param)
|
||||
|
||||
|
||||
|
@ -121,6 +121,10 @@ class TestMeta(object):
|
||||
x = meta.find_undeclared_variables(ast)
|
||||
assert x == set(['bar', 'seq', 'muh'])
|
||||
|
||||
ast = env.parse('{% for x in range(5) %}{{ x }}{% endfor %}{{ foo }}')
|
||||
x = meta.find_undeclared_variables(ast)
|
||||
assert x == set(['foo'])
|
||||
|
||||
def test_find_refererenced_templates(self, env):
|
||||
ast = env.parse('{% extends "layout.html" %}{% include helper %}')
|
||||
i = meta.find_referenced_templates(ast)
|
||||
|
Loading…
Reference in New Issue
Block a user