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
4 changes: 3 additions & 1 deletion crates/oxc_ast/src/ast/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ macro_rules! inherit_variants {
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0,
/// Inherited from [`TSTypeName`]
QualifiedName(Box<'a, TSQualifiedName<'a>>) = 1,
/// Inherited from [`TSTypeName`]
ThisExpression(Box<'a, ThisExpression>) = 2,

$($rest)*
}
Expand All @@ -717,7 +719,7 @@ macro_rules! inherit_variants {
as_ts_type_name_mut,
to_ts_type_name,
to_ts_type_name_mut,
[IdentifierReference, QualifiedName]
[IdentifierReference, QualifiedName, ThisExpression]
);
};

Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,21 +769,22 @@ pub struct TSTypeReference<'a> {

/// TSTypeName:
/// IdentifierReference
/// this
/// TSTypeName . IdentifierName
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum TSTypeName<'a> {
#[estree(via = TSTypeNameIdentifierReference)]
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0,
QualifiedName(Box<'a, TSQualifiedName<'a>>) = 1,
ThisExpression(Box<'a, ThisExpression>) = 2,
}

/// Macro for matching `TSTypeName`'s variants.
#[macro_export]
macro_rules! match_ts_type_name {
($ty:ident) => {
$ty::IdentifierReference(_) | $ty::QualifiedName(_)
$ty::IdentifierReference(_) | $ty::QualifiedName(_) | $ty::ThisExpression(_)
};
}
pub use match_ts_type_name;
Expand Down Expand Up @@ -1335,7 +1336,7 @@ inherit_variants! {
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum TSTypeQueryExprName<'a> {
/// `type foo = typeof import('foo')`
TSImportType(Box<'a, TSImportType<'a>>) = 2,
TSImportType(Box<'a, TSImportType<'a>>) = 3,
// `TSTypeName` variants added here by `inherit_variants!` macro
@inherit TSTypeName
}
Expand Down Expand Up @@ -1585,7 +1586,7 @@ inherit_variants! {
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum TSModuleReference<'a> {
ExternalModuleReference(Box<'a, TSExternalModuleReference<'a>>) = 2,
ExternalModuleReference(Box<'a, TSExternalModuleReference<'a>>) = 3,
// `TSTypeName` variants added here by `inherit_variants!` macro
@inherit TSTypeName
}
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl<'a> TSType<'a> {
/// returned.
pub fn get_identifier_reference(&self) -> Option<&IdentifierReference<'a>> {
match self {
TSType::TSTypeReference(reference) => {
Some(reference.type_name.get_identifier_reference())
}
TSType::TSTypeReference(reference) => reference.type_name.get_identifier_reference(),
TSType::TSTypeQuery(query) => match &query.expr_name {
TSTypeQueryExprName::IdentifierReference(ident) => Some(ident),
_ => None,
Expand Down Expand Up @@ -86,10 +84,11 @@ impl<'a> TSTypeName<'a> {
/// type Foo = Bar; // -> Bar
/// type Foo = Bar.Baz; // -> Bar
/// ```
pub fn get_identifier_reference(&self) -> &IdentifierReference<'a> {
pub fn get_identifier_reference(&self) -> Option<&IdentifierReference<'a>> {
match self {
TSTypeName::IdentifierReference(ident) => ident,
TSTypeName::IdentifierReference(ident) => Some(ident),
TSTypeName::QualifiedName(name) => name.left.get_identifier_reference(),
TSTypeName::ThisExpression(_) => None,
}
}

Expand Down Expand Up @@ -120,6 +119,7 @@ impl fmt::Display for TSTypeName<'_> {
match self {
TSTypeName::IdentifierReference(ident) => ident.fmt(f),
TSTypeName::QualifiedName(qualified) => qualified.fmt(f),
TSTypeName::ThisExpression(_) => "this".fmt(f),
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11748,6 +11748,17 @@ impl<'a> AstBuilder<'a> {
TSTypeName::QualifiedName(self.alloc_ts_qualified_name(span, left, right))
}

/// Build a [`TSTypeName::ThisExpression`].
///
/// This node contains a [`ThisExpression`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
#[inline]
pub fn ts_type_name_this_expression(self, span: Span) -> TSTypeName<'a> {
TSTypeName::ThisExpression(self.alloc_this_expression(span))
}

/// Build a [`TSQualifiedName`].
///
/// If you want the built node to be allocated in the memory arena,
Expand Down
18 changes: 18 additions & 0 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6714,6 +6714,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeName<'_> {
TSTypeName::IdentifierReference(CloneIn::clone_in(it, allocator))
}
Self::QualifiedName(it) => TSTypeName::QualifiedName(CloneIn::clone_in(it, allocator)),
Self::ThisExpression(it) => {
TSTypeName::ThisExpression(CloneIn::clone_in(it, allocator))
}
}
}

