Constructor
new ComponentParser(styleProcessor, customVoidTagsopt, configopt)
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
styleProcessor |
StyleProcessor | An instance of StyleProcessor to handle styles. |
||
customVoidTags |
Array:.<string:> |
<optional> |
Additional void tag names (lowercase). |
|
config |
object |
<optional> |
null | Project configuration object. |
- Source:
Members
__atlasUnits :Array:.<{name:: string:, filePath:: string:, content:: string:, kind:: string:}>
The units handed to Atlas so far, so render edges can be resolved once every component name is known.
Type:
- Source:
__componentNames :Set:.<string:>
Every registered component and page name in the project, supplied by the compiler through ComponentParser#setComponentNames before any file is parsed. Used by the unresolved-component check (AVX_W46). Empty when a component is parsed standalone, which disables that check.
Type:
- Source:
bridges :Map:.<string:, object:>
Bridges discovered by the compiler, keyed by absolute path. Set by AvenxCompiler before components are parsed; when a component is parsed standalone (tests, the Vite plugin) bridges are analysed on demand.
Type:
- Source:
config :object|null
Type:
- object | null
- Source:
customVoidTags :Array:.<string:>
Type:
- Source:
expressionGaps :Array:.<{name:: string:, refusals:: Array:.<object:>, gaps:: Array:.<object:>}>
What the expression generator could not compile, per unit.
A security refusal fails the build; a language gap is reported as a warning and leaves that one expression on the runtime path. Recorded here rather than thrown at the point of generation so a build reports every unit's problems at once instead of the first one's.
Type:
- Source:
expressionParser :ExpressionParser
Type:
- Source:
locations :Map:.<string:, object:>
Source locations of every declaration parsed so far, keyed by class name.
Collected as a by-product of parsing and written beside the bundle rather
than into it, so avenx trace view can turn a recorded action name into
a file and a line without an application paying for the mapping.
Type:
- Source:
model :AppModel|null
The Atlas model being populated, or null when Atlas is not being built.
Set by AvenxCompiler. When it is null, parse does no Atlas work at
all, so a caller that only wants a compiled class — the Vite plugin, a
unit test, loadComponent — pays nothing for it.
Type:
- AppModel | null
- Source:
moduleMeta :Map:.<string:, object:>
Per-unit information the module generator needs, keyed by absolute source path. Filled by ComponentParser#parse.
Type:
- Source:
referencedComponents :Set:.<string:>
Component tag names referenced by any template in this build.
Populated as templates compile, so by the time the entry module is built the answer is exact rather than a guess from the source text.
Type:
- Source:
rootDir :string|null
The project root, when the compiler has told the parser what it is.
findProjectRoot walks up from a component looking for a project
marker, which lands somewhere arbitrary in a directory that has none —
a scratch project in a temp directory, for instance — and every reported
path is then relative to the wrong place. The compiler resolved the root
once and authoritatively, so it is preferred when available.
Type:
- string | null
- Source:
styleProcessor :StyleProcessor
Type:
- Source:
Methods
assertNoCompiledOnlyConstruct(name, filePath, template, refusal)
Fails the build when a refused template uses a compiled-only construct.
Falling back is safe for a construct both renderers implement: the template
renders, more slowly, and the build says so. <@if> is not such a
construct. It only ever existed on the compiled path, so the string
renderer has no rewrite for it -- a refused template containing one would
render <@if cond> into the document as a literal element, wrapping the
branch it was supposed to choose between.
That is exactly the silent miscompile the compile-or-refuse rule exists to prevent, so it is an error with a location rather than a warning. The fix is always the same: get the template compiling, by moving the construct that refused into a child component.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The component class name. |
filePath |
string | The component's path. |
template |
string | The semantic template. |
refusal |
Object | Why it refused. |
- Source:
Throws:
-
When the template cannot fall back safely.
compileRenderProgram(name, filePath, voidTags) → {Object}
Compiles this component's template to a render program.
Runs on ComponentParser#lastSemanticTemplate -- the template after
styles and two-way bindings and before any directive rewrite -- so the IR
reads <@for> and <@if> as the constructs they are rather than as the
markup they used to be turned into.
Either half may refuse. The IR refuses a construct it does not model yet; the lowering refuses an IR node it cannot emit. Either way the component keeps the string renderer and the reason is recorded for the build to report, which is the same compile-or-refuse rule that has always applied.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The component class name. |
filePath |
string | The component's path, for diagnostics. |
voidTags |
Array:.<string:> | The effective void tag set. |
- Source:
Returns:
The program and the sources its indices address.
- Type
- Object
escapeScopedSlots(template) → {string}
Encodes interpolations inside <template data-slot-props="..."> tags
to avoid premature evaluation by the parent component.
Parameters:
| Name | Type | Description |
|---|---|---|
template |
string | The template string. |
- Source:
Returns:
The processed template.
- Type
- string
markStaticNodes(nodes, parentIsStaticopt, inSlotopt)
Recursively traverses nodes to find and mark the root of static subtrees.
Parameters:
- Source:
optimizeStaticSubtrees(template, filePathopt) → {string}
Identifies static elements/subtrees and marks them with data-ax-static="true".
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
template |
string | The compiled HTML template. |
|
filePath |
string |
<optional> |
The component file path, used to resolve project-specific
void tags from |
- Source:
Returns:
The optimized template.
- Type
- string
parse(filePath, typeopt) → {string}
Parses a .component.js or .page.js file and its corresponding CSS file.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
filePath |
string | The absolute path to the file. |
||
type |
'component' | 'page' |
<optional> |
component | The type of file being parsed. |
- Source:
Returns:
The generated JavaScript class.
- Type
- string
preprocessTemplate(rawTemplate, filePathopt) → {string}
Preprocesses a raw template string using configured template preprocessor hooks. Supports custom filter functions (e.g. Pug -> HTML) before ComponentParser parses HTML.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
rawTemplate |
string | The raw template content. |
|
filePath |
string |
<optional> |
Absolute path to component file. |
- Source:
Returns:
Preprocessed template string.
- Type
- string
processBindDirectives(template) → {string}
Processes data-ax-bind attributes on input, textarea, and select elements. Converts data-ax-bind="expr" to value="{{ expr }}" and event listener.
Parameters:
| Name | Type | Description |
|---|---|---|
template |
string | The template string. |
- Source:
Returns:
The processed template.
- Type
- string
processComponentTags(template) → {string}
Processes component tags recursively to handle transclusion slots.
Maps <CompName ...>...</CompName> to <div data-avenx-comp="CompName">...</div>.
Parameters:
| Name | Type | Description |
|---|---|---|
template |
string | The template string. |
- Source:
Returns:
The processed template.
- Type
- string
processEventDelegation(template, filePath) → {string}
Translates common event handler attributes (@click, @input, etc.) to a single data-ax-event JSON-encoded attribute for centralized delegation.
Parameters:
| Name | Type | Description |
|---|---|---|
template |
string | The HTML template string. |
filePath |
string | The component file path. |
- Source:
Returns:
The transformed template string.
- Type
- string
processSlotProps(template) → {string}
Processes slot elements in the template, converting dynamic props starting
with : to data-props- attributes.
Parameters:
| Name | Type | Description |
|---|---|---|
template |
string | The template string. |
- Source:
Returns:
The processed template.
- Type
- string
processTransitionTags(template, filePathopt) → {string}
Processes transition tags in the template, converting them to data-ax-transition attributes.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
template |
string | The HTML template string. |
|
filePath |
string |
<optional> |
The component file path, used to resolve project-specific
void tags from |
- Source:
Returns:
The processed template.
- Type
- string
processTransitionTagsInTree(nodes) → {Array:.<HTMLNode:>}
Recursively processes transition tags in the node tree.
Parameters:
| Name | Type | Description |
|---|---|---|
nodes |
Array:.<HTMLNode:> |
- Source:
Returns:
setBridges(bridges)
Supplies the project's bridge descriptors, so imports can be resolved without re-reading each bridge module for every component.
Parameters:
| Name | Type | Description |
|---|---|---|
bridges |
Map:.<string:, object:> | Descriptors keyed by absolute path. |
- Source:
setComponentNames(names) → {void}
Supplies the full set of registered component and page names, so a template tag can be validated against every name in the project rather than only the ones parsed so far.
The compiler discovers all names by filename before it parses any file, and hands them over here. When it is never called — a component parsed standalone in a test or the Vite plugin — the set stays empty and the unresolved-component check does nothing, so a lone component is never flagged for referencing a sibling the parser could not see.
Parameters:
| Name | Type | Description |
|---|---|---|
names |
Iterable:.<string:> | Registered component and page names. |
- Source:
Returns:
- Type
- void
setModel(model) → {void}
Attaches an Atlas model for parse to populate.
Parameters:
| Name | Type | Description |
|---|---|---|
model |
AppModel | null | The model. |
- Source:
Returns:
- Type
- void
setRootDir(rootDir) → {void}
Tells the parser which directory reported paths are relative to.
Parameters:
| Name | Type | Description |
|---|---|---|
rootDir |
string | The project root. |
- Source:
Returns:
- Type
- void