Skip to content

File tree

9 files changed

+36
-9
lines changed

9 files changed

+36
-9
lines changed

crates/oxc_ast/src/ast/jsx.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,10 @@ pub struct JSXText<'a> {
482482
pub span: Span,
483483
/// The text content.
484484
pub value: Atom<'a>,
485+
486+
/// The raw string as it appears in source code.
487+
///
488+
/// `None` when this ast node is not constructed from the parser.
489+
#[content_eq(skip)]
490+
pub raw: Option<Atom<'a>>,
485491
}

crates/oxc_ast/src/generated/assert_layouts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,10 +898,11 @@ const _: () = {
898898
assert!(offset_of!(JSXSpreadChild, span) == 0);
899899
assert!(offset_of!(JSXSpreadChild, expression) == 8);
900900

901-
assert!(size_of::<JSXText>() == 24);
901+
assert!(size_of::<JSXText>() == 40);
902902
assert!(align_of::<JSXText>() == 8);
903903
assert!(offset_of!(JSXText, span) == 0);
904904
assert!(offset_of!(JSXText, value) == 8);
905+
assert!(offset_of!(JSXText, raw) == 24);
905906

906907
assert!(size_of::<TSThisParameter>() == 24);
907908
assert!(align_of::<TSThisParameter>() == 8);
@@ -2302,10 +2303,11 @@ const _: () = {
23022303
assert!(offset_of!(JSXSpreadChild, span) == 0);
23032304
assert!(offset_of!(JSXSpreadChild, expression) == 8);
23042305

2305-
assert!(size_of::<JSXText>() == 16);
2306+
assert!(size_of::<JSXText>() == 24);
23062307
assert!(align_of::<JSXText>() == 4);
23072308
assert!(offset_of!(JSXText, span) == 0);
23082309
assert!(offset_of!(JSXText, value) == 8);
2310+
assert!(offset_of!(JSXText, raw) == 16);
23092311

23102312
assert!(size_of::<TSThisParameter>() == 20);
23112313
assert!(align_of::<TSThisParameter>() == 4);

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9449,12 +9449,13 @@ impl<'a> AstBuilder<'a> {
94499449
/// ## Parameters
94509450
/// * `span`: Node location in source code
94519451
/// * `value`: The text content.
9452+
/// * `raw`: The raw string as it appears in source code.
94529453
#[inline]
9453-
pub fn jsx_child_text<A>(self, span: Span, value: A) -> JSXChild<'a>
9454+
pub fn jsx_child_text<A>(self, span: Span, value: A, raw: Option<Atom<'a>>) -> JSXChild<'a>
94549455
where
94559456
A: IntoIn<'a, Atom<'a>>,
94569457
{
9457-
JSXChild::Text(self.alloc_jsx_text(span, value))
9458+
JSXChild::Text(self.alloc_jsx_text(span, value, raw))
94589459
}
94599460

94609461
/// Build a [`JSXChild::Element`].
@@ -9569,12 +9570,13 @@ impl<'a> AstBuilder<'a> {
95699570
/// ## Parameters
95709571
/// * `span`: Node location in source code
95719572
/// * `value`: The text content.
9573+
/// * `raw`: The raw string as it appears in source code.
95729574
#[inline]
9573-
pub fn jsx_text<A>(self, span: Span, value: A) -> JSXText<'a>
9575+
pub fn jsx_text<A>(self, span: Span, value: A, raw: Option<Atom<'a>>) -> JSXText<'a>
95749576
where
95759577
A: IntoIn<'a, Atom<'a>>,
95769578
{
9577-
JSXText { span, value: value.into_in(self.allocator) }
9579+
JSXText { span, value: value.into_in(self.allocator), raw }
95789580
}
95799581

95809582
/// Build a [`JSXText`], and store it in the memory arena.
@@ -9584,12 +9586,18 @@ impl<'a> AstBuilder<'a> {
95849586
/// ## Parameters
95859587
/// * `span`: Node location in source code
95869588
/// * `value`: The text content.
9589+
/// * `raw`: The raw string as it appears in source code.
95879590
#[inline]
9588-
pub fn alloc_jsx_text<A>(self, span: Span, value: A) -> Box<'a, JSXText<'a>>
9591+
pub fn alloc_jsx_text<A>(
9592+
self,
9593+
span: Span,
9594+
value: A,
9595+
raw: Option<Atom<'a>>,
9596+
) -> Box<'a, JSXText<'a>>
95899597
where
95909598
A: IntoIn<'a, Atom<'a>>,
95919599
{
9592-
Box::new_in(self.jsx_text(span, value), self.allocator)
9600+
Box::new_in(self.jsx_text(span, value, raw), self.allocator)
95939601
}
95949602

95959603
/// Build a [`TSThisParameter`].

crates/oxc_ast/src/generated/derive_clone_in.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,6 +2950,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXText<'_> {
29502950
JSXText {
29512951
span: CloneIn::clone_in(&self.span, allocator),
29522952
value: CloneIn::clone_in(&self.value, allocator),
2953+
raw: CloneIn::clone_in(&self.raw, allocator),
29532954
}
29542955
}
29552956
}

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,7 @@ impl ESTree for JSXText<'_> {
22572257
state.serialize_field("start", &self.span.start);
22582258
state.serialize_field("end", &self.span.end);
22592259
state.serialize_field("value", &self.value);
2260+
state.serialize_field("raw", &self.raw);
22602261
state.end();
22612262
}
22622263
}

crates/oxc_parser/src/jsx/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,13 @@ impl<'a> ParserImpl<'a> {
419419
let span = self.start_span();
420420
let value = Atom::from(self.cur_string());
421421
self.bump_any();
422-
self.ast.alloc_jsx_text(self.end_span(span), value)
422+
let span = self.end_span(span);
423+
// SAFETY:
424+
// range comes from the lexer, which are ensured to meeting the criteria of `get_unchecked`.
425+
let raw = Atom::from(unsafe {
426+
self.source_text.get_unchecked(span.start as usize..span.end as usize)
427+
});
428+
self.ast.alloc_jsx_text(span, value, Some(raw))
423429
}
424430

425431
fn jsx_element_name_eq(lhs: &JSXElementName<'a>, rhs: &JSXElementName<'a>) -> bool {

napi/parser/deserialize-js.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ function deserializeJSXText(pos) {
12541254
start: deserializeU32(pos),
12551255
end: deserializeU32(pos + 4),
12561256
value: deserializeStr(pos + 8),
1257+
raw: deserializeOptionStr(pos + 24),
12571258
};
12581259
}
12591260

napi/parser/deserialize-ts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,7 @@ function deserializeJSXText(pos) {
13071307
start: deserializeU32(pos),
13081308
end: deserializeU32(pos + 4),
13091309
value: deserializeStr(pos + 8),
1310+
raw: deserializeOptionStr(pos + 24),
13101311
};
13111312
}
13121313

npm/oxc-types/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ export interface JSXSpreadChild extends Span {
902902
export interface JSXText extends Span {
903903
type: 'JSXText';
904904
value: string;
905+
raw: string | null;
905906
}
906907

907908
export interface TSThisParameter extends Span {

0 commit comments

Comments
 (0)