use alloc::vec::Vec;
use vize_l0::{Span, String};
use super::expr::{FolioContract, FolioExpr, own_expr};
use super::{FolioAttribute, FolioName, own_attribute, own_name};
use crate::op::BindingOp;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FolioBinding {
Bind(FolioBind),
On(FolioOn),
Model(FolioModel),
SlotContent(FolioSlotContent),
VueDirective(FolioVueDirective),
VueCssBind(FolioVueCssBind),
VueSync(FolioVueSync),
VueSlotScope(FolioVueSlotScope),
VueOnce(FolioVueOnce),
VueMemo(FolioVueMemo),
VueShow(FolioVueShow),
VueHtml(FolioVueHtml),
VueText(FolioVueText),
VueCloak(FolioVueCloak),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioBind {
pub name: Option<FolioName>,
pub modifiers: Vec<String>,
pub value: Option<FolioExpr>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioOn {
pub name: Option<FolioName>,
pub modifiers: Vec<String>,
pub handler: Option<FolioExpr>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioModel {
pub contract: FolioContract,
pub argument: Option<FolioName>,
pub attributes: Vec<FolioAttribute>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioSlotContent {
pub name: Option<FolioName>,
pub modifiers: Vec<String>,
pub params: Option<FolioExpr>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueSync {
pub name: String,
pub modifiers: Vec<String>,
pub value: FolioExpr,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueSlotScope {
pub name: Option<String>,
pub params: Option<FolioExpr>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueDirective {
pub name: String,
pub argument: Option<FolioName>,
pub modifiers: Vec<String>,
pub value: Option<FolioExpr>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueCssBind {
pub value: FolioExpr,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueOnce {
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueMemo {
pub value: FolioExpr,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueShow {
pub value: FolioExpr,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueHtml {
pub value: Option<FolioExpr>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueText {
pub value: Option<FolioExpr>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FolioVueCloak {
pub span: Span,
}
pub(super) fn own_binding(binding: &BindingOp<'_>) -> FolioBinding {
match binding {
BindingOp::Bind(bind) => FolioBinding::Bind(FolioBind {
name: bind.name.as_ref().map(own_name),
modifiers: own_modifiers(&bind.modifiers),
value: bind.value.as_ref().map(own_expr),
span: bind.span,
}),
BindingOp::On(on) => FolioBinding::On(FolioOn {
name: on.name.as_ref().map(own_name),
modifiers: own_modifiers(&on.modifiers),
handler: on.handler.as_ref().map(own_expr),
span: on.span,
}),
BindingOp::Model(model) => FolioBinding::Model(FolioModel {
contract: FolioContract {
read: own_expr(&model.contract.read),
write: own_expr(&model.contract.write),
},
argument: model.argument.as_ref().map(own_name),
attributes: model.attributes.iter().map(own_attribute).collect(),
span: model.span,
}),
BindingOp::SlotContent(content) => FolioBinding::SlotContent(FolioSlotContent {
name: content.name.as_ref().map(own_name),
modifiers: own_modifiers(&content.modifiers),
params: content.params.as_ref().map(own_expr),
span: content.span,
}),
BindingOp::VueDirective(directive) => FolioBinding::VueDirective(FolioVueDirective {
name: String::from(directive.name),
argument: directive.argument.as_ref().map(own_name),
modifiers: own_modifiers(&directive.modifiers),
value: directive.value.as_ref().map(own_expr),
span: directive.span,
}),
BindingOp::VueCssBind(bind) => FolioBinding::VueCssBind(FolioVueCssBind {
value: own_expr(&bind.value),
span: bind.span,
}),
BindingOp::VueSync(sync) => FolioBinding::VueSync(FolioVueSync {
name: String::from(sync.name),
modifiers: own_modifiers(&sync.modifiers),
value: own_expr(&sync.value),
span: sync.span,
}),
BindingOp::VueSlotScope(scope) => FolioBinding::VueSlotScope(FolioVueSlotScope {
name: scope.name.map(String::from),
params: scope.params.as_ref().map(own_expr),
span: scope.span,
}),
BindingOp::VueOnce(once) => FolioBinding::VueOnce(FolioVueOnce { span: once.span }),
BindingOp::VueMemo(memo) => FolioBinding::VueMemo(FolioVueMemo {
value: own_expr(&memo.value),
span: memo.span,
}),
BindingOp::VueShow(show) => FolioBinding::VueShow(FolioVueShow {
value: own_expr(&show.value),
span: show.span,
}),
BindingOp::VueHtml(html) => FolioBinding::VueHtml(FolioVueHtml {
value: html.value.as_ref().map(own_expr),
span: html.span,
}),
BindingOp::VueText(text) => FolioBinding::VueText(FolioVueText {
value: text.value.as_ref().map(own_expr),
span: text.span,
}),
BindingOp::VueCloak(cloak) => FolioBinding::VueCloak(FolioVueCloak { span: cloak.span }),
}
}
fn own_modifiers(modifiers: &[&str]) -> Vec<String> {
modifiers.iter().map(|text| String::from(*text)).collect()
}