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
30 changes: 29 additions & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,10 +1359,38 @@ pub struct TSImportType<'a> {
pub span: Span,
pub argument: TSType<'a>,
pub options: Option<Box<'a, ObjectExpression<'a>>>,
pub qualifier: Option<TSTypeName<'a>>,
pub qualifier: Option<TSImportTypeQualifier<'a>>,
pub type_arguments: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
}

/// TypeScript Import Type Qualifier
///
/// The qualifier part of an import type that doesn't create references.
/// In `import("./a").b.c`, the `.b.c` part is the qualifier.
///
/// Unlike `TSTypeName`, this doesn't use `IdentifierReference` because
/// these are not references to identifiers in scope, but rather property
/// accesses on the imported module type.
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
pub enum TSImportTypeQualifier<'a> {
Identifier(Box<'a, IdentifierName<'a>>) = 0,
QualifiedName(Box<'a, TSImportTypeQualifiedName<'a>>) = 1,
}

/// TypeScript Import Type Qualified Name
///
/// A qualified name in an import type (e.g., `a.b.c` in `import("./module").a.b.c`)
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
pub struct TSImportTypeQualifiedName<'a> {
pub span: Span,
pub left: TSImportTypeQualifier<'a>,
pub right: IdentifierName<'a>,
}

/// TypeScript Function Type
///
/// ## Examples
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ impl AstKind<'_> {
"AssignmentTargetPropertyIdentifier".into()
}
Self::AssignmentTargetPropertyProperty(_) => "AssignmentTargetPropertyProperty".into(),
Self::TSImportTypeQualifiedName(_) => "TSImportTypeQualifiedName".into(),
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,16 @@ const _: () = {
assert!(offset_of!(TSImportType, qualifier) == 32);
assert!(offset_of!(TSImportType, type_arguments) == 48);

assert!(size_of::<TSImportTypeQualifier>() == 16);
assert!(align_of::<TSImportTypeQualifier>() == 8);

// Padding: 0 bytes
assert!(size_of::<TSImportTypeQualifiedName>() == 48);
assert!(align_of::<TSImportTypeQualifiedName>() == 8);
assert!(offset_of!(TSImportTypeQualifiedName, span) == 0);
assert!(offset_of!(TSImportTypeQualifiedName, left) == 8);
assert!(offset_of!(TSImportTypeQualifiedName, right) == 24);

// Padding: 4 bytes
assert!(size_of::<TSFunctionType>() == 48);
assert!(align_of::<TSFunctionType>() == 8);
Expand Down Expand Up @@ -3042,6 +3052,16 @@ const _: () = {
assert!(offset_of!(TSImportType, qualifier) == 20);
assert!(offset_of!(TSImportType, type_arguments) == 28);

assert!(size_of::<TSImportTypeQualifier>() == 8);
assert!(align_of::<TSImportTypeQualifier>() == 4);

// Padding: 0 bytes
assert!(size_of::<TSImportTypeQualifiedName>() == 32);
assert!(align_of::<TSImportTypeQualifiedName>() == 4);
assert!(offset_of!(TSImportTypeQualifiedName, span) == 0);
assert!(offset_of!(TSImportTypeQualifiedName, left) == 8);
assert!(offset_of!(TSImportTypeQualifiedName, right) == 16);

// Padding: 0 bytes
assert!(size_of::<TSFunctionType>() == 28);
assert!(align_of::<TSFunctionType>() == 4);
Expand Down
85 changes: 81 additions & 4 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10486,7 +10486,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
argument: TSType<'a>,
options: T1,
qualifier: Option<TSTypeName<'a>>,
qualifier: Option<TSImportTypeQualifier<'a>>,
type_arguments: T2,
) -> TSType<'a>
where
Expand Down Expand Up @@ -13665,7 +13665,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
argument: TSType<'a>,
options: T1,
qualifier: Option<TSTypeName<'a>>,
qualifier: Option<TSImportTypeQualifier<'a>>,
type_arguments: T2,
) -> TSTypeQueryExprName<'a>
where
Expand Down Expand Up @@ -13698,7 +13698,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
argument: TSType<'a>,
options: T1,
qualifier: Option<TSTypeName<'a>>,
qualifier: Option<TSImportTypeQualifier<'a>>,
type_arguments: T2,
) -> TSImportType<'a>
where
Expand Down Expand Up @@ -13731,7 +13731,7 @@ impl<'a> AstBuilder<'a> {
span: Span,
argument: TSType<'a>,
options: T1,
qualifier: Option<TSTypeName<'a>>,
qualifier: Option<TSImportTypeQualifier<'a>>,
type_arguments: T2,
) -> Box<'a, TSImportType<'a>>
where
Expand All @@ -13744,6 +13744,83 @@ impl<'a> AstBuilder<'a> {
)
}

