use oxc_ast::ast::{Comment, Expression};
use oxc_diagnostics::Diagnostics;
use oxc_span::{GetSpan, SourceType, Span};
use super::EmbeddingObservation;
use crate::ParseOptions;
pub struct AdmittedBorrowedExpression<'o, 'a> {
owner: &'o EmbeddingObservation<'a>,
root: &'o Expression<'a>,
}
impl<'a> EmbeddingObservation<'a> {
#[must_use]
pub fn admitted_expression(&self) -> Option<AdmittedBorrowedExpression<'_, 'a>> {
let root = self.expression()?;
Some(AdmittedBorrowedExpression { owner: self, root })
}
}
impl<'o, 'a> AdmittedBorrowedExpression<'o, 'a> {
#[must_use]
pub const fn original(&self) -> &'o EmbeddingObservation<'a> {
self.owner
}
#[must_use]
pub const fn expression(&self) -> &'o Expression<'a> {
self.root
}
#[must_use]
pub const fn content(&self) -> &'a str {
self.owner.content
}
#[must_use]
pub const fn source_type(&self) -> SourceType {
self.owner.source_type
}
#[must_use]
pub const fn options(&self) -> ParseOptions {
self.owner.options
}
#[must_use]
pub const fn parser_content_span(&self) -> Span {
self.owner.content_span
}
#[must_use]
pub fn parser_container_span(&self) -> Span {
self.root.span()
}
#[must_use]
pub fn comments(&self) -> &'o [Comment] {
self.owner.comments()
}
#[must_use]
pub fn diagnostics(&self) -> &'o Diagnostics {
self.owner.diagnostics()
}
#[must_use]
pub const fn has_legacy_literals(&self) -> bool {
self.owner.parsed.has_legacy_literals
}
}