Skip to content

Commit c8f4709

Browse files
committed
feat(ast)!: remove IdentifierReference from qualifier field of TSImportType
1 parent 0eaebcd commit c8f4709

File tree

37 files changed

+1289
-476
lines changed

37 files changed

+1289
-476
lines changed

crates/oxc_ast/src/ast/ts.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,10 +1359,38 @@ pub struct TSImportType<'a> {
13591359
pub span: Span,
13601360
pub argument: TSType<'a>,
13611361
pub options: Option<Box<'a, ObjectExpression<'a>>>,
1362-
pub qualifier: Option<TSTypeName<'a>>,
1362+
pub qualifier: Option<TSImportTypeQualifier<'a>>,
13631363
pub type_arguments: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
13641364
}
13651365

1366+
/// TypeScript Import Type Qualifier
1367+
///
1368+
/// The qualifier part of an import type that doesn't create references.
1369+
/// In `import("./a").b.c`, the `.b.c` part is the qualifier.
1370+
///
1371+
/// Unlike `TSTypeName`, this doesn't use `IdentifierReference` because
1372+
/// these are not references to identifiers in scope, but rather property
1373+
/// accesses on the imported module type.
1374+
#[ast(visit)]
1375+
#[derive(Debug)]
1376+
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, GetAddress, ContentEq, ESTree)]
1377+
pub enum TSImportTypeQualifier<'a> {
1378+
Identifier(Box<'a, IdentifierName<'a>>) = 0,
1379+
QualifiedName(Box<'a, TSImportTypeQualifiedName<'a>>) = 1,
1380+
}
1381+
1382+
/// TypeScript Import Type Qualified Name
1383+
///
1384+
/// A qualified name in an import type (e.g., `a.b.c` in `import("./module").a.b.c`)
1385+
#[ast(visit)]
1386+
#[derive(Debug)]
1387+
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
1388+
pub struct TSImportTypeQualifiedName<'a> {
1389+
pub span: Span,
1390+
pub left: TSImportTypeQualifier<'a>,
1391+
pub right: IdentifierName<'a>,
1392+
}
1393+
13661394
/// TypeScript Function Type
13671395
///
13681396
/// ## Examples

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ impl AstKind<'_> {
502502
"AssignmentTargetPropertyIdentifier".into()
503503
}
504504
Self::AssignmentTargetPropertyProperty(_) => "AssignmentTargetPropertyProperty".into(),
505+
Self::TSImportTypeQualifiedName(_) => "TSImportTypeQualifiedName".into(),
505506
}
506507
}
507508
}

crates/oxc_ast/src/generated/assert_layouts.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,16 @@ const _: () = {
14471447
assert!(offset_of!(TSImportType, qualifier) == 32);
14481448
assert!(offset_of!(TSImportType, type_arguments) == 48);
14491449

1450+
assert!(size_of::<TSImportTypeQualifier>() == 16);
1451+
assert!(align_of::<TSImportTypeQualifier>() == 8);
1452+
1453+
// Padding: 0 bytes
1454+
assert!(size_of::<TSImportTypeQualifiedName>() == 48);
1455+
assert!(align_of::<TSImportTypeQualifiedName>() == 8);
1456+
assert!(offset_of!(TSImportTypeQualifiedName, span) == 0);
1457+
assert!(offset_of!(TSImportTypeQualifiedName, left) == 8);
1458+
assert!(offset_of!(TSImportTypeQualifiedName, right) == 24);
1459+
14501460
// Padding: 4 bytes
14511461
assert!(size_of::<TSFunctionType>() == 48);
14521462
assert!(align_of::<TSFunctionType>() == 8);
@@ -3042,6 +3052,16 @@ const _: () = {
30423052
assert!(offset_of!(TSImportType, qualifier) == 20);
30433053
assert!(offset_of!(TSImportType, type_arguments) == 28);
30443054

3055+
assert!(size_of::<TSImportTypeQualifier>() == 8);
3056+
assert!(align_of::<TSImportTypeQualifier>() == 4);
3057+
3058+
// Padding: 0 bytes
3059+
assert!(size_of::<TSImportTypeQualifiedName>() == 32);
3060+
assert!(align_of::<TSImportTypeQualifiedName>() == 4);
3061+
assert!(offset_of!(TSImportTypeQualifiedName, span) == 0);
3062+
assert!(offset_of!(TSImportTypeQualifiedName, left) == 8);
3063+
assert!(offset_of!(TSImportTypeQualifiedName, right) == 16);
3064+
30453065
// Padding: 0 bytes
30463066
assert!(size_of::<TSFunctionType>() == 28);
30473067
assert!(align_of::<TSFunctionType>() == 4);

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10486,7 +10486,7 @@ impl<'a> AstBuilder<'a> {
1048610486
span: Span,
1048710487
argument: TSType<'a>,
1048810488
options: T1,
10489-
qualifier: Option<TSTypeName<'a>>,
10489+
qualifier: Option<TSImportTypeQualifier<'a>>,
1049010490
type_arguments: T2,
1049110491
) -> TSType<'a>
1049210492
where
@@ -13665,7 +13665,7 @@ impl<'a> AstBuilder<'a> {
1366513665
span: Span,
1366613666
argument: TSType<'a>,
1366713667
options: T1,
13668-
qualifier: Option<TSTypeName<'a>>,
13668+
qualifier: Option<TSImportTypeQualifier<'a>>,
1366913669
type_arguments: T2,
1367013670
) -> TSTypeQueryExprName<'a>
1367113671
where
@@ -13698,7 +13698,7 @@ impl<'a> AstBuilder<'a> {
1369813698
span: Span,
1369913699
argument: TSType<'a>,
1370013700
options: T1,
13701-
qualifier: Option<TSTypeName<'a>>,
13701+
qualifier: Option<TSImportTypeQualifier<'a>>,
1370213702
type_arguments: T2,
1370313703
) -> TSImportType<'a>
1370413704
where
@@ -13731,7 +13731,7 @@ impl<'a> AstBuilder<'a> {
1373113731
span: Span,
1373213732
argument: TSType<'a>,
1373313733
options: T1,
13734-
qualifier: Option<TSTypeName<'a>>,
13734+
qualifier: Option<TSImportTypeQualifier<'a>>,
1373513735
type_arguments: T2,
1373613736
) -> Box<'a, TSImportType<'a>>
1373713737
where
@@ -13744,6 +13744,83 @@ impl<'a> AstBuilder<'a> {
1374413744
)
1374513745
}
1374613746

13747+
/// Build a [`TSImportTypeQualifier::Identifier`].
13748+
///
13749+
/// This node contains an [`IdentifierName`] that will be stored in the memory arena.
13750+
///
13751+
/// ## Parameters
13752+
/// * `span`: The [`Span`] covering this node
13753+
/// * `name`
13754+
#[inline]
13755+
pub fn ts_import_type_qualifier_identifier<A1>(
13756+
self,
13757+
span: Span,
13758+
name: A1,
13759+
) -> TSImportTypeQualifier<'a>
13760+
where
13761+
A1: Into<Atom<'a>>,
13762+
{
13763+
TSImportTypeQualifier::Identifier(self.alloc_identifier_name(span, name))
13764+
}
13765+
13766+
/// Build a [`TSImportTypeQualifier::QualifiedName`].
13767+
///
13768+
/// This node contains a [`TSImportTypeQualifiedName`] that will be stored in the memory arena.
13769+
///
13770+
/// ## Parameters
13771+
/// * `span`: The [`Span`] covering this node
13772+
/// * `left`
13773+
/// * `right`
13774+
#[inline]
13775+
pub fn ts_import_type_qualifier_qualified_name(
13776+
self,
13777+
span: Span,
13778+
left: TSImportTypeQualifier<'a>,
13779+
right: IdentifierName<'a>,
13780+
) -> TSImportTypeQualifier<'a> {
13781+
TSImportTypeQualifier::QualifiedName(
13782+
self.alloc_ts_import_type_qualified_name(span, left, right),
13783+
)
13784+
}
13785+
13786+
/// Build a [`TSImportTypeQualifiedName`].
13787+
///
13788+
/// If you want the built node to be allocated in the memory arena,
13789+
/// use [`AstBuilder::alloc_ts_import_type_qualified_name`] instead.
13790+
///
13791+
/// ## Parameters
13792+
/// * `span`: The [`Span`] covering this node
13793+
/// * `left`
13794+
/// * `right`
13795+
#[inline]
13796+
pub fn ts_import_type_qualified_name(
13797+
self,
13798+
span: Span,
13799+
left: TSImportTypeQualifier<'a>,
13800+
right: IdentifierName<'a>,
13801+
) -> TSImportTypeQualifiedName<'a> {
13802+
TSImportTypeQualifiedName { span, left, right }
13803+
}
13804+
13805+
/// Build a [`TSImportTypeQualifiedName`], and store it in the memory arena.
13806+
///
13807+
/// Returns a [`Box`] containing the newly-allocated node.
13808+
/// If you want a stack-allocated node, use [`AstBuilder::ts_import_type_qualified_name`] instead.
13809+
///
13810+
/// ## Parameters
13811+
/// * `span`: The [`Span`] covering this node
13812+
/// * `left`
13813+
/// * `right`
13814+
#[inline]
13815+
pub fn alloc_ts_import_type_qualified_name(
13816+
self,
13817+
span: Span,
13818+
left: TSImportTypeQualifier<'a>,
13819+
right: IdentifierName<'a>,
13820+
) -> Box<'a, TSImportTypeQualifiedName<'a>> {
13821+
Box::new_in(self.ts_import_type_qualified_name(span, left, right), self.allocator)
13822+
}
13823+
1374713824
/// Build a [`TSFunctionType`].
1374813825
///
1374913826
/// If you want the built node to be allocated in the memory arena,

