use vize_l0::Span;
use super::{BindingId, EffectSet, ReactivityClass};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BindingOrigin {
Local,
Prop,
ProvideInject,
TemplateRef,
}
impl BindingOrigin {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Local => "local",
Self::Prop => "prop",
Self::ProvideInject => "provide-inject",
Self::TemplateRef => "template-ref",
}
}
#[must_use]
pub const fn from_str(value: &str) -> Option<Self> {
match value.as_bytes() {
b"local" => Some(Self::Local),
b"prop" => Some(Self::Prop),
b"provide-inject" => Some(Self::ProvideInject),
b"template-ref" => Some(Self::TemplateRef),
_ => None,
}
}
#[must_use]
pub const fn class_floor(self) -> ReactivityClass {
match self {
Self::Local => ReactivityClass::Static,
Self::Prop => ReactivityClass::PropsStable,
Self::ProvideInject | Self::TemplateRef => ReactivityClass::Reactive,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EscapeKind {
None,
Returned,
Stored,
Global,
}
impl EscapeKind {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::None => "none",
Self::Returned => "returned",
Self::Stored => "stored",
Self::Global => "global",
}
}
#[must_use]
pub const fn from_str(value: &str) -> Option<Self> {
match value.as_bytes() {
b"none" => Some(Self::None),
b"returned" => Some(Self::Returned),
b"stored" => Some(Self::Stored),
b"global" => Some(Self::Global),
_ => None,
}
}
#[must_use]
pub const fn class_floor(self) -> ReactivityClass {
match self {
Self::None => ReactivityClass::Static,
Self::Returned => ReactivityClass::PropsStable,
Self::Stored => ReactivityClass::Reactive,
Self::Global => ReactivityClass::Unstable,
}
}
}
pub use vize_davinci::diagnostic::Verdict;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BindingInput {
pub id: BindingId,
pub origin: BindingOrigin,
pub effects: EffectSet,
pub escape: EscapeKind,
pub verdict: Verdict,
pub span: Span,
}
impl BindingInput {
#[must_use]
pub const fn local(id: BindingId, span: Span) -> Self {
Self {
id,
origin: BindingOrigin::Local,
effects: EffectSet::empty(),
escape: EscapeKind::None,
verdict: Verdict::Proven,
span,
}
}
#[must_use]
pub const fn with_origin(mut self, origin: BindingOrigin) -> Self {
self.origin = origin;
self
}
#[must_use]
pub const fn with_effects(mut self, effects: EffectSet) -> Self {
self.effects = effects;
self
}
#[must_use]
pub const fn with_escape(mut self, escape: EscapeKind) -> Self {
self.escape = escape;
self
}
#[must_use]
pub const fn with_verdict(mut self, verdict: Verdict) -> Self {
self.verdict = verdict;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BindingFact {
pub id: BindingId,
pub class: ReactivityClass,
pub verdict: Verdict,
pub origin: BindingOrigin,
pub effects: EffectSet,
pub escape: EscapeKind,
pub span: Span,
}
impl BindingFact {
#[must_use]
pub const fn proven_class(self) -> Option<ReactivityClass> {
if self.verdict.is_proven() {
Some(self.class)
} else {
None
}
}
#[must_use]
pub const fn fires_as(self, class: ReactivityClass) -> bool {
self.verdict.is_proven() && self.class as u8 == class as u8
}
}