Expand All @@ -6725,6 +6728,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeName<'_> {
Self::QualifiedName(it) => {
TSTypeName::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator))
}
Self::ThisExpression(it) => {
TSTypeName::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator))
}
}
}
}
Expand Down Expand Up @@ -7379,6 +7385,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeQueryExprName<'_> {
Self::QualifiedName(it) => {
TSTypeQueryExprName::QualifiedName(CloneIn::clone_in(it, allocator))
}
Self::ThisExpression(it) => {
TSTypeQueryExprName::ThisExpression(CloneIn::clone_in(it, allocator))
}
}
}

Expand All @@ -7393,6 +7402,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeQueryExprName<'_> {
Self::QualifiedName(it) => TSTypeQueryExprName::QualifiedName(
CloneIn::clone_in_with_semantic_ids(it, allocator),
),
Self::ThisExpression(it) => TSTypeQueryExprName::ThisExpression(
CloneIn::clone_in_with_semantic_ids(it, allocator),
),
}
}
}
Expand Down Expand Up @@ -7632,6 +7644,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleReference<'_> {
Self::QualifiedName(it) => {
TSModuleReference::QualifiedName(CloneIn::clone_in(it, allocator))
}
Self::ThisExpression(it) => {
TSModuleReference::ThisExpression(CloneIn::clone_in(it, allocator))
}
}
}

Expand All @@ -7646,6 +7661,9 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleReference<'_> {
Self::QualifiedName(it) => {
TSModuleReference::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator))
}
Self::ThisExpression(it) => TSModuleReference::ThisExpression(
CloneIn::clone_in_with_semantic_ids(it, allocator),
),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,7 @@ impl ContentEq for TSTypeName<'_> {
match (self, other) {
(Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b),
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
(Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b),
_ => false,
}
}
Expand Down Expand Up @@ -2306,6 +2307,7 @@ impl ContentEq for TSTypeQueryExprName<'_> {
(Self::TSImportType(a), Self::TSImportType(b)) => a.content_eq(b),
(Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b),
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
(Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b),
_ => false,
}
}
Expand Down Expand Up @@ -2396,6 +2398,7 @@ impl ContentEq for TSModuleReference<'_> {
(Self::ExternalModuleReference(a), Self::ExternalModuleReference(b)) => a.content_eq(b),
(Self::IdentifierReference(a), Self::IdentifierReference(b)) => a.content_eq(b),
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
(Self::ThisExpression(a), Self::ThisExpression(b)) => a.content_eq(b),
_ => false,
}
}
Expand Down
22 changes: 11 additions & 11 deletions crates/oxc_ast/src/generated/derive_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ impl<'a> Dummy<'a> for TSBigIntKeyword {
impl<'a> Dummy<'a> for TSTypeReference<'a> {
/// Create a dummy [`TSTypeReference`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
Expand All @@ -2245,16 +2245,16 @@ impl<'a> Dummy<'a> for TSTypeReference<'a> {
impl<'a> Dummy<'a> for TSTypeName<'a> {
/// Create a dummy [`TSTypeName`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self::IdentifierReference(Dummy::dummy(allocator))
Self::ThisExpression(Dummy::dummy(allocator))
}
}

impl<'a> Dummy<'a> for TSQualifiedName<'a> {
/// Create a dummy [`TSQualifiedName`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
Expand Down Expand Up @@ -2328,7 +2328,7 @@ impl<'a> Dummy<'a> for TSAccessibility {
impl<'a> Dummy<'a> for TSClassImplements<'a> {
/// Create a dummy [`TSClassImplements`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
Expand Down Expand Up @@ -2591,7 +2591,7 @@ impl<'a> Dummy<'a> for TSInferType<'a> {
impl<'a> Dummy<'a> for TSTypeQuery<'a> {
/// Create a dummy [`TSTypeQuery`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
Expand All @@ -2604,9 +2604,9 @@ impl<'a> Dummy<'a> for TSTypeQuery<'a> {
impl<'a> Dummy<'a> for TSTypeQueryExprName<'a> {
/// Create a dummy [`TSTypeQueryExprName`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self::IdentifierReference(Dummy::dummy(allocator))
Self::ThisExpression(Dummy::dummy(allocator))
}
}

Expand Down Expand Up @@ -2738,7 +2738,7 @@ impl<'a> Dummy<'a> for TSTypeAssertion<'a> {
impl<'a> Dummy<'a> for TSImportEqualsDeclaration<'a> {
/// Create a dummy [`TSImportEqualsDeclaration`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
Expand All @@ -2752,9 +2752,9 @@ impl<'a> Dummy<'a> for TSImportEqualsDeclaration<'a> {
impl<'a> Dummy<'a> for TSModuleReference<'a> {
/// Create a dummy [`TSModuleReference`].
///
/// Has cost of making 1 allocation (32 bytes).
/// Has cost of making 1 allocation (8 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self::IdentifierReference(Dummy::dummy(allocator))
Self::ThisExpression(Dummy::dummy(allocator))
}
}

