MCPcopy Create free account
hub / github.com/nodejs/node / find_undeclared_variables

Function find_undeclared_variables

tools/inspector_protocol/jinja2/meta.py:36–57  ·  view source on GitHub ↗

Returns a set of all variables in the AST that will be looked up from the context at runtime. Because at compile time it's not known which variables will be used depending on the path the execution takes at runtime, all variables are returned. >>> from jinja2 import Environment, me

(ast)

Source from the content-addressed store, hash-verified

34
35
36def find_undeclared_variables(ast):
37 """Returns a set of all variables in the AST that will be looked up from
38 the context at runtime. Because at compile time it's not known which
39 variables will be used depending on the path the execution takes at
40 runtime, all variables are returned.
41
42 >>> from jinja2 import Environment, meta
43 >>> env = Environment()
44 >>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
45 >>> meta.find_undeclared_variables(ast) == set(['bar'])
46 True
47
48 .. admonition:: Implementation
49
50 Internally the code generator is used for finding undeclared variables.
51 This is good to know because the code generator might raise a
52 :exc:`TemplateAssertionError` during compilation and as a matter of
53 fact this function can currently raise that exception as well.
54 """
55 codegen = TrackingCodeGenerator(ast.environment)
56 codegen.visit(ast)
57 return codegen.undeclared_identifiers
58
59
60def find_referenced_templates(ast):

Callers

nothing calls this directly

Calls 2

visitMethod · 0.45

Tested by

no test coverage detected