use super::{ComponentParse, ComponentSourceError, parse_component};
use vize_l0::{Allocator, SourceBlock};
mod child;
mod element;
mod interpolation;
mod lint;
mod lint_tag;
mod operand;
mod selected;
mod text;
mod text_value;
pub use child::{NativeChild, NativeChildren};
pub use element::{
NativeAttribute, NativeAttributes, NativeElement, NativeElementClosingName,
NativeElementNameRefusal, NativeElementNames,
};
pub use interpolation::{
NativeInterpolationError, NativeInterpolationFailure, NativeInterpolationOperand,
NativeInterpolationView,
};
pub use lint::NativeLintComponent;
pub use lint_tag::{NativeLintTag, NativeLintTagKind, NativeLintTagRefusal};
pub use operand::{
NativeAttributeBindingExpression, NativeAttributeBindingExpressionView,
NativeAttributeExpression, NativeAttributeExpressionFailure, NativeAttributeExpressionView,
NativeAttributeForHead, NativeAttributeForHeadFailure, NativeAttributeForHeadView,
NativeAttributeHandler, NativeAttributeHandlerFailure, NativeAttributeHandlerView,
NativeAttributeHead, NativeAttributeOperandError, NativeAttributeValue,
NativeAttributeValueFailure, NativeAttributeValueView, NativeConditionKind,
NativeStaticBindingHead,
};
pub use selected::{NativeScriptSelection, NativeTemplateComponent, NativeTemplateGrammar};
pub use text::{NativeRootText, NativeRootTextError, NativeRootTextProfile, NativeRootTextView};
pub use text_value::{
NativeTextValue, NativeTextValueError, NativeTextValueFailure, NativeTextValueView,
};
pub struct NativeComponent<'a> {
allocator: &'a Allocator,
block: SourceBlock<'a>,
component: ComponentParse<'a>,
}
impl core::fmt::Debug for NativeComponent<'_> {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
formatter
.debug_struct("NativeComponent")
.field("block", &self.block)
.field("component", &self.component)
.finish_non_exhaustive()
}
}
impl<'a> NativeComponent<'a> {
pub fn parse_in(
allocator: &'a Allocator,
block: SourceBlock<'a>,
) -> Result<Self, ComponentSourceError> {
Ok(Self {
allocator,
block,
component: parse_component(allocator, block.source())?,
})
}
pub(super) fn parse_selected_in(
allocator: &'a Allocator,
block: SourceBlock<'a>,
) -> Result<Self, ComponentSourceError> {
Self::parse_lint_in(allocator, block)
}
fn parse_lint_in(
allocator: &'a Allocator,
block: SourceBlock<'a>,
) -> Result<Self, ComponentSourceError> {
Ok(Self {
allocator,
block,
component: crate::dialect::vue3::surface::parse_component_with_lint(
allocator,
block.source(),
)?,
})
}
#[must_use]
pub fn allocator(&self) -> &'a Allocator {
self.allocator
}
#[must_use]
pub fn block(&self) -> SourceBlock<'a> {
self.block
}
#[must_use]
pub fn carrier(&self) -> &ComponentParse<'a> {
&self.component
}
#[must_use]
pub fn children(&self) -> NativeChildren<'_, 'a> {
NativeChildren::root(self)
}
fn root_child_at(&self, ordinal: usize) -> Option<&crate::markup::SurfaceChild<'a>> {
self.component.tree.children.get(ordinal)
}
#[must_use]
pub fn into_carrier(self) -> ComponentParse<'a> {
self.component
}
}
#[cfg(test)]
mod reborrow_tests;
#[cfg(test)]
mod tests;