What if you could use meta-template to figure out all of the variables a given template expects? All of the following should be theoretically possible to figure out from the AST:
You can derive top-level variable names from statements like {% if foo %}, {{ foo }}
You can reasonably assume that foo is an object with an optional bar property from {% if foo.bar %}, or expressions like {{ foo.bar[0] }}
You can infer arrays from loops like {% for x in foo %}
Conditional statements could suggest whether certain data properties are optional; whereas a "naked" expression like {{ foo }} suggests that foo is required
The other way that this could work is as a validation tool in which you would provide, say, the JSON Schema for the data a template expects (which would serve as the template's "API"), and then validate a template against that schema to confirm that it doesn't attempt to access invalid properties, attempt to iterate over primitives, etc.
What if you could use meta-template to figure out all of the variables a given template expects? All of the following should be theoretically possible to figure out from the AST:
{% if foo %}
,{{ foo }}
foo
is an object with an optionalbar
property from{% if foo.bar %}
, or expressions like{{ foo.bar[0] }}
{% for x in foo %}
{{ foo }}
suggests thatfoo
is requiredThe other way that this could work is as a validation tool in which you would provide, say, the JSON Schema for the data a template expects (which would serve as the template's "API"), and then validate a template against that schema to confirm that it doesn't attempt to access invalid properties, attempt to iterate over primitives, etc.