crates/oxc_ast/src/generated/ast_kind.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,24 @@ pub enum AstType {
183183
TSInferType = 166,
184184
TSTypeQuery = 167,
185185
TSImportType = 168,
186-
TSFunctionType = 169,
187-
TSConstructorType = 170,
188-
TSMappedType = 171,
189-
TSTemplateLiteralType = 172,
190-
TSAsExpression = 173,
191-
TSSatisfiesExpression = 174,
192-
TSTypeAssertion = 175,
193-
TSImportEqualsDeclaration = 176,
194-
TSExternalModuleReference = 177,
195-
TSNonNullExpression = 178,
196-
Decorator = 179,
197-
TSExportAssignment = 180,
198-
TSNamespaceExportDeclaration = 181,
199-
TSInstantiationExpression = 182,
200-
JSDocNullableType = 183,
201-
JSDocNonNullableType = 184,
202-
JSDocUnknownType = 185,
186+
TSImportTypeQualifiedName = 169,
187+
TSFunctionType = 170,
188+
TSConstructorType = 171,
189+
TSMappedType = 172,
190+
TSTemplateLiteralType = 173,
191+
TSAsExpression = 174,
192+
TSSatisfiesExpression = 175,
193+
TSTypeAssertion = 176,
194+
TSImportEqualsDeclaration = 177,
195+
TSExternalModuleReference = 178,
196+
TSNonNullExpression = 179,
197+
Decorator = 180,
198+
TSExportAssignment = 181,
199+
TSNamespaceExportDeclaration = 182,
200+
TSInstantiationExpression = 183,
201+
JSDocNullableType = 184,
202+
JSDocNonNullableType = 185,
203+
JSDocUnknownType = 186,
203204
}
204205

205206
/// Untyped AST Node Kind
@@ -388,6 +389,8 @@ pub enum AstKind<'a> {
388389
TSInferType(&'a TSInferType<'a>) = AstType::TSInferType as u8,
389390
TSTypeQuery(&'a TSTypeQuery<'a>) = AstType::TSTypeQuery as u8,
390391
TSImportType(&'a TSImportType<'a>) = AstType::TSImportType as u8,
392+
TSImportTypeQualifiedName(&'a TSImportTypeQualifiedName<'a>) =
393+
AstType::TSImportTypeQualifiedName as u8,
391394
TSFunctionType(&'a TSFunctionType<'a>) = AstType::TSFunctionType as u8,
392395
TSConstructorType(&'a TSConstructorType<'a>) = AstType::TSConstructorType as u8,
393396
TSMappedType(&'a TSMappedType<'a>) = AstType::TSMappedType as u8,
@@ -595,6 +598,7 @@ impl GetSpan for AstKind<'_> {
595598
Self::TSInferType(it) => it.span(),
596599
Self::TSTypeQuery(it) => it.span(),
597600
Self::TSImportType(it) => it.span(),
601+
Self::TSImportTypeQualifiedName(it) => it.span(),
598602
Self::TSFunctionType(it) => it.span(),
599603
Self::TSConstructorType(it) => it.span(),
600604
Self::TSMappedType(it) => it.span(),
@@ -788,6 +792,7 @@ impl GetAddress for AstKind<'_> {
788792
Self::TSInferType(it) => Address::from_ptr(it),
789793
Self::TSTypeQuery(it) => Address::from_ptr(it),
790794
Self::TSImportType(it) => Address::from_ptr(it),
795+
Self::TSImportTypeQualifiedName(it) => Address::from_ptr(it),
791796
Self::TSFunctionType(it) => Address::from_ptr(it),
792797
Self::TSConstructorType(it) => Address::from_ptr(it),
793798
Self::TSMappedType(it) => Address::from_ptr(it),
@@ -1663,6 +1668,11 @@ impl<'a> AstKind<'a> {
16631668
if let Self::TSImportType(v) = self { Some(v) } else { None }
16641669
}
16651670

1671+
#[inline]
1672+
pub fn as_ts_import_type_qualified_name(self) -> Option<&'a TSImportTypeQualifiedName<'a>> {
1673+
if let Self::TSImportTypeQualifiedName(v) = self { Some(v) } else { None }
1674+
}
1675+
16661676
#[inline]
16671677
pub fn as_ts_function_type(self) -> Option<&'a TSFunctionType<'a>> {
16681678
if let Self::TSFunctionType(v) = self { Some(v) } else { None }

crates/oxc_ast/src/generated/derive_clone_in.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7448,6 +7448,52 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSImportType<'_> {
74487448
}
74497449
}
74507450