/// Build a [`TSImportTypeQualifier::Identifier`].
///
/// This node contains an [`IdentifierName`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `name`
#[inline]
pub fn ts_import_type_qualifier_identifier<A1>(
self,
span: Span,
name: A1,
) -> TSImportTypeQualifier<'a>
where
A1: Into<Atom<'a>>,
{
TSImportTypeQualifier::Identifier(self.alloc_identifier_name(span, name))
}

/// Build a [`TSImportTypeQualifier::QualifiedName`].
///
/// This node contains a [`TSImportTypeQualifiedName`] that will be stored in the memory arena.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `left`
/// * `right`
#[inline]
pub fn ts_import_type_qualifier_qualified_name(
self,
span: Span,
left: TSImportTypeQualifier<'a>,
right: IdentifierName<'a>,
) -> TSImportTypeQualifier<'a> {
TSImportTypeQualifier::QualifiedName(
self.alloc_ts_import_type_qualified_name(span, left, right),
)
}

/// Build a [`TSImportTypeQualifiedName`].
///
/// If you want the built node to be allocated in the memory arena,
/// use [`AstBuilder::alloc_ts_import_type_qualified_name`] instead.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `left`
/// * `right`
#[inline]
pub fn ts_import_type_qualified_name(
self,
span: Span,
left: TSImportTypeQualifier<'a>,
right: IdentifierName<'a>,
) -> TSImportTypeQualifiedName<'a> {
TSImportTypeQualifiedName { span, left, right }
}

/// Build a [`TSImportTypeQualifiedName`], and store it in the memory arena.
///
/// Returns a [`Box`] containing the newly-allocated node.
/// If you want a stack-allocated node, use [`AstBuilder::ts_import_type_qualified_name`] instead.
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `left`
/// * `right`
#[inline]
pub fn alloc_ts_import_type_qualified_name(
self,
span: Span,
left: TSImportTypeQualifier<'a>,
right: IdentifierName<'a>,
) -> Box<'a, TSImportTypeQualifiedName<'a>> {
Box::new_in(self.ts_import_type_qualified_name(span, left, right), self.allocator)
}

/// Build a [`TSFunctionType`].
///
/// If you want the built node to be allocated in the memory arena,
Expand Down
44 changes: 27 additions & 17 deletions crates/oxc_ast/src/generated/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,24 @@ pub enum AstType {
TSInferType = 166,
TSTypeQuery = 167,
TSImportType = 168,
TSFunctionType = 169,
TSConstructorType = 170,
TSMappedType = 171,
TSTemplateLiteralType = 172,
TSAsExpression = 173,
TSSatisfiesExpression = 174,
TSTypeAssertion = 175,
TSImportEqualsDeclaration = 176,
TSExternalModuleReference = 177,
TSNonNullExpression = 178,
Decorator = 179,
TSExportAssignment = 180,
TSNamespaceExportDeclaration = 181,
TSInstantiationExpression = 182,
JSDocNullableType = 183,
JSDocNonNullableType = 184,
JSDocUnknownType = 185,
TSImportTypeQualifiedName = 169,
TSFunctionType = 170,
TSConstructorType = 171,
TSMappedType = 172,
TSTemplateLiteralType = 173,
TSAsExpression = 174,
TSSatisfiesExpression = 175,
TSTypeAssertion = 176,
TSImportEqualsDeclaration = 177,
TSExternalModuleReference = 178,
TSNonNullExpression = 179,
Decorator = 180,
TSExportAssignment = 181,
TSNamespaceExportDeclaration = 182,
TSInstantiationExpression = 183,
JSDocNullableType = 184,
JSDocNonNullableType = 185,
JSDocUnknownType = 186,
}

/// Untyped AST Node Kind
Expand Down Expand Up @@ -388,6 +389,8 @@ pub enum AstKind<'a> {
TSInferType(&'a TSInferType<'a>) = AstType::TSInferType as u8,
TSTypeQuery(&'a TSTypeQuery<'a>) = AstType::TSTypeQuery as u8,
TSImportType(&'a TSImportType<'a>) = AstType::TSImportType as u8,
TSImportTypeQualifiedName(&'a TSImportTypeQualifiedName<'a>) =
AstType::TSImportTypeQualifiedName as u8,
TSFunctionType(&'a TSFunctionType<'a>) = AstType::TSFunctionType as u8,
TSConstructorType(&'a TSConstructorType<'a>) = AstType::TSConstructorType as u8,
TSMappedType(&'a TSMappedType<'a>) = AstType::TSMappedType as u8,
Expand Down Expand Up @@ -595,6 +598,7 @@ impl GetSpan for AstKind<'_> {
Self::TSInferType(it) => it.span(),
Self::TSTypeQuery(it) => it.span(),
Self::TSImportType(it) => it.span(),
Self::TSImportTypeQualifiedName(it) => it.span(),
Self::TSFunctionType(it) => it.span(),
Self::TSConstructorType(it) => it.span(),
Self::TSMappedType(it) => it.span(),
Expand Down Expand Up @@ -788,6 +792,7 @@ impl GetAddress for AstKind<'_> {
Self::TSInferType(it) => Address::from_ptr(it),
Self::TSTypeQuery(it) => Address::from_ptr(it),
Self::TSImportType(it) => Address::from_ptr(it),
Self::TSImportTypeQualifiedName(it) => Address::from_ptr(it),
Self::TSFunctionType(it) => Address::from_ptr(it),
Self::TSConstructorType(it) => Address::from_ptr(it),
Self::TSMappedType(it) => Address::from_ptr(it),
Expand Down Expand Up @@ -1663,6 +1668,11 @@ impl<'a> AstKind<'a> {
if let Self::TSImportType(v) = self { Some(v) } else { None }
}

