Archived
94 lines
2.5 KiB
Rust
94 lines
2.5 KiB
Rust
//! AST types for el-ui component files.
|
|
|
|
/// A parsed component definition.
|
|
#[derive(Debug, Clone)]
|
|
pub struct Component {
|
|
pub name: String,
|
|
pub props: Vec<PropDef>,
|
|
pub state: Vec<StateDef>,
|
|
pub methods: Vec<Method>,
|
|
pub template: Template,
|
|
}
|
|
|
|
/// A prop declaration inside `props { ... }`.
|
|
#[derive(Debug, Clone)]
|
|
pub struct PropDef {
|
|
pub name: String,
|
|
pub type_name: String,
|
|
pub default: Option<String>,
|
|
}
|
|
|
|
/// A state declaration inside `state { ... }`.
|
|
#[derive(Debug, Clone)]
|
|
pub struct StateDef {
|
|
pub name: String,
|
|
pub type_name: String,
|
|
pub initial: String,
|
|
}
|
|
|
|
/// A method defined with `fn` inside the component body.
|
|
#[derive(Debug, Clone)]
|
|
pub struct Method {
|
|
pub name: String,
|
|
pub params: Vec<(String, String)>, // (name, type)
|
|
pub return_type: String,
|
|
pub body: String, // raw source text of the body (we pass through verbatim)
|
|
}
|
|
|
|
/// The template block.
|
|
#[derive(Debug, Clone)]
|
|
pub struct Template {
|
|
pub nodes: Vec<TemplateNode>,
|
|
}
|
|
|
|
/// A node within the template tree.
|
|
#[derive(Debug, Clone)]
|
|
pub enum TemplateNode {
|
|
/// A plain HTML element: `<div class="foo">...</div>`
|
|
Element {
|
|
tag: String,
|
|
attrs: Vec<Attr>,
|
|
children: Vec<TemplateNode>,
|
|
},
|
|
/// A component usage (uppercase first letter): `<Counter />`
|
|
Component {
|
|
name: String,
|
|
props: Vec<Attr>,
|
|
},
|
|
/// Literal text content.
|
|
Text(String),
|
|
/// An interpolated expression: `{count}`
|
|
Interpolation(String),
|
|
/// Conditional: `{#if cond}...{/if}` or `{#if cond}...{:else}...{/if}`
|
|
If {
|
|
condition: String,
|
|
then: Vec<TemplateNode>,
|
|
else_: Option<Vec<TemplateNode>>,
|
|
},
|
|
/// List rendering: `{#each items as item}...{/each}`
|
|
Each {
|
|
items: String,
|
|
item_name: String,
|
|
children: Vec<TemplateNode>,
|
|
},
|
|
/// Semantic activation query: `{#activate "query" as results}...{/activate}`
|
|
Activate {
|
|
query: String,
|
|
result_name: String,
|
|
children: Vec<TemplateNode>,
|
|
},
|
|
}
|
|
|
|
/// An attribute on a template element.
|
|
#[derive(Debug, Clone)]
|
|
pub enum Attr {
|
|
/// `class="btn"` — static string value
|
|
Static { name: String, value: String },
|
|
/// `class={expr}` — dynamic expression
|
|
Dynamic { name: String, expr: String },
|
|
/// `on:click={handler}` — event handler
|
|
EventHandler { event: String, handler: String },
|
|
/// `disabled={boolExpr}` — boolean attribute
|
|
BoolAttr { name: String, expr: String },
|
|
}
|