Module: lib/compiler/parser/declarations

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.

Source:

Members

(static, constant) VALID_CONTRACTS :Array:.<string:>

Contract names the compiler understands.

Type:
  • Array:.<string:>
Source:

(inner, constant) DECLARATION_TAGS :Set:.<string:>

The declaration tags that are lifted out of the template.

Type:
  • Set:.<string:>
Source:

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.

Source:
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.

Source:
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.

Source:
Returns:

The value, or undefined when absent.

Type
string | undefined

Type Definitions

DeclarationSet

Type:
  • object
Properties:
Name Type Description
state Array:.<{name:: string:, value:: any:, line:: number:, column:: number:}>

Declared state keys, in source order.

stateTagCount number

How many <state> tags were written.

secondStateTagOffset number

Source offset of a duplicate <state> tag, or -1.

computed Array:.<{name:: string:, expression:: string:, line:: number:, column:: number:}>

Declared computed values.

actions Array:.<{name:: string:, body:: string:, atomic:: boolean:, onConflict:: (string:|undefined:), line:: number:, column:: number:, tagOffset:: number:, bodyOffset:: number:}>

Declared actions with their modifiers.

resources Array:.<{name:: string:, handler:: string:, pollInterval:: (number:|null:), line:: number:, column:: number:}>

Declared resources.

contracts Set:.<string:>

Declared compiler contracts.

template string

The source with every declaration removed.

ranges Array:.<{start:: number:, end:: number:}>

Removed source ranges.

Source: