Skip to content

Commit 7838c35

Browse files
committed
refactor(ast)!: reorder fields of TemplateElement
1 parent db946e6 commit 7838c35

File tree

10 files changed

+22
-23
lines changed

10 files changed

+22
-23
lines changed

crates/oxc_ast/src/ast/js.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,10 @@ pub struct TaggedTemplateExpression<'a> {
446446
#[ast(visit)]
447447
#[derive(Debug, Clone)]
448448
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
449-
#[estree(field_order(span, value, tail))]
450449
pub struct TemplateElement<'a> {
451450
pub span: Span,
452-
pub tail: bool,
453451
pub value: TemplateElementValue<'a>,
452+
pub tail: bool,
454453
}
455454

456455
/// See [template-strings-cooked-vs-raw](https://exploringjs.com/js/book/ch_template-literals.html#template-strings-cooked-vs-raw)

crates/oxc_ast/src/generated/assert_layouts.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ const _: () = {
103103
assert!(size_of::<TemplateElement>() == 48);
104104
assert!(align_of::<TemplateElement>() == 8);
105105
assert!(offset_of!(TemplateElement, span) == 0);
106-
assert!(offset_of!(TemplateElement, tail) == 8);
107-
assert!(offset_of!(TemplateElement, value) == 16);
106+
assert!(offset_of!(TemplateElement, value) == 8);
107+
assert!(offset_of!(TemplateElement, tail) == 40);
108108

109109
assert!(size_of::<TemplateElementValue>() == 32);
110110
assert!(align_of::<TemplateElementValue>() == 8);
@@ -1508,8 +1508,8 @@ const _: () = {
15081508
assert!(size_of::<TemplateElement>() == 28);
15091509
assert!(align_of::<TemplateElement>() == 4);
15101510
assert!(offset_of!(TemplateElement, span) == 0);
1511-
assert!(offset_of!(TemplateElement, tail) == 8);
1512-
assert!(offset_of!(TemplateElement, value) == 12);
1511+
assert!(offset_of!(TemplateElement, value) == 8);
1512+
assert!(offset_of!(TemplateElement, tail) == 24);
15131513

15141514
assert!(size_of::<TemplateElementValue>() == 16);
15151515
assert!(align_of::<TemplateElementValue>() == 4);

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,16 +1863,16 @@ impl<'a> AstBuilder<'a> {
18631863
///
18641864
/// ## Parameters
18651865
/// * `span`: The [`Span`] covering this node
1866-
/// * `tail`
18671866
/// * `value`
1867+
/// * `tail`
18681868
#[inline]
18691869
pub fn template_element(
18701870
self,
18711871
span: Span,
1872-
tail: bool,
18731872
value: TemplateElementValue<'a>,
1873+
tail: bool,
18741874
) -> TemplateElement<'a> {
1875-
TemplateElement { span, tail, value }
1875+
TemplateElement { span, value, tail }
18761876
}
18771877

18781878
/// Build a [`TemplateElement`], and store it in the memory arena.
@@ -1881,16 +1881,16 @@ impl<'a> AstBuilder<'a> {
18811881
///
18821882
/// ## Parameters
18831883
/// * `span`: The [`Span`] covering this node
1884-
/// * `tail`
18851884
/// * `value`
1885+
/// * `tail`
18861886
#[inline]
18871887
pub fn alloc_template_element(
18881888
self,
18891889
span: Span,
1890-
tail: bool,
18911890
value: TemplateElementValue<'a>,
1891+
tail: bool,
18921892
) -> Box<'a, TemplateElement<'a>> {
1893-
Box::new_in(self.template_element(span, tail, value), self.allocator)
1893+
Box::new_in(self.template_element(span, value, tail), self.allocator)
18941894
}
18951895

18961896
/// Build a [`MemberExpression::ComputedMemberExpression`].

crates/oxc_ast/src/generated/derive_clone_in.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ impl<'new_alloc> CloneIn<'new_alloc> for TemplateElement<'_> {
552552
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
553553
TemplateElement {
554554
span: CloneIn::clone_in(&self.span, allocator),
555-
tail: CloneIn::clone_in(&self.tail, allocator),
556555
value: CloneIn::clone_in(&self.value, allocator),
556+
tail: CloneIn::clone_in(&self.tail, allocator),
557557
}
558558
}
559559
}

crates/oxc_ast/src/generated/derive_content_eq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ impl ContentEq for TaggedTemplateExpression<'_> {
289289

290290
impl ContentEq for TemplateElement<'_> {
291291
fn content_eq(&self, other: &Self) -> bool {
292-
ContentEq::content_eq(&self.tail, &other.tail)
293-
&& ContentEq::content_eq(&self.value, &other.value)
292+
ContentEq::content_eq(&self.value, &other.value)
293+
&& ContentEq::content_eq(&self.tail, &other.tail)
294294
}
295295
}
296296

crates/oxc_minifier/src/peephole/remove_unused_expression.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ impl<'a> PeepholeOptimizations {
305305
iter::repeat_with(|| {
306306
ctx.ast.template_element(
307307
e.span(),
308-
false,
309308
TemplateElementValue { raw: "".into(), cooked: Some("".into()) },
309+
false,
310310
)
311311
})
312312
.take(expressions.len() + 1),
@@ -331,8 +331,8 @@ impl<'a> PeepholeOptimizations {
331331
iter::repeat_with(|| {
332332
ctx.ast.template_element(
333333
temp_lit.span,
334-
false,
335334
TemplateElementValue { raw: "".into(), cooked: Some("".into()) },
335+
false,
336336
)
337337
})
338338
.take(expressions.len() + 1),

crates/oxc_minifier/src/peephole/replace_known_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,12 @@ impl<'a> PeepholeOptimizations {
738738
let cooked = s.clone().into_in(ctx.ast.allocator);
739739
ctx.ast.template_element(
740740
SPAN,
741-
false,
742741
TemplateElementValue {
743742
raw: Self::escape_string_for_template_literal(&s)
744743
.into_in(ctx.ast.allocator),
745744
cooked: Some(cooked),
746745
},
746+
false,
747747
)
748748
}));
749749
if let Some(last_quasi) = quasis.last_mut() {

crates/oxc_parser/src/js/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ impl<'a> ParserImpl<'a> {
546546
let tail = matches!(cur_kind, Kind::TemplateTail | Kind::NoSubstitutionTemplate);
547547
self.ast.template_element(
548548
span,
549-
tail,
550549
TemplateElementValue { raw, cooked: cooked.map(Atom::from) },
550+
tail,
551551
)
552552
}
553553

napi/parser/deserialize-js.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ function deserializeTemplateElement(pos) {
152152
type: 'TemplateElement',
153153
start: deserializeU32(pos),
154154
end: deserializeU32(pos + 4),
155-
value: deserializeTemplateElementValue(pos + 16),
156-
tail: deserializeBool(pos + 8),
155+
value: deserializeTemplateElementValue(pos + 8),
156+
tail: deserializeBool(pos + 40),
157157
};
158158
}
159159

napi/parser/deserialize-ts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ function deserializeTemplateElement(pos) {
153153
type: 'TemplateElement',
154154
start: deserializeU32(pos),
155155
end: deserializeU32(pos + 4),
156-
value: deserializeTemplateElementValue(pos + 16),
157-
tail: deserializeBool(pos + 8),
156+
value: deserializeTemplateElementValue(pos + 8),
157+
tail: deserializeBool(pos + 40),
158158
};
159159
}
160160

0 commit comments

Comments
 (0)