#[inline]
pub fn as_ts_import_type_qualified_name(self) -> Option<&'a TSImportTypeQualifiedName<'a>> {
if let Self::TSImportTypeQualifiedName(v) = self { Some(v) } else { None }
}

#[inline]
pub fn as_ts_function_type(self) -> Option<&'a TSFunctionType<'a>> {
if let Self::TSFunctionType(v) = self { Some(v) } else { None }
Expand Down
46 changes: 46 additions & 0 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7448,6 +7448,52 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSImportType<'_> {
}
}

impl<'new_alloc> CloneIn<'new_alloc> for TSImportTypeQualifier<'_> {
type Cloned = TSImportTypeQualifier<'new_alloc>;

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
match self {
Self::Identifier(it) => {
TSImportTypeQualifier::Identifier(CloneIn::clone_in(it, allocator))
}
Self::QualifiedName(it) => {
TSImportTypeQualifier::QualifiedName(CloneIn::clone_in(it, allocator))
}
}
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
match self {
Self::Identifier(it) => TSImportTypeQualifier::Identifier(
CloneIn::clone_in_with_semantic_ids(it, allocator),
),
Self::QualifiedName(it) => TSImportTypeQualifier::QualifiedName(
CloneIn::clone_in_with_semantic_ids(it, allocator),
),
}
}
}

impl<'new_alloc> CloneIn<'new_alloc> for TSImportTypeQualifiedName<'_> {
type Cloned = TSImportTypeQualifiedName<'new_alloc>;

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
TSImportTypeQualifiedName {
span: CloneIn::clone_in(&self.span, allocator),
left: CloneIn::clone_in(&self.left, allocator),
right: CloneIn::clone_in(&self.right, allocator),
}
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
TSImportTypeQualifiedName {
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
left: CloneIn::clone_in_with_semantic_ids(&self.left, allocator),
right: CloneIn::clone_in_with_semantic_ids(&self.right, allocator),
}
}
}

impl<'new_alloc> CloneIn<'new_alloc> for TSFunctionType<'_> {
type Cloned = TSFunctionType<'new_alloc>;

Expand Down
17 changes: 17 additions & 0 deletions crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,23 @@ impl ContentEq for TSImportType<'_> {
}
}

impl ContentEq for TSImportTypeQualifier<'_> {
fn content_eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Identifier(a), Self::Identifier(b)) => a.content_eq(b),
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
_ => false,
}
}
}

impl ContentEq for TSImportTypeQualifiedName<'_> {
fn content_eq(&self, other: &Self) -> bool {
ContentEq::content_eq(&self.left, &other.left)
&& ContentEq::content_eq(&self.right, &other.right)
}
}

impl ContentEq for TSFunctionType<'_> {
fn content_eq(&self, other: &Self) -> bool {
ContentEq::content_eq(&self.type_parameters, &other.type_parameters)
Expand Down
22 changes: 22 additions & 0 deletions crates/oxc_ast/src/generated/derive_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,28 @@ impl<'a> Dummy<'a> for TSImportType<'a> {
}
}

impl<'a> Dummy<'a> for TSImportTypeQualifier<'a> {
/// Create a dummy [`TSImportTypeQualifier`].
///
/// Has cost of making 1 allocation (24 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self::Identifier(Dummy::dummy(allocator))
}
}

impl<'a> Dummy<'a> for TSImportTypeQualifiedName<'a> {
/// Create a dummy [`TSImportTypeQualifiedName`].
///
/// Has cost of making 1 allocation (24 bytes).
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
left: Dummy::dummy(allocator),
right: Dummy::dummy(allocator),
}
}
}

impl<'a> Dummy<'a> for TSFunctionType<'a> {
/// Create a dummy [`TSFunctionType`].
///
Expand Down
Loading
Loading