oxc_parser/embedding/
borrowed.rs1use oxc_ast::ast::{Comment, Expression};
4use oxc_diagnostics::Diagnostics;
5use oxc_span::{GetSpan, SourceType, Span};
6
7use super::EmbeddingObservation;
8use crate::ParseOptions;
9
10pub struct AdmittedBorrowedExpression<'o, 'a> {
14 owner: &'o EmbeddingObservation<'a>,
15 root: &'o Expression<'a>,
16}
17
18impl<'a> EmbeddingObservation<'a> {
19 #[must_use]
24 pub fn admitted_expression(&self) -> Option<AdmittedBorrowedExpression<'_, 'a>> {
25 let root = self.expression()?;
26 Some(AdmittedBorrowedExpression { owner: self, root })
27 }
28}
29
30impl<'o, 'a> AdmittedBorrowedExpression<'o, 'a> {
31 #[must_use]
32 pub const fn original(&self) -> &'o EmbeddingObservation<'a> {
33 self.owner
34 }
35 #[must_use]
36 pub const fn expression(&self) -> &'o Expression<'a> {
37 self.root
38 }
39 #[must_use]
40 pub const fn content(&self) -> &'a str {
41 self.owner.content
42 }
43 #[must_use]
44 pub const fn source_type(&self) -> SourceType {
45 self.owner.source_type
46 }
47 #[must_use]
48 pub const fn options(&self) -> ParseOptions {
49 self.owner.options
50 }
51 #[must_use]
52 pub const fn parser_content_span(&self) -> Span {
53 self.owner.content_span
54 }
55 #[must_use]
56 pub fn parser_container_span(&self) -> Span {
57 self.root.span()
58 }
59 #[must_use]
60 pub fn comments(&self) -> &'o [Comment] {
61 self.owner.comments()
62 }
63 #[must_use]
64 pub fn diagnostics(&self) -> &'o Diagnostics {
65 self.owner.diagnostics()
66 }
67 #[must_use]
70 pub const fn has_legacy_literals(&self) -> bool {
71 self.owner.parsed.has_legacy_literals
72 }
73}