use vize_carton::{CompactString, SmallVec};
#[derive(Debug, Clone, Default)]
pub struct TemplateInfo {
pub root_element_count: usize,
pub uses_attrs: bool,
pub binds_attrs_explicitly: bool,
pub inherit_attrs_disabled: bool,
pub content_start: u32,
pub content_end: u32,
}
impl TemplateInfo {
#[inline]
pub fn has_multiple_roots(&self) -> bool {
self.root_element_count > 1
}
#[inline]
pub fn may_lose_fallthrough_attrs(&self) -> bool {
self.has_multiple_roots() && !self.binds_attrs_explicitly
}
}
#[derive(Debug, Clone)]
pub struct ElementIdInfo {
pub value: CompactString,
pub start: u32,
pub end: u32,
pub is_static: bool,
pub in_loop: bool,
pub scope_id: crate::scope::ScopeId,
pub kind: ElementIdKind,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ElementIdKind {
Id,
For,
AriaReference,
OtherReference,
}
impl ElementIdKind {
#[inline]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Id => "id",
Self::For => "for",
Self::AriaReference => "aria-reference",
Self::OtherReference => "other-reference",
}
}
#[inline]
pub const fn is_definition(&self) -> bool {
matches!(self, Self::Id)
}
#[inline]
pub const fn is_reference(&self) -> bool {
!self.is_definition()
}
}
#[derive(Debug, Clone)]
pub struct TemplateExpression {
pub content: CompactString,
pub kind: TemplateExpressionKind,
pub start: u32,
pub end: u32,
pub scope_id: crate::scope::ScopeId,
pub vif_guard: Option<CompactString>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TemplateExpressionKind {
Interpolation,
VBind,
VOn,
VIf,
VShow,
VModel,
}
impl TemplateExpressionKind {
#[inline]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Interpolation => "Interpolation",
Self::VBind => "VBind",
Self::VOn => "VOn",
Self::VIf => "VIf",
Self::VShow => "VShow",
Self::VModel => "VModel",
}
}
}
#[derive(Debug, Clone)]
pub struct ComponentUsage {
pub name: CompactString,
pub start: u32,
pub end: u32,
pub props: SmallVec<[PassedProp; 8]>,
pub events: SmallVec<[EventListener; 4]>,
pub slots: SmallVec<[SlotUsage; 2]>,
pub has_spread_attrs: bool,
pub scope_id: crate::scope::ScopeId,
pub vif_guard: Option<CompactString>,
}
#[derive(Debug, Clone)]
pub struct PassedProp {
pub name: CompactString,
pub value: Option<CompactString>,
pub start: u32,
pub end: u32,
pub is_dynamic: bool,
}
#[derive(Debug, Clone)]
pub struct EventListener {
pub name: CompactString,
pub handler: Option<CompactString>,
pub modifiers: SmallVec<[CompactString; 4]>,
pub start: u32,
pub end: u32,
}
#[derive(Debug, Clone)]
pub struct SlotUsage {
pub name: CompactString,
pub scope_vars: SmallVec<[CompactString; 4]>,
pub start: u32,
pub end: u32,
pub has_scope: bool,
}