7451+
impl<'new_alloc> CloneIn<'new_alloc> for TSImportTypeQualifier<'_> {
7452+
type Cloned = TSImportTypeQualifier<'new_alloc>;
7453+
7454+
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
7455+
match self {
7456+
Self::Identifier(it) => {
7457+
TSImportTypeQualifier::Identifier(CloneIn::clone_in(it, allocator))
7458+
}
7459+
Self::QualifiedName(it) => {
7460+
TSImportTypeQualifier::QualifiedName(CloneIn::clone_in(it, allocator))
7461+
}
7462+
}
7463+
}
7464+
7465+
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
7466+
match self {
7467+
Self::Identifier(it) => TSImportTypeQualifier::Identifier(
7468+
CloneIn::clone_in_with_semantic_ids(it, allocator),
7469+
),
7470+
Self::QualifiedName(it) => TSImportTypeQualifier::QualifiedName(
7471+
CloneIn::clone_in_with_semantic_ids(it, allocator),
7472+
),
7473+
}
7474+
}
7475+
}
7476+
7477+
impl<'new_alloc> CloneIn<'new_alloc> for TSImportTypeQualifiedName<'_> {
7478+
type Cloned = TSImportTypeQualifiedName<'new_alloc>;
7479+
7480+
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
7481+
TSImportTypeQualifiedName {
7482+
span: CloneIn::clone_in(&self.span, allocator),
7483+
left: CloneIn::clone_in(&self.left, allocator),
7484+
right: CloneIn::clone_in(&self.right, allocator),
7485+
}
7486+
}
7487+
7488+
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
7489+
TSImportTypeQualifiedName {
7490+
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
7491+
left: CloneIn::clone_in_with_semantic_ids(&self.left, allocator),
7492+
right: CloneIn::clone_in_with_semantic_ids(&self.right, allocator),
7493+
}
7494+
}
7495+
}
7496+
74517497
impl<'new_alloc> CloneIn<'new_alloc> for TSFunctionType<'_> {
74527498
type Cloned = TSFunctionType<'new_alloc>;
74537499

crates/oxc_ast/src/generated/derive_content_eq.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,23 @@ impl ContentEq for TSImportType<'_> {
23302330
}
23312331
}
23322332

2333+
impl ContentEq for TSImportTypeQualifier<'_> {
2334+
fn content_eq(&self, other: &Self) -> bool {
2335+
match (self, other) {
2336+
(Self::Identifier(a), Self::Identifier(b)) => a.content_eq(b),
2337+
(Self::QualifiedName(a), Self::QualifiedName(b)) => a.content_eq(b),
2338+
_ => false,
2339+
}
2340+
}
2341+
}
2342+
2343+
impl ContentEq for TSImportTypeQualifiedName<'_> {
2344+
fn content_eq(&self, other: &Self) -> bool {
2345+
ContentEq::content_eq(&self.left, &other.left)
2346+
&& ContentEq::content_eq(&self.right, &other.right)
2347+
}
2348+
}
2349+
23332350
impl ContentEq for TSFunctionType<'_> {
23342351
fn content_eq(&self, other: &Self) -> bool {
23352352
ContentEq::content_eq(&self.type_parameters, &other.type_parameters)

crates/oxc_ast/src/generated/derive_dummy.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,28 @@ impl<'a> Dummy<'a> for TSImportType<'a> {
26372637
}
26382638
}
26392639

2640+
impl<'a> Dummy<'a> for TSImportTypeQualifier<'a> {
2641+
/// Create a dummy [`TSImportTypeQualifier`].
2642+
///
2643+
/// Has cost of making 1 allocation (24 bytes).
2644+
fn dummy(allocator: &'a Allocator) -> Self {
2645+
Self::Identifier(Dummy::dummy(allocator))
2646+
}
2647+
}
2648+
2649+
impl<'a> Dummy<'a> for TSImportTypeQualifiedName<'a> {
2650+
/// Create a dummy [`TSImportTypeQualifiedName`].
2651+
///
2652+
/// Has cost of making 1 allocation (24 bytes).
2653+
fn dummy(allocator: &'a Allocator) -> Self {
2654+
Self {
2655+
span: Dummy::dummy(allocator),
2656+
left: Dummy::dummy(allocator),
2657+
right: Dummy::dummy(allocator),
2658+
}
2659+
}
2660+
}
2661+
26402662
impl<'a> Dummy<'a> for TSFunctionType<'a> {
26412663
/// Create a dummy [`TSFunctionType`].
26422664
///

0 commit comments

Comments
 (0)