Align compile closer with jinja upstream

pull/82224/head
Matt Martz 11 months ago
parent 0794609d43
commit c8892b39a5
No known key found for this signature in database
GPG Key ID: 40832D88E9FC91D8

@ -592,25 +592,31 @@ class AnsibleEnvironment(NativeEnvironment):
if not C.JINJA2_BYTECODE_CACHE: if not C.JINJA2_BYTECODE_CACHE:
return super().compile(source, name=name, filename=filename, raw=raw, defer_init=defer_init) # type: ignore[call-overload] return super().compile(source, name=name, filename=filename, raw=raw, defer_init=defer_init) # type: ignore[call-overload]
# Environment._parse try:
parsed = Parser(self, source, name, filename).parse() # Environment._parse
parsed = Parser(self, source, name, filename).parse()
# This wrapper ensures that all templates are not considered literal/constant
eval_ctx = nodes.ScopedEvalContextModifier(lineno=-1) # This wrapper ensures that all templates are not considered literal/constant
eval_ctx.options = [nodes.Keyword('volatile', nodes.Const(True))] eval_ctx = nodes.ScopedEvalContextModifier(lineno=-1)
eval_ctx.body = parsed.body eval_ctx.options = [nodes.Keyword('volatile', nodes.Const(True))]
eval_ctx.body = parsed.body
# Environment._generate
generated = generate( # Environment._generate
nodes.Template([eval_ctx], lineno=-1), generated = generate(
self, nodes.Template([eval_ctx], lineno=-1),
name, self,
filename, name,
defer_init=False, filename,
optimized=self.optimized, defer_init=False,
) optimized=self.optimized,
)
if raw:
return generated
return compile(generated, filename or '<template>', 'exec') return compile(generated, filename or '<template>', 'exec')
except TemplateSyntaxError:
self.handle_exception(source=source)
def from_string( def from_string(
self, self,

Loading…
Cancel
Save