Extracts Avenx declaration tags from a component source.
This is the single place that decides what a component declares. Both the
reader (what <state> says) and the remover (what leaves the template) come
from one scan over one set of source ranges, so the two can no longer
disagree — which is the class of bug that let a multi-line <state> tag be
parsed correctly and stripped incorrectly at the same time.
The declarations recognised here are the component's header: <state>,
<computed>, <action>, <resource> and <contract>. Structural
directives (<@for>, <@suspense>, <@deadlock>, <@css />) stay in the
template and are handled by the template pipeline; they describe rendering,
not declaration.
Members
(static, constant) VALID_CONTRACTS :Array:.<string:>
Contract names the compiler understands.
Type:
(inner, constant) DECLARATION_TAGS :Set:.<string:>
The declaration tags that are lifted out of the template.
Type:
Methods
(static) coerceValue(raw) → {any}
Coerces a declared attribute value to a JavaScript value.
<state count="0" /> should produce the number 0, not the string "0",
and <state items="[1,2]" /> should produce an array. The order matters:
literal keywords first, then numbers, then JSON, then the raw string.
Parameters:
| Name | Type | Description |
|---|---|---|
raw |
string | The attribute value as written. |
Returns:
The coerced value.
- Type
- any
(static) parseDeclarations(source) → {DeclarationSet}
Reads every declaration in a component source.
Parameters:
| Name | Type | Description |
|---|---|---|
source |
string | The component source text. |
Returns:
The declarations and the remaining template.
- Type
- DeclarationSet
(inner) readBindable(attrs, name) → {string|undefined}
Reads an attribute that may carry Vue-style : binding syntax.
<resource :handler="x" :pollInterval="5000" /> and the unprefixed form mean
the same thing to Avenx; the colon is accepted because developers arriving
from Vue write it out of habit.
Parameters:
| Name | Type | Description |
|---|---|---|
attrs |
Object:.<string:, string:> | The parsed attribute map. |
name |
string | The attribute name without a prefix. |
Returns:
The value, or undefined when absent.
- Type
- string | undefined
Type Definitions
DeclarationSet
Type:
- object