Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/oxc_ast/src/ast/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,10 @@ pub struct JSXText<'a> {
pub span: Span,
/// The text content.
pub value: Atom<'a>,

/// The raw string as it appears in source code.
///
/// `None` when this ast node is not constructed from the parser.
#[content_eq(skip)]
pub raw: Option<Atom<'a>>,
}
6 changes: 4 additions & 2 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,10 +898,11 @@ const _: () = {
assert!(offset_of!(JSXSpreadChild, span) == 0);
assert!(offset_of!(JSXSpreadChild, expression) == 8);

assert!(size_of::<JSXText>() == 24);
assert!(size_of::<JSXText>() == 40);
assert!(align_of::<JSXText>() == 8);
assert!(offset_of!(JSXText, span) == 0);
assert!(offset_of!(JSXText, value) == 8);
assert!(offset_of!(JSXText, raw) == 24);

assert!(size_of::<TSThisParameter>() == 24);
assert!(align_of::<TSThisParameter>() == 8);
Expand Down Expand Up @@ -2302,10 +2303,11 @@ const _: () = {
assert!(offset_of!(JSXSpreadChild, span) == 0);
assert!(offset_of!(JSXSpreadChild, expression) == 8);

assert!(size_of::<JSXText>() == 16);
assert!(size_of::<JSXText>() == 24);
assert!(align_of::<JSXText>() == 4);
assert!(offset_of!(JSXText, span) == 0);
assert!(offset_of!(JSXText, value) == 8);
assert!(offset_of!(JSXText, raw) == 16);

assert!(size_of::<TSThisParameter>() == 20);
assert!(align_of::<TSThisParameter>() == 4);
Expand Down
20 changes: 14 additions & 6 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9449,12 +9449,13 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The text content.
/// * `raw`: The raw string as it appears in source code.
#[inline]
pub fn jsx_child_text<A>(self, span: Span, value: A) -> JSXChild<'a>
pub fn jsx_child_text<A>(self, span: Span, value: A, raw: Option<Atom<'a>>) -> JSXChild<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
JSXChild::Text(self.alloc_jsx_text(span, value))
JSXChild::Text(self.alloc_jsx_text(span, value, raw))
}

/// Build a [`JSXChild::Element`].
Expand Down Expand Up @@ -9569,12 +9570,13 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The text content.
/// * `raw`: The raw string as it appears in source code.
#[inline]
pub fn jsx_text<A>(self, span: Span, value: A) -> JSXText<'a>
pub fn jsx_text<A>(self, span: Span, value: A, raw: Option<Atom<'a>>) -> JSXText<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
JSXText { span, value: value.into_in(self.allocator) }
JSXText { span, value: value.into_in(self.allocator), raw }
}

/// Build a [`JSXText`], and store it in the memory arena.
Expand All @@ -9584,12 +9586,18 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: Node location in source code
/// * `value`: The text content.
/// * `raw`: The raw string as it appears in source code.
#[inline]
pub fn alloc_jsx_text<A>(self, span: Span, value: A) -> Box<'a, JSXText<'a>>
pub fn alloc_jsx_text<A>(
self,
span: Span,
value: A,
raw: Option<Atom<'a>>,
) -> Box<'a, JSXText<'a>>
where
A: IntoIn<'a, Atom<'a>>,
{
Box::new_in(self.jsx_text(span, value), self.allocator)
Box::new_in(self.jsx_text(span, value, raw), self.allocator)
}

/// Build a [`TSThisParameter`].
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXText<'_> {
JSXText {
span: CloneIn::clone_in(&self.span, allocator),
value: CloneIn::clone_in(&self.value, allocator),
raw: CloneIn::clone_in(&self.raw, allocator),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,7 @@ impl ESTree for JSXText<'_> {
state.serialize_field("start", &self.span.start);
state.serialize_field("end", &self.span.end);
state.serialize_field("value", &self.value);
state.serialize_field("raw", &self.raw);
state.end();
}
}
Expand Down
8 changes: 7 additions & 1 deletion crates/oxc_parser/src/jsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,13 @@ impl<'a> ParserImpl<'a> {
let span = self.start_span();
let value = Atom::from(self.cur_string());
self.bump_any();
self.ast.alloc_jsx_text(self.end_span(span), value)
let span = self.end_span(span);
// SAFETY:
// range comes from the lexer, which are ensured to meeting the criteria of `get_unchecked`.
let raw = Atom::from(unsafe {
self.source_text.get_unchecked(span.start as usize..span.end as usize)
});
self.ast.alloc_jsx_text(span, value, Some(raw))
}

fn jsx_element_name_eq(lhs: &JSXElementName<'a>, rhs: &JSXElementName<'a>) -> bool {
Expand Down
1 change: 1 addition & 0 deletions napi/parser/deserialize-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,7 @@ function deserializeJSXText(pos) {
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
value: deserializeStr(pos + 8),
raw: deserializeOptionStr(pos + 24),
};
}

Expand Down
1 change: 1 addition & 0 deletions napi/parser/deserialize-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,7 @@ function deserializeJSXText(pos) {
start: deserializeU32(pos),
end: deserializeU32(pos + 4),
value: deserializeStr(pos + 8),
raw: deserializeOptionStr(pos + 24),
};
}

Expand Down
1 change: 1 addition & 0 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ export interface JSXSpreadChild extends Span {
export interface JSXText extends Span {
type: 'JSXText';
value: string;
raw: string | null;
}

export interface TSThisParameter extends Span {
Expand Down
Loading