Finds every expression a component will evaluate at runtime.
Why this is a scan rather than a list of call sites
Expressions reach the runtime from more places than the render program: the
list manager reads data-ax-for and data-ax-key off the DOM, the defer
manager reads data-ax-defer-when, computed values arrive as declarations,
and event handlers travel inside a JSON attribute. Enumerating those call
sites in the compiler would mean two lists that have to stay in step, and the
failure mode of them drifting is silent: an expression that is not in the
table simply falls back to being interpreted, which is exactly the thing this
work exists to remove.
So the collector reads the finished template — the one the runtime is handed — and takes every expression-bearing position in it. A construct the compiler learns to emit later is picked up without changing this file, as long as it puts its expression where the others put theirs.
Over-collecting is safe, under-collecting is not
The table is keyed by exact source text and consulted only when the runtime actually evaluates that text. An entry nothing ever looks up costs a few bytes; a missing entry costs an interpreter in the bundle. The scan therefore errs towards including a candidate, and anything that does not parse as an expression is dropped rather than reported.
- Source:
Members
(inner, constant) EXPRESSION_ATTRIBUTES :Array:.<string:>
Attributes whose whole value is one expression the runtime evaluates.
Type:
- Source:
Methods
(static) collectExpressions(unit) → {Object}
Every expression and handler body a compiled unit will evaluate.
Parameters:
- Source:
Returns:
The collected sources.
- Type
- Object
(inner) add(into, source)
Adds a candidate expression to a set, ignoring blanks.
Parameters:
| Name | Type | Description |
|---|---|---|
into |
Set:.<string:> | The collecting set. |
source |
any | The candidate text. |
- Source:
(inner) addEventHandlers(into, value)
Collects the handler bodies out of a data-ax-event attribute.
The attribute is a JSON object of event name to handler source, written by module:lib/compiler/templateEvents. A malformed one is skipped: the template validator already reports it, and guessing here would put a wrong key in the table.
Parameters:
| Name | Type | Description |
|---|---|---|
into |
Set:.<string:> | The collecting set. |
value |
string | The attribute value. |
- Source:
(inner) addInterpolations(into, text)
Collects the interpolations in a piece of text.
Parameters:
| Name | Type | Description |
|---|---|---|
into |
Set:.<string:> | The collecting set. |
text |
string | Text that may contain |
- Source:
(inner) addListInterpolations(into, text)
Collects the escaped interpolations in a <@for> body.
Parameters:
| Name | Type | Description |
|---|---|---|
into |
Set:.<string:> | The collecting set. |
text |
string | Text that may contain |
- Source:
(inner) decodeEntities(value) → {string}
Decodes the entities an attribute value carries.
The template parser keeps attribute values exactly as written, so a
data-ax-event payload arrives as {"click":"save()"}.
The browser decodes it before the runtime reads it; this does the same so
both see the same handler source.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
string | The raw attribute value. |
- Source:
Returns:
The decoded value.
- Type
- string
(inner) listInterpolationRegex() → {RegExp}
Interpolations inside a <@for> body, which the compiler escapes to {% %}
so the outer template's own interpolation pass leaves them alone. The list
manager restores them to {{ }} before evaluating, so the expression text
the runtime sees is what sits between the delimiters here.
- Source:
Returns:
A fresh regex, because it is stateful.
- Type
- RegExp
(inner) walk(nodes, expressions, statements)
Walks a parsed template, collecting expressions and handler statements.
Parameters:
| Name | Type | Description |
|---|---|---|
nodes |
Array:.<object:> | Parsed template nodes. |
expressions |
Set:.<string:> | Collects value expressions. |
statements |
Set:.<string:> | Collects handler bodies. |
- Source: