Emits a component's compiled expressions as module source.
Shape, and why it is keyed by source
Counter.__axExprs = {
"count": (scope) => axGet(scope, "count"),
"item.qty": (scope) => axRead(axGet(scope, "item"), "qty", false),
};
Keying by the original source text rather than by an index is what lets every evaluation site take the compiled path at once. The render program addresses its bindings by index and could have used one; the list manager, the defer manager and computed declarations all arrive holding text, read from a DOM attribute or a declaration. One table keyed by that text serves all of them, so no call site had to learn a new calling convention in order to stop being interpreted.
The cost is the key: a component's expression sources are in the bundle twice, once as a key and once as compiled code. That is paid back many times over by not shipping a parser and an interpreter, and it is temporary — once every evaluation site addresses bindings by index, the keys go.
What is not in the table
An expression the generator refuses. Refusals are returned to the caller
rather than swallowed, because the two reasons are very different. A security
refusal (naming window, writing __proto__) must fail the build, while an
expression merely outside the supported language should leave the entry
absent and let the existing runtime path handle it.
- Source:
Members
(inner, constant) SECURITY_REFUSAL :RegExp
Security refusals that must fail the build rather than fall back.
An expression outside the supported language is a capability gap and falls back. An expression that names a restricted global or touches a forbidden key is a mistake in the application, and letting it fall back would mean the developer learns about it from a runtime sandbox violation instead of from the build.
Type:
- RegExp
- Source:
Methods
(static) buildExpressionTable(className, collected) → {CompiledTable}
Builds the compiled-expression statics for one component class.
Parameters:
| Name | Type | Description |
|---|---|---|
className |
string | The generated class name. |
collected |
object | Output of module:lib/compiler/codegen/collect. Properties |
- Source:
Returns:
The generated source and what it covers.
- Type
- CompiledTable
(static) buildProgramTables(className, expressions, statements) → {Object}
Compiles a render program's expression and statement tables.
Separate from buildExpressionTable because the two have different failure modes. A source-keyed entry that does not compile leaves the runtime to interpret the source it still has; an indexed entry that does not compile leaves nothing behind, so the program cannot ship.
Parameters:
| Name | Type | Description |
|---|---|---|
className |
string | The component class name. |
expressions |
Array:.<string:> | Expression sources, in index order. |
statements |
Array:.<string:> | Statement sources, in index order. |
- Source:
Returns:
The emitted assignments, or the first source that would not compile.
- Type
- Object
(inner) buildEntries(sources, generate, accumulator) → {Array:.<string:>}
Compiles a set of sources into table entries.
Parameters:
| Name | Type | Description |
|---|---|---|
sources |
Array:.<string:> | The expression or statement sources. |
generate |
function | The generator to apply. |
accumulator |
object | Collects refusals and gaps. |
- Source:
Returns:
Entry source lines.
(inner) buildIndexedTable(className, staticName, sources, generate) → {Object}
Compiles an ordered list of sources into a positional array literal.
The render program addresses expressions by index, so its table is an array and every slot must be filled: a hole would be a binding the runtime cannot evaluate and cannot name, because the source is not in the bundle. So this refuses the whole table rather than emitting a sparse one, and the caller keeps the component on the legacy path -- the same compile-or-refuse rule the program itself follows.
Parameters:
- Source:
Returns:
The emitted assignment, or the first source that would not compile.
- Type
- Object
(inner) buildNamedEntries(bodies, accumulator) → {Object}
Compiles a set of named bodies into table entries.
Actions and resources are addressed by name at run time, not by source, so they get their own table. Keying by name is what allows a production build to leave the body text out of the bundle entirely: nothing has to match a string in order to find the implementation.
Parameters:
| Name | Type | Description |
|---|---|---|
bodies |
Object:.<string:, string:> | Sources keyed by name. |
accumulator |
object | Collects refusals and gaps. |
- Source:
Returns:
Entry lines and what compiled.
- Type
- Object
(inner) generateBody(source) → {string}
Compiles one executable body, preferring the expression-program generator.
A run of expressions -- count++, busy = true; save() -- takes the same
path a template binding does, so it emits the same guarded primitives.
Anything with real statement syntax goes to the action compiler, which parses
it properly and rewrites only how free identifiers resolve.
Parameters:
| Name | Type | Description |
|---|---|---|
source |
string | The body source. |
- Source:
Returns:
JavaScript source for the function.
- Type
- string
Type Definitions
CompiledTable
Type:
- object
Properties:
- Source: