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
9 changes: 6 additions & 3 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,21 @@ pub struct TemplateLiteral<'a> {
pub expressions: Vec<'a, Expression<'a>>,
}

/// `` foo`Hello, ${name}` `` in `` const foo = foo`Hello, ${name}` ``
/// `` tag`Hello, ${name}` `` in `` const foo = tag`Hello, ${name}`; ``.
///
/// Represents a tagged template expression, which can include a tag and a quasi.
/// Or with TS type arguments:
/// ```ts
/// const foo = tag<T>`Hello, ${name}`;
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
pub struct TaggedTemplateExpression<'a> {
pub span: Span,
pub tag: Expression<'a>,
pub quasi: TemplateLiteral<'a>,
#[ts]
pub type_arguments: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
pub quasi: TemplateLiteral<'a>,
}

/// `Hello, ` in `` `Hello, ${name}` ``
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ const _: () = {
assert!(align_of::<TaggedTemplateExpression>() == 8);
assert!(offset_of!(TaggedTemplateExpression, span) == 0);
assert!(offset_of!(TaggedTemplateExpression, tag) == 8);
assert!(offset_of!(TaggedTemplateExpression, quasi) == 24);
assert!(offset_of!(TaggedTemplateExpression, type_arguments) == 96);
assert!(offset_of!(TaggedTemplateExpression, type_arguments) == 24);
assert!(offset_of!(TaggedTemplateExpression, quasi) == 32);

assert!(size_of::<TemplateElement>() == 48);
assert!(align_of::<TemplateElement>() == 8);
Expand Down Expand Up @@ -1490,8 +1490,8 @@ const _: () = {
assert!(align_of::<TaggedTemplateExpression>() == 4);
assert!(offset_of!(TaggedTemplateExpression, span) == 0);
assert!(offset_of!(TaggedTemplateExpression, tag) == 8);
assert!(offset_of!(TaggedTemplateExpression, quasi) == 16);
assert!(offset_of!(TaggedTemplateExpression, type_arguments) == 56);
assert!(offset_of!(TaggedTemplateExpression, type_arguments) == 16);
assert!(offset_of!(TaggedTemplateExpression, quasi) == 20);

assert!(size_of::<TemplateElement>() == 28);
assert!(align_of::<TemplateElement>() == 4);
Expand Down
18 changes: 9 additions & 9 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,24 +934,24 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `tag`
/// * `quasi`
/// * `type_arguments`
/// * `quasi`
#[inline]
pub fn expression_tagged_template<T1>(
self,
span: Span,
tag: Expression<'a>,
quasi: TemplateLiteral<'a>,
type_arguments: T1,
quasi: TemplateLiteral<'a>,
) -> Expression<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
{
Expression::TaggedTemplateExpression(self.alloc_tagged_template_expression(
span,
tag,
quasi,
type_arguments,
quasi,
))
}

Expand Down Expand Up @@ -1720,24 +1720,24 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `tag`
/// * `quasi`
/// * `type_arguments`
/// * `quasi`
#[inline]
pub fn tagged_template_expression<T1>(
self,
span: Span,
tag: Expression<'a>,
quasi: TemplateLiteral<'a>,
type_arguments: T1,
quasi: TemplateLiteral<'a>,
) -> TaggedTemplateExpression<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
{
TaggedTemplateExpression {
span,
tag,
quasi,
type_arguments: type_arguments.into_in(self.allocator),
quasi,
}
}

Expand All @@ -1749,21 +1749,21 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `tag`
/// * `quasi`
/// * `type_arguments`
/// * `quasi`
#[inline]
pub fn alloc_tagged_template_expression<T1>(
self,
span: Span,
tag: Expression<'a>,
quasi: TemplateLiteral<'a>,
type_arguments: T1,
quasi: TemplateLiteral<'a>,
) -> Box<'a, TaggedTemplateExpression<'a>>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
{
Box::new_in(
self.tagged_template_expression(span, tag, quasi, type_arguments),
self.tagged_template_expression(span, tag, type_arguments, quasi),
self.allocator,
)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,17 +1070,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for TaggedTemplateExpression<'_> {
TaggedTemplateExpression {
span: CloneIn::clone_in(&self.span, allocator),
tag: CloneIn::clone_in(&self.tag, allocator),
quasi: CloneIn::clone_in(&self.quasi, allocator),
type_arguments: CloneIn::clone_in(&self.type_arguments, allocator),
quasi: CloneIn::clone_in(&self.quasi, allocator),
}
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
TaggedTemplateExpression {
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
tag: CloneIn::clone_in_with_semantic_ids(&self.tag, allocator),
quasi: CloneIn::clone_in_with_semantic_ids(&self.quasi, allocator),
type_arguments: CloneIn::clone_in_with_semantic_ids(&self.type_arguments, allocator),
quasi: CloneIn::clone_in_with_semantic_ids(&self.quasi, allocator),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ impl ContentEq for TemplateLiteral<'_> {
impl ContentEq for TaggedTemplateExpression<'_> {
fn content_eq(&self, other: &Self) -> bool {
ContentEq::content_eq(&self.tag, &other.tag)
&& ContentEq::content_eq(&self.quasi, &other.quasi)
&& ContentEq::content_eq(&self.type_arguments, &other.type_arguments)
&& ContentEq::content_eq(&self.quasi, &other.quasi)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ impl<'a> Dummy<'a> for TaggedTemplateExpression<'a> {
Self {
span: Dummy::dummy(allocator),
tag: Dummy::dummy(allocator),
quasi: Dummy::dummy(allocator),
type_arguments: Dummy::dummy(allocator),
quasi: Dummy::dummy(allocator),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,10 +1554,10 @@ pub mod walk {
visitor.enter_node(kind);
visitor.visit_span(&it.span);
visitor.visit_expression(&it.tag);
visitor.visit_template_literal(&it.quasi);
if let Some(type_arguments) = &it.type_arguments {
visitor.visit_ts_type_parameter_instantiation(type_arguments);
}
visitor.visit_template_literal(&it.quasi);
visitor.leave_node(kind);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,10 +1564,10 @@ pub mod walk_mut {
visitor.enter_node(kind);
visitor.visit_span(&mut it.span);
visitor.visit_expression(&mut it.tag);
visitor.visit_template_literal(&mut it.quasi);
if let Some(type_arguments) = &mut it.type_arguments {
visitor.visit_ts_type_parameter_instantiation(type_arguments);
}
visitor.visit_template_literal(&mut it.quasi);
visitor.leave_node(kind);
}

Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl<'a> ParserImpl<'a> {
span: u32,
lhs: Expression<'a>,
in_optional_chain: bool,
type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
type_arguments: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
) -> Expression<'a> {
let quasi = self.parse_template_literal(true);
let span = self.end_span(span);
Expand All @@ -525,7 +525,7 @@ impl<'a> ParserImpl<'a> {
if in_optional_chain {
self.error(diagnostics::optional_chain_tagged_template(quasi.span));
}
self.ast.expression_tagged_template(span, lhs, quasi, type_parameters)
self.ast.expression_tagged_template(span, lhs, type_arguments, quasi)
}

pub(crate) fn parse_template_element(&mut self, tagged: bool) -> TemplateElement<'a> {
Expand Down Expand Up @@ -761,15 +761,15 @@ impl<'a> ParserImpl<'a> {
}

if self.cur_kind().is_template_start_of_tagged_template() {
let (expr, type_parameters) =
let (expr, type_arguments) =
if let Expression::TSInstantiationExpression(instantiation_expr) = lhs {
let expr = instantiation_expr.unbox();
(expr.expression, Some(expr.type_arguments))
} else {
(lhs, None)
};
lhs =
self.parse_tagged_template(lhs_span, expr, *in_optional_chain, type_parameters);
self.parse_tagged_template(lhs_span, expr, *in_optional_chain, type_arguments);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "StyledPaymentProps",
"node_id": 31
"node_id": 30
}
]
},
Expand Down
52 changes: 26 additions & 26 deletions crates/oxc_traverse/src/generated/ancestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub(crate) enum AncestorType {
TemplateLiteralQuasis = 8,
TemplateLiteralExpressions = 9,
TaggedTemplateExpressionTag = 10,
TaggedTemplateExpressionQuasi = 11,
TaggedTemplateExpressionTypeArguments = 12,
TaggedTemplateExpressionTypeArguments = 11,
TaggedTemplateExpressionQuasi = 12,
ComputedMemberExpressionObject = 13,
ComputedMemberExpressionExpression = 14,
StaticMemberExpressionObject = 15,
Expand Down Expand Up @@ -355,10 +355,10 @@ pub enum Ancestor<'a, 't> {
AncestorType::TemplateLiteralExpressions as u16,
TaggedTemplateExpressionTag(TaggedTemplateExpressionWithoutTag<'a, 't>) =
AncestorType::TaggedTemplateExpressionTag as u16,
TaggedTemplateExpressionQuasi(TaggedTemplateExpressionWithoutQuasi<'a, 't>) =
AncestorType::TaggedTemplateExpressionQuasi as u16,
TaggedTemplateExpressionTypeArguments(TaggedTemplateExpressionWithoutTypeArguments<'a, 't>) =
AncestorType::TaggedTemplateExpressionTypeArguments as u16,
TaggedTemplateExpressionQuasi(TaggedTemplateExpressionWithoutQuasi<'a, 't>) =
AncestorType::TaggedTemplateExpressionQuasi as u16,
ComputedMemberExpressionObject(ComputedMemberExpressionWithoutObject<'a, 't>) =
AncestorType::ComputedMemberExpressionObject as u16,
ComputedMemberExpressionExpression(ComputedMemberExpressionWithoutExpression<'a, 't>) =
Expand Down Expand Up @@ -919,8 +919,8 @@ impl<'a, 't> Ancestor<'a, 't> {
matches!(
self,
Self::TaggedTemplateExpressionTag(_)
| Self::TaggedTemplateExpressionQuasi(_)
| Self::TaggedTemplateExpressionTypeArguments(_)
| Self::TaggedTemplateExpressionQuasi(_)
)
}

Expand Down Expand Up @@ -2208,8 +2208,8 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> {
Self::TemplateLiteralQuasis(a) => a.address(),
Self::TemplateLiteralExpressions(a) => a.address(),
Self::TaggedTemplateExpressionTag(a) => a.address(),
Self::TaggedTemplateExpressionQuasi(a) => a.address(),
Self::TaggedTemplateExpressionTypeArguments(a) => a.address(),
Self::TaggedTemplateExpressionQuasi(a) => a.address(),
Self::ComputedMemberExpressionObject(a) => a.address(),
Self::ComputedMemberExpressionExpression(a) => a.address(),
Self::StaticMemberExpressionObject(a) => a.address(),
Expand Down Expand Up @@ -2898,10 +2898,10 @@ pub(crate) const OFFSET_TAGGED_TEMPLATE_EXPRESSION_SPAN: usize =
offset_of!(TaggedTemplateExpression, span);
pub(crate) const OFFSET_TAGGED_TEMPLATE_EXPRESSION_TAG: usize =
offset_of!(TaggedTemplateExpression, tag);
pub(crate) const OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI: usize =
offset_of!(TaggedTemplateExpression, quasi);
pub(crate) const OFFSET_TAGGED_TEMPLATE_EXPRESSION_TYPE_ARGUMENTS: usize =
offset_of!(TaggedTemplateExpression, type_arguments);
pub(crate) const OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI: usize =
offset_of!(TaggedTemplateExpression, quasi);

#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
Expand All @@ -2919,18 +2919,18 @@ impl<'a, 't> TaggedTemplateExpressionWithoutTag<'a, 't> {
}

#[inline]
pub fn quasi(self) -> &'t TemplateLiteral<'a> {
pub fn type_arguments(self) -> &'t Option<Box<'a, TSTypeParameterInstantiation<'a>>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
as *const TemplateLiteral<'a>)
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_TYPE_ARGUMENTS)
as *const Option<Box<'a, TSTypeParameterInstantiation<'a>>>)
}
}

#[inline]
pub fn type_arguments(self) -> &'t Option<Box<'a, TSTypeParameterInstantiation<'a>>> {
pub fn quasi(self) -> &'t TemplateLiteral<'a> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_TYPE_ARGUMENTS)
as *const Option<Box<'a, TSTypeParameterInstantiation<'a>>>)
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
as *const TemplateLiteral<'a>)
}
}
}
Expand All @@ -2944,12 +2944,12 @@ impl<'a, 't> GetAddress for TaggedTemplateExpressionWithoutTag<'a, 't> {

#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct TaggedTemplateExpressionWithoutQuasi<'a, 't>(
pub struct TaggedTemplateExpressionWithoutTypeArguments<'a, 't>(
pub(crate) *const TaggedTemplateExpression<'a>,
pub(crate) PhantomData<&'t ()>,
);

impl<'a, 't> TaggedTemplateExpressionWithoutQuasi<'a, 't> {
impl<'a, 't> TaggedTemplateExpressionWithoutTypeArguments<'a, 't> {
#[inline]
pub fn span(self) -> &'t Span {
unsafe {
Expand All @@ -2966,15 +2966,15 @@ impl<'a, 't> TaggedTemplateExpressionWithoutQuasi<'a, 't> {
}

#[inline]
pub fn type_arguments(self) -> &'t Option<Box<'a, TSTypeParameterInstantiation<'a>>> {
pub fn quasi(self) -> &'t TemplateLiteral<'a> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_TYPE_ARGUMENTS)
as *const Option<Box<'a, TSTypeParameterInstantiation<'a>>>)
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
as *const TemplateLiteral<'a>)
}
}
}

impl<'a, 't> GetAddress for TaggedTemplateExpressionWithoutQuasi<'a, 't> {
impl<'a, 't> GetAddress for TaggedTemplateExpressionWithoutTypeArguments<'a, 't> {
#[inline]
fn address(&self) -> Address {
Address::from_ptr(self.0)
Expand All @@ -2983,12 +2983,12 @@ impl<'a, 't> GetAddress for TaggedTemplateExpressionWithoutQuasi<'a, 't> {

#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
pub struct TaggedTemplateExpressionWithoutTypeArguments<'a, 't>(
pub struct TaggedTemplateExpressionWithoutQuasi<'a, 't>(
pub(crate) *const TaggedTemplateExpression<'a>,
pub(crate) PhantomData<&'t ()>,
);

impl<'a, 't> TaggedTemplateExpressionWithoutTypeArguments<'a, 't> {
impl<'a, 't> TaggedTemplateExpressionWithoutQuasi<'a, 't> {
#[inline]
pub fn span(self) -> &'t Span {
unsafe {
Expand All @@ -3005,15 +3005,15 @@ impl<'a, 't> TaggedTemplateExpressionWithoutTypeArguments<'a, 't> {
}

#[inline]
pub fn quasi(self) -> &'t TemplateLiteral<'a> {
pub fn type_arguments(self) -> &'t Option<Box<'a, TSTypeParameterInstantiation<'a>>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
as *const TemplateLiteral<'a>)
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_TYPE_ARGUMENTS)
as *const Option<Box<'a, TSTypeParameterInstantiation<'a>>>)
}
}
}

impl<'a, 't> GetAddress for TaggedTemplateExpressionWithoutTypeArguments<'a, 't> {
impl<'a, 't> GetAddress for TaggedTemplateExpressionWithoutQuasi<'a, 't> {
#[inline]
fn address(&self) -> Address {
Address::from_ptr(self.0)
Expand Down
Loading
Loading