Expand Down
15 changes: 6 additions & 9 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2628,10 +2628,9 @@ impl ESTree for TSTypeReference<'_> {
impl ESTree for TSTypeName<'_> {
fn serialize<S: Serializer>(&self, serializer: S) {
match self {
Self::IdentifierReference(it) => {
crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer)
}
Self::IdentifierReference(it) => it.serialize(serializer),
Self::QualifiedName(it) => it.serialize(serializer),
Self::ThisExpression(it) => it.serialize(serializer),
}
}
}
Expand Down Expand Up @@ -2965,10 +2964,9 @@ impl ESTree for TSTypeQueryExprName<'_> {
fn serialize<S: Serializer>(&self, serializer: S) {
match self {
Self::TSImportType(it) => it.serialize(serializer),
Self::IdentifierReference(it) => {
crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer)
}
Self::IdentifierReference(it) => it.serialize(serializer),
Self::QualifiedName(it) => it.serialize(serializer),
Self::ThisExpression(it) => it.serialize(serializer),
}
}
}
Expand Down Expand Up @@ -3096,10 +3094,9 @@ impl ESTree for TSModuleReference<'_> {
fn serialize<S: Serializer>(&self, serializer: S) {
match self {
Self::ExternalModuleReference(it) => it.serialize(serializer),
Self::IdentifierReference(it) => {
crate::serialize::ts::TSTypeNameIdentifierReference(it).serialize(serializer)
}
Self::IdentifierReference(it) => it.serialize(serializer),
Self::QualifiedName(it) => it.serialize(serializer),
Self::ThisExpression(it) => it.serialize(serializer),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_ast/src/generated/derive_get_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ impl GetAddress for TSTypeName<'_> {
match self {
Self::IdentifierReference(it) => GetAddress::address(it),
Self::QualifiedName(it) => GetAddress::address(it),
Self::ThisExpression(it) => GetAddress::address(it),
}
}
}
Expand Down Expand Up @@ -764,6 +765,7 @@ impl GetAddress for TSTypeQueryExprName<'_> {
Self::TSImportType(it) => GetAddress::address(it),
Self::IdentifierReference(it) => GetAddress::address(it),
Self::QualifiedName(it) => GetAddress::address(it),
Self::ThisExpression(it) => GetAddress::address(it),
}
}
}
Expand All @@ -776,6 +778,7 @@ impl GetAddress for TSModuleReference<'_> {
Self::ExternalModuleReference(it) => GetAddress::address(it),
Self::IdentifierReference(it) => GetAddress::address(it),
Self::QualifiedName(it) => GetAddress::address(it),
Self::ThisExpression(it) => GetAddress::address(it),
}
}
}
3 changes: 3 additions & 0 deletions crates/oxc_ast/src/generated/derive_get_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,7 @@ impl GetSpan for TSTypeName<'_> {
match self {
Self::IdentifierReference(it) => GetSpan::span(&**it),
Self::QualifiedName(it) => GetSpan::span(&**it),
Self::ThisExpression(it) => GetSpan::span(&**it),
}
}
}
Expand Down Expand Up @@ -2013,6 +2014,7 @@ impl GetSpan for TSTypeQueryExprName<'_> {
Self::TSImportType(it) => GetSpan::span(&**it),
Self::IdentifierReference(it) => GetSpan::span(&**it),
Self::QualifiedName(it) => GetSpan::span(&**it),
Self::ThisExpression(it) => GetSpan::span(&**it),
}
}
}
Expand Down Expand Up @@ -2086,6 +2088,7 @@ impl GetSpan for TSModuleReference<'_> {
Self::ExternalModuleReference(it) => GetSpan::span(&**it),
Self::IdentifierReference(it) => GetSpan::span(&**it),
Self::QualifiedName(it) => GetSpan::span(&**it),
Self::ThisExpression(it) => GetSpan::span(&**it),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_ast/src/generated/derive_get_span_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,7 @@ impl GetSpanMut for TSTypeName<'_> {
match self {
Self::IdentifierReference(it) => GetSpanMut::span_mut(&mut **it),
Self::QualifiedName(it) => GetSpanMut::span_mut(&mut **it),
Self::ThisExpression(it) => GetSpanMut::span_mut(&mut **it),
}
}
}
Expand Down Expand Up @@ -2013,6 +2014,7 @@ impl GetSpanMut for TSTypeQueryExprName<'_> {
Self::TSImportType(it) => GetSpanMut::span_mut(&mut **it),
Self::IdentifierReference(it) => GetSpanMut::span_mut(&mut **it),
Self::QualifiedName(it) => GetSpanMut::span_mut(&mut **it),
Self::ThisExpression(it) => GetSpanMut::span_mut(&mut **it),
}
}
}
Expand Down Expand Up @@ -2086,6 +2088,7 @@ impl GetSpanMut for TSModuleReference<'_> {
Self::ExternalModuleReference(it) => GetSpanMut::span_mut(&mut **it),
Self::IdentifierReference(it) => GetSpanMut::span_mut(&mut **it),
Self::QualifiedName(it) => GetSpanMut::span_mut(&mut **it),
Self::ThisExpression(it) => GetSpanMut::span_mut(&mut **it),
}
}
}
Expand Down
Loading
Loading