Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 23e3b76

Browse files
committedMar 20, 2025··
feat(parser)!: parse TSImportAttributes as ObjectExpression
closes #9662 closes #9663
1 parent 2e023ab commit 23e3b76

File tree

23 files changed

+65
-962
lines changed

23 files changed

+65
-962
lines changed
 

‎crates/oxc_ast/src/ast/ts.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -1279,41 +1279,13 @@ pub enum TSTypeQueryExprName<'a> {
12791279
pub struct TSImportType<'a> {
12801280
pub span: Span,
12811281
pub argument: TSType<'a>,
1282-
pub options: Option<Box<'a, TSImportAttributes<'a>>>,
1282+
pub options: Option<Box<'a, ObjectExpression<'a>>>,
12831283
pub qualifier: Option<TSTypeName<'a>>,
12841284
pub type_arguments: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
12851285
/// `true` for `typeof import("foo")`
12861286
pub is_type_of: bool,
12871287
}
12881288

1289-
#[ast(visit)]
1290-
#[derive(Debug)]
1291-
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
1292-
pub struct TSImportAttributes<'a> {
1293-
pub span: Span,
1294-
pub attributes_keyword: IdentifierName<'a>, // `with` or `assert`
1295-
pub elements: Vec<'a, TSImportAttribute<'a>>,
1296-
}
1297-
1298-
#[ast(visit)]
1299-
#[derive(Debug)]
1300-
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
1301-
// Pluralize as `TSImportAttributeList` to avoid naming clash with `TSImportAttributes`.
1302-
#[plural(TSImportAttributeList)]
1303-
pub struct TSImportAttribute<'a> {
1304-
pub span: Span,
1305-
pub name: TSImportAttributeName<'a>,
1306-
pub value: Expression<'a>,
1307-
}
1308-
1309-
#[ast(visit)]
1310-
#[derive(Debug)]
1311-
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
1312-
pub enum TSImportAttributeName<'a> {
1313-
Identifier(IdentifierName<'a>) = 0,
1314-
StringLiteral(StringLiteral<'a>) = 1,
1315-
}
1316-
13171289
/// TypeScript Function Type
13181290
///
13191291
/// ## Examples

‎crates/oxc_ast/src/generated/assert_layouts.rs

-30
Original file line numberDiff line numberDiff line change
@@ -1263,21 +1263,6 @@ const _: () = {
12631263
assert!(offset_of!(TSImportType, type_arguments) == 48);
12641264
assert!(offset_of!(TSImportType, is_type_of) == 56);
12651265

1266-
assert!(size_of::<TSImportAttributes>() == 64);
1267-
assert!(align_of::<TSImportAttributes>() == 8);
1268-
assert!(offset_of!(TSImportAttributes, span) == 0);
1269-
assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8);
1270-
assert!(offset_of!(TSImportAttributes, elements) == 32);
1271-
1272-
assert!(size_of::<TSImportAttribute>() == 72);
1273-
assert!(align_of::<TSImportAttribute>() == 8);
1274-
assert!(offset_of!(TSImportAttribute, span) == 0);
1275-
assert!(offset_of!(TSImportAttribute, name) == 8);
1276-
assert!(offset_of!(TSImportAttribute, value) == 56);
1277-
1278-
assert!(size_of::<TSImportAttributeName>() == 48);
1279-
assert!(align_of::<TSImportAttributeName>() == 8);
1280-
12811266
assert!(size_of::<TSFunctionType>() == 48);
12821267
assert!(align_of::<TSFunctionType>() == 8);
12831268
assert!(offset_of!(TSFunctionType, span) == 0);
@@ -2668,21 +2653,6 @@ const _: () = {
26682653
assert!(offset_of!(TSImportType, type_arguments) == 28);
26692654
assert!(offset_of!(TSImportType, is_type_of) == 32);
26702655

2671-
assert!(size_of::<TSImportAttributes>() == 40);
2672-
assert!(align_of::<TSImportAttributes>() == 4);
2673-
assert!(offset_of!(TSImportAttributes, span) == 0);
2674-
assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8);
2675-
assert!(offset_of!(TSImportAttributes, elements) == 24);
2676-
2677-
assert!(size_of::<TSImportAttribute>() == 44);
2678-
assert!(align_of::<TSImportAttribute>() == 4);
2679-
assert!(offset_of!(TSImportAttribute, span) == 0);
2680-
assert!(offset_of!(TSImportAttribute, name) == 8);
2681-
assert!(offset_of!(TSImportAttribute, value) == 36);
2682-
2683-
assert!(size_of::<TSImportAttributeName>() == 28);
2684-
assert!(align_of::<TSImportAttributeName>() == 4);
2685-
26862656
assert!(size_of::<TSFunctionType>() == 28);
26872657
assert!(align_of::<TSFunctionType>() == 4);
26882658
assert!(offset_of!(TSFunctionType, span) == 0);

‎crates/oxc_ast/src/generated/ast_builder.rs

+4-112
Original file line numberDiff line numberDiff line change
@@ -10323,7 +10323,7 @@ impl<'a> AstBuilder<'a> {
1032310323
is_type_of: bool,
1032410324
) -> TSType<'a>
1032510325
where
10326-
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
10326+
T1: IntoIn<'a, Option<Box<'a, ObjectExpression<'a>>>>,
1032710327
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
1032810328
{
1032910329
TSType::TSImportType(self.alloc_ts_import_type(
@@ -13435,7 +13435,7 @@ impl<'a> AstBuilder<'a> {
1343513435
is_type_of: bool,
1343613436
) -> TSTypeQueryExprName<'a>
1343713437
where
13438-
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
13438+
T1: IntoIn<'a, Option<Box<'a, ObjectExpression<'a>>>>,
1343913439
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
1344013440
{
1344113441
TSTypeQueryExprName::TSImportType(self.alloc_ts_import_type(
@@ -13470,7 +13470,7 @@ impl<'a> AstBuilder<'a> {
1347013470
is_type_of: bool,
1347113471
) -> TSImportType<'a>
1347213472
where
13473-
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
13473+
T1: IntoIn<'a, Option<Box<'a, ObjectExpression<'a>>>>,
1347413474
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
1347513475
{
1347613476
TSImportType {
@@ -13505,7 +13505,7 @@ impl<'a> AstBuilder<'a> {
1350513505
is_type_of: bool,
1350613506
) -> Box<'a, TSImportType<'a>>
1350713507
where
13508-
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
13508+
T1: IntoIn<'a, Option<Box<'a, ObjectExpression<'a>>>>,
1350913509
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
1351013510
{
1351113511
Box::new_in(
@@ -13514,114 +13514,6 @@ impl<'a> AstBuilder<'a> {
1351413514
)
1351513515
}
1351613516

13517-
/// Build a [`TSImportAttributes`].
13518-
///
13519-
/// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_ts_import_attributes`] instead.
13520-
///
13521-
/// ## Parameters
13522-
/// * `span`: The [`Span`] covering this node
13523-
/// * `attributes_keyword`
13524-
/// * `elements`
13525-
#[inline]
13526-
pub fn ts_import_attributes(
13527-
self,
13528-
span: Span,
13529-
attributes_keyword: IdentifierName<'a>,
13530-
elements: Vec<'a, TSImportAttribute<'a>>,
13531-
) -> TSImportAttributes<'a> {
13532-
TSImportAttributes { span, attributes_keyword, elements }
13533-
}
13534-
13535-
/// Build a [`TSImportAttributes`], and store it in the memory arena.
13536-
///
13537-
/// Returns a [`Box`] containing the newly-allocated node. If you want a stack-allocated node, use [`AstBuilder::ts_import_attributes`] instead.
13538-
///
13539-
/// ## Parameters
13540-
/// * `span`: The [`Span`] covering this node
13541-
/// * `attributes_keyword`
13542-
/// * `elements`
13543-
#[inline]
13544-
pub fn alloc_ts_import_attributes(
13545-
self,
13546-
span: Span,
13547-
attributes_keyword: IdentifierName<'a>,
13548-
elements: Vec<'a, TSImportAttribute<'a>>,
13549-
) -> Box<'a, TSImportAttributes<'a>> {
13550-
Box::new_in(self.ts_import_attributes(span, attributes_keyword, elements), self.allocator)
13551-
}
13552-
13553-
/// Build a [`TSImportAttribute`].
13554-
///
13555-
/// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_ts_import_attribute`] instead.
13556-
///
13557-
/// ## Parameters
13558-
/// * `span`: The [`Span`] covering this node
13559-
/// * `name`
13560-
/// * `value`
13561-
#[inline]
13562-
pub fn ts_import_attribute(
13563-
self,
13564-
span: Span,
13565-
name: TSImportAttributeName<'a>,
13566-
value: Expression<'a>,
13567-
) -> TSImportAttribute<'a> {
13568-
TSImportAttribute { span, name, value }
13569-
}
13570-
13571-
/// Build a [`TSImportAttribute`], and store it in the memory arena.
13572-
///
13573-
/// Returns a [`Box`] containing the newly-allocated node. If you want a stack-allocated node, use [`AstBuilder::ts_import_attribute`] instead.
13574-
///
13575-
/// ## Parameters
13576-
/// * `span`: The [`Span`] covering this node
13577-
/// * `name`
13578-
/// * `value`
13579-
#[inline]
13580-
pub fn alloc_ts_import_attribute(
13581-
self,
13582-
span: Span,
13583-
name: TSImportAttributeName<'a>,
13584-
value: Expression<'a>,
13585-
) -> Box<'a, TSImportAttribute<'a>> {
13586-
Box::new_in(self.ts_import_attribute(span, name, value), self.allocator)
13587-
}
13588-
13589-
/// Build a [`TSImportAttributeName::Identifier`].
13590-
///
13591-
/// ## Parameters
13592-
/// * `span`: The [`Span`] covering this node
13593-
/// * `name`
13594-
#[inline]
13595-
pub fn ts_import_attribute_name_identifier<A>(
13596-
self,
13597-
span: Span,
13598-
name: A,
13599-
) -> TSImportAttributeName<'a>
13600-
where
13601-
A: IntoIn<'a, Atom<'a>>,
13602-
{
13603-
TSImportAttributeName::Identifier(self.identifier_name(span, name))
13604-
}
13605-
13606-
/// Build a [`TSImportAttributeName::StringLiteral`].
13607-
///
13608-
/// ## Parameters
13609-
/// * `span`: Node location in source code
13610-
/// * `value`: The value of the string.
13611-
/// * `raw`: The raw string as it appears in source code.
13612-
#[inline]
13613-
pub fn ts_import_attribute_name_string_literal<A>(
13614-
self,
13615-
span: Span,
13616-
value: A,
13617-
raw: Option<Atom<'a>>,
13618-
) -> TSImportAttributeName<'a>
13619-
where
13620-
A: IntoIn<'a, Atom<'a>>,
13621-
{
13622-
TSImportAttributeName::StringLiteral(self.string_literal(span, value, raw))
13623-
}
13624-
1362513517
/// Build a [`TSFunctionType`].
1362613518
///
1362713519
/// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_ts_function_type`] instead.

‎crates/oxc_ast/src/generated/derive_clone_in.rs

-36
Original file line numberDiff line numberDiff line change
@@ -3859,42 +3859,6 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSImportType<'_> {
38593859
}
38603860
}
38613861

3862-
impl<'new_alloc> CloneIn<'new_alloc> for TSImportAttributes<'_> {
3863-
type Cloned = TSImportAttributes<'new_alloc>;
3864-
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
3865-
TSImportAttributes {
3866-
span: CloneIn::clone_in(&self.span, allocator),
3867-
attributes_keyword: CloneIn::clone_in(&self.attributes_keyword, allocator),
3868-
elements: CloneIn::clone_in(&self.elements, allocator),
3869-
}
3870-
}
3871-
}
3872-
3873-
impl<'new_alloc> CloneIn<'new_alloc> for TSImportAttribute<'_> {
3874-
type Cloned = TSImportAttribute<'new_alloc>;
3875-
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
3876-
TSImportAttribute {
3877-
span: CloneIn::clone_in(&self.span, allocator),
3878-
name: CloneIn::clone_in(&self.name, allocator),
3879-
value: CloneIn::clone_in(&self.value, allocator),
3880-
}
3881-
}
3882-
}
3883-
3884-
impl<'new_alloc> CloneIn<'new_alloc> for TSImportAttributeName<'_> {
3885-
type Cloned = TSImportAttributeName<'new_alloc>;
3886-
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
3887-
match self {
3888-
Self::Identifier(it) => {
3889-
TSImportAttributeName::Identifier(CloneIn::clone_in(it, allocator))
3890-
}
3891-
Self::StringLiteral(it) => {
3892-
TSImportAttributeName::StringLiteral(CloneIn::clone_in(it, allocator))
3893-
}
3894-
}
3895-
}
3896-
}
3897-
38983862
impl<'new_alloc> CloneIn<'new_alloc> for TSFunctionType<'_> {
38993863
type Cloned = TSFunctionType<'new_alloc>;
39003864
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {

‎crates/oxc_ast/src/generated/derive_content_eq.rs

-24
Original file line numberDiff line numberDiff line change
@@ -2305,30 +2305,6 @@ impl ContentEq for TSImportType<'_> {
23052305
}
23062306
}
23072307

2308-
impl ContentEq for TSImportAttributes<'_> {
2309-
fn content_eq(&self, other: &Self) -> bool {
2310-
ContentEq::content_eq(&self.attributes_keyword, &other.attributes_keyword)
2311-
&& ContentEq::content_eq(&self.elements, &other.elements)
2312-
}
2313-
}
2314-
2315-
impl ContentEq for TSImportAttribute<'_> {
2316-
fn content_eq(&self, other: &Self) -> bool {
2317-
ContentEq::content_eq(&self.name, &other.name)
2318-
&& ContentEq::content_eq(&self.value, &other.value)
2319-
}
2320-
}
2321-
2322-
impl ContentEq for TSImportAttributeName<'_> {
2323-
fn content_eq(&self, other: &Self) -> bool {
2324-
match (self, other) {
2325-
(Self::Identifier(a), Self::Identifier(b)) => a.content_eq(b),
2326-
(Self::StringLiteral(a), Self::StringLiteral(b)) => a.content_eq(b),
2327-
_ => false,
2328-
}
2329-
}
2330-
}
2331-
23322308
impl ContentEq for TSFunctionType<'_> {
23332309
fn content_eq(&self, other: &Self) -> bool {
23342310
ContentEq::content_eq(&self.type_parameters, &other.type_parameters)

‎crates/oxc_ast/src/generated/derive_estree.rs

-33
Original file line numberDiff line numberDiff line change
@@ -3111,39 +3111,6 @@ impl ESTree for TSImportType<'_> {
31113111
}
31123112
}
31133113

3114-
impl ESTree for TSImportAttributes<'_> {
3115-
fn serialize<S: Serializer>(&self, serializer: S) {
3116-
let mut state = serializer.serialize_struct();
3117-
state.serialize_field("type", &JsonSafeString("TSImportAttributes"));
3118-
state.serialize_field("start", &self.span.start);
3119-
state.serialize_field("end", &self.span.end);
3120-
state.serialize_field("attributesKeyword", &self.attributes_keyword);
3121-
state.serialize_field("elements", &self.elements);
3122-
state.end();
3123-
}
3124-
}
3125-
3126-
impl ESTree for TSImportAttribute<'_> {
3127-
fn serialize<S: Serializer>(&self, serializer: S) {
3128-
let mut state = serializer.serialize_struct();
3129-
state.serialize_field("type", &JsonSafeString("TSImportAttribute"));
3130-
state.serialize_field("start", &self.span.start);
3131-
state.serialize_field("end", &self.span.end);
3132-
state.serialize_field("name", &self.name);
3133-
state.serialize_field("value", &self.value);
3134-
state.end();
3135-
}
3136-
}
3137-
3138-
impl ESTree for TSImportAttributeName<'_> {
3139-
fn serialize<S: Serializer>(&self, serializer: S) {
3140-
match self {
3141-
Self::Identifier(it) => it.serialize(serializer),
3142-
Self::StringLiteral(it) => it.serialize(serializer),
3143-
}
3144-
}
3145-
}
3146-
31473114
impl ESTree for TSFunctionType<'_> {
31483115
fn serialize<S: Serializer>(&self, serializer: S) {
31493116
let mut state = serializer.serialize_struct();

‎crates/oxc_ast/src/generated/derive_get_span.rs

-23
Original file line numberDiff line numberDiff line change
@@ -2015,29 +2015,6 @@ impl GetSpan for TSImportType<'_> {
20152015
}
20162016
}
20172017

2018-
impl GetSpan for TSImportAttributes<'_> {
2019-
#[inline]
2020-
fn span(&self) -> Span {
2021-
self.span
2022-
}
2023-
}
2024-
2025-
impl GetSpan for TSImportAttribute<'_> {
2026-
#[inline]
2027-
fn span(&self) -> Span {
2028-
self.span
2029-
}
2030-
}
2031-
2032-
impl GetSpan for TSImportAttributeName<'_> {
2033-
fn span(&self) -> Span {
2034-
match self {
2035-
Self::Identifier(it) => GetSpan::span(it),
2036-
Self::StringLiteral(it) => GetSpan::span(it),
2037-
}
2038-
}
2039-
}
2040-
20412018
impl GetSpan for TSFunctionType<'_> {
20422019
#[inline]
20432020
fn span(&self) -> Span {

‎crates/oxc_ast/src/generated/derive_get_span_mut.rs

-23
Original file line numberDiff line numberDiff line change
@@ -2015,29 +2015,6 @@ impl GetSpanMut for TSImportType<'_> {
20152015
}
20162016
}
20172017

2018-
impl GetSpanMut for TSImportAttributes<'_> {
2019-
#[inline]
2020-
fn span_mut(&mut self) -> &mut Span {
2021-
&mut self.span
2022-
}
2023-
}
2024-
2025-
impl GetSpanMut for TSImportAttribute<'_> {
2026-
#[inline]
2027-
fn span_mut(&mut self) -> &mut Span {
2028-
&mut self.span
2029-
}
2030-
}
2031-
2032-
impl GetSpanMut for TSImportAttributeName<'_> {
2033-
fn span_mut(&mut self) -> &mut Span {
2034-
match self {
2035-
Self::Identifier(it) => GetSpanMut::span_mut(it),
2036-
Self::StringLiteral(it) => GetSpanMut::span_mut(it),
2037-
}
2038-
}
2039-
}
2040-
20412018
impl GetSpanMut for TSFunctionType<'_> {
20422019
#[inline]
20432020
fn span_mut(&mut self) -> &mut Span {

‎crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs

-12
Original file line numberDiff line numberDiff line change
@@ -983,18 +983,6 @@ impl<'a> VisitMut<'a> for Utf8ToUtf16Converter<'_> {
983983
self.convert_offset(&mut it.span.end);
984984
}
985985

986-
fn visit_ts_import_attributes(&mut self, it: &mut TSImportAttributes<'a>) {
987-
self.convert_offset(&mut it.span.start);
988-
walk_mut::walk_ts_import_attributes(self, it);
989-
self.convert_offset(&mut it.span.end);
990-
}
991-
992-
fn visit_ts_import_attribute(&mut self, it: &mut TSImportAttribute<'a>) {
993-
self.convert_offset(&mut it.span.start);
994-
walk_mut::walk_ts_import_attribute(self, it);
995-
self.convert_offset(&mut it.span.end);
996-
}
997-
998986
fn visit_ts_function_type(&mut self, it: &mut TSFunctionType<'a>) {
999987
self.convert_offset(&mut it.span.start);
1000988
walk_mut::walk_ts_function_type(self, it);

‎crates/oxc_ast_visit/src/generated/visit.rs

+1-62
Original file line numberDiff line numberDiff line change
@@ -1088,21 +1088,6 @@ pub trait Visit<'a>: Sized {
10881088
walk_ts_import_type(self, it);
10891089
}
10901090

1091-
#[inline]
1092-
fn visit_ts_import_attributes(&mut self, it: &TSImportAttributes<'a>) {
1093-
walk_ts_import_attributes(self, it);
1094-
}
1095-
1096-
#[inline]
1097-
fn visit_ts_import_attribute(&mut self, it: &TSImportAttribute<'a>) {
1098-
walk_ts_import_attribute(self, it);
1099-
}
1100-
1101-
#[inline]
1102-
fn visit_ts_import_attribute_name(&mut self, it: &TSImportAttributeName<'a>) {
1103-
walk_ts_import_attribute_name(self, it);
1104-
}
1105-
11061091
#[inline]
11071092
fn visit_ts_function_type(&mut self, it: &TSFunctionType<'a>) {
11081093
walk_ts_function_type(self, it);
@@ -1336,11 +1321,6 @@ pub trait Visit<'a>: Sized {
13361321
walk_ts_index_signature_names(self, it);
13371322
}
13381323

1339-
#[inline]
1340-
fn visit_ts_import_attribute_list(&mut self, it: &Vec<'a, TSImportAttribute<'a>>) {
1341-
walk_ts_import_attribute_list(self, it);
1342-
}
1343-
13441324
#[inline]
13451325
fn visit_spans(&mut self, it: &Vec<'a, Span>) {
13461326
walk_spans(self, it);
@@ -3911,7 +3891,7 @@ pub mod walk {
39113891
visitor.visit_span(&it.span);
39123892
visitor.visit_ts_type(&it.argument);
39133893
if let Some(options) = &it.options {
3914-
visitor.visit_ts_import_attributes(options);
3894+
visitor.visit_object_expression(options);
39153895
}
39163896
if let Some(qualifier) = &it.qualifier {
39173897
visitor.visit_ts_type_name(qualifier);
@@ -3922,37 +3902,6 @@ pub mod walk {
39223902
visitor.leave_node(kind);
39233903
}
39243904

3925-
#[inline]
3926-
pub fn walk_ts_import_attributes<'a, V: Visit<'a>>(
3927-
visitor: &mut V,
3928-
it: &TSImportAttributes<'a>,
3929-
) {
3930-
// No `AstKind` for this type
3931-
visitor.visit_span(&it.span);
3932-
visitor.visit_identifier_name(&it.attributes_keyword);
3933-
visitor.visit_ts_import_attribute_list(&it.elements);
3934-
}
3935-
3936-
#[inline]
3937-
pub fn walk_ts_import_attribute<'a, V: Visit<'a>>(visitor: &mut V, it: &TSImportAttribute<'a>) {
3938-
// No `AstKind` for this type
3939-
visitor.visit_span(&it.span);
3940-
visitor.visit_ts_import_attribute_name(&it.name);
3941-
visitor.visit_expression(&it.value);
3942-
}
3943-
3944-
#[inline]
3945-
pub fn walk_ts_import_attribute_name<'a, V: Visit<'a>>(
3946-
visitor: &mut V,
3947-
it: &TSImportAttributeName<'a>,
3948-
) {
3949-
// No `AstKind` for this type
3950-
match it {
3951-
TSImportAttributeName::Identifier(it) => visitor.visit_identifier_name(it),
3952-
TSImportAttributeName::StringLiteral(it) => visitor.visit_string_literal(it),
3953-
}
3954-
}
3955-
39563905
#[inline]
39573906
pub fn walk_ts_function_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSFunctionType<'a>) {
39583907
// No `AstKind` for this type
@@ -4407,16 +4356,6 @@ pub mod walk {
44074356
}
44084357
}
44094358

4410-
#[inline]
4411-
pub fn walk_ts_import_attribute_list<'a, V: Visit<'a>>(
4412-
visitor: &mut V,
4413-
it: &Vec<'a, TSImportAttribute<'a>>,
4414-
) {
4415-
for el in it {
4416-
visitor.visit_ts_import_attribute(el);
4417-
}
4418-
}
4419-
44204359
#[inline]
44214360
pub fn walk_spans<'a, V: Visit<'a>>(visitor: &mut V, it: &Vec<'a, Span>) {
44224361
for el in it {

‎crates/oxc_ast_visit/src/generated/visit_mut.rs

+1-65
Original file line numberDiff line numberDiff line change
@@ -1080,21 +1080,6 @@ pub trait VisitMut<'a>: Sized {
10801080
walk_ts_import_type(self, it);
10811081
}
10821082

1083-
#[inline]
1084-
fn visit_ts_import_attributes(&mut self, it: &mut TSImportAttributes<'a>) {
1085-
walk_ts_import_attributes(self, it);
1086-
}
1087-
1088-
#[inline]
1089-
fn visit_ts_import_attribute(&mut self, it: &mut TSImportAttribute<'a>) {
1090-
walk_ts_import_attribute(self, it);
1091-
}
1092-
1093-
#[inline]
1094-
fn visit_ts_import_attribute_name(&mut self, it: &mut TSImportAttributeName<'a>) {
1095-
walk_ts_import_attribute_name(self, it);
1096-
}
1097-
10981083
#[inline]
10991084
fn visit_ts_function_type(&mut self, it: &mut TSFunctionType<'a>) {
11001085
walk_ts_function_type(self, it);
@@ -1331,11 +1316,6 @@ pub trait VisitMut<'a>: Sized {
13311316
walk_ts_index_signature_names(self, it);
13321317
}
13331318

1334-
#[inline]
1335-
fn visit_ts_import_attribute_list(&mut self, it: &mut Vec<'a, TSImportAttribute<'a>>) {
1336-
walk_ts_import_attribute_list(self, it);
1337-
}
1338-
13391319
#[inline]
13401320
fn visit_spans(&mut self, it: &mut Vec<'a, Span>) {
13411321
walk_spans(self, it);
@@ -4120,7 +4100,7 @@ pub mod walk_mut {
41204100
visitor.visit_span(&mut it.span);
41214101
visitor.visit_ts_type(&mut it.argument);
41224102
if let Some(options) = &mut it.options {
4123-
visitor.visit_ts_import_attributes(options);
4103+
visitor.visit_object_expression(options);
41244104
}
41254105
if let Some(qualifier) = &mut it.qualifier {
41264106
visitor.visit_ts_type_name(qualifier);
@@ -4131,40 +4111,6 @@ pub mod walk_mut {
41314111
visitor.leave_node(kind);
41324112
}
41334113

4134-
#[inline]
4135-
pub fn walk_ts_import_attributes<'a, V: VisitMut<'a>>(
4136-
visitor: &mut V,
4137-
it: &mut TSImportAttributes<'a>,
4138-
) {
4139-
// No `AstType` for this type
4140-
visitor.visit_span(&mut it.span);
4141-
visitor.visit_identifier_name(&mut it.attributes_keyword);
4142-
visitor.visit_ts_import_attribute_list(&mut it.elements);
4143-
}
4144-
4145-
#[inline]
4146-
pub fn walk_ts_import_attribute<'a, V: VisitMut<'a>>(
4147-
visitor: &mut V,
4148-
it: &mut TSImportAttribute<'a>,
4149-
) {
4150-
// No `AstType` for this type
4151-
visitor.visit_span(&mut it.span);
4152-
visitor.visit_ts_import_attribute_name(&mut it.name);
4153-
visitor.visit_expression(&mut it.value);
4154-
}
4155-
4156-
#[inline]
4157-
pub fn walk_ts_import_attribute_name<'a, V: VisitMut<'a>>(
4158-
visitor: &mut V,
4159-
it: &mut TSImportAttributeName<'a>,
4160-
) {
4161-
// No `AstType` for this type
4162-
match it {
4163-
TSImportAttributeName::Identifier(it) => visitor.visit_identifier_name(it),
4164-
TSImportAttributeName::StringLiteral(it) => visitor.visit_string_literal(it),
4165-
}
4166-
}
4167-
41684114
#[inline]
41694115
pub fn walk_ts_function_type<'a, V: VisitMut<'a>>(
41704116
visitor: &mut V,
@@ -4652,16 +4598,6 @@ pub mod walk_mut {
46524598
}
46534599
}
46544600

4655-
#[inline]
4656-
pub fn walk_ts_import_attribute_list<'a, V: VisitMut<'a>>(
4657-
visitor: &mut V,
4658-
it: &mut Vec<'a, TSImportAttribute<'a>>,
4659-
) {
4660-
for el in it {
4661-
visitor.visit_ts_import_attribute(el);
4662-
}
4663-
}
4664-
46654601
#[inline]
46664602
pub fn walk_spans<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Vec<'a, Span>) {
46674603
for el in it {

‎crates/oxc_codegen/src/gen.rs

+2-38
Original file line numberDiff line numberDiff line change
@@ -3552,9 +3552,9 @@ impl Gen for TSImportType<'_> {
35523552
}
35533553
p.print_str("import(");
35543554
self.argument.print(p, ctx);
3555-
if let Some(attributes) = &self.options {
3555+
if let Some(options) = &self.options {
35563556
p.print_str(", ");
3557-
attributes.print(p, ctx);
3557+
options.print_expr(p, Precedence::Lowest, ctx);
35583558
}
35593559
p.print_str(")");
35603560
if let Some(qualifier) = &self.qualifier {
@@ -3567,42 +3567,6 @@ impl Gen for TSImportType<'_> {
35673567
}
35683568
}
35693569

3570-
impl Gen for TSImportAttributes<'_> {
3571-
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
3572-
p.print_ascii_byte(b'{');
3573-
p.print_soft_space();
3574-
self.attributes_keyword.print(p, ctx);
3575-
p.print_str(":");
3576-
p.print_soft_space();
3577-
p.print_ascii_byte(b'{');
3578-
p.print_soft_space();
3579-
p.print_list(&self.elements, ctx);
3580-
p.print_soft_space();
3581-
p.print_ascii_byte(b'}');
3582-
p.print_soft_space();
3583-
p.print_ascii_byte(b'}');
3584-
}
3585-
}
3586-
3587-
impl Gen for TSImportAttribute<'_> {
3588-
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
3589-
self.name.print(p, ctx);
3590-
p.print_str(": ");
3591-
self.value.print_expr(p, Precedence::Member, ctx);
3592-
}
3593-
}
3594-
3595-
impl Gen for TSImportAttributeName<'_> {
3596-
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
3597-
match self {
3598-
TSImportAttributeName::Identifier(ident) => ident.print(p, ctx),
3599-
TSImportAttributeName::StringLiteral(literal) => {
3600-
p.print_string_literal(literal, false);
3601-
}
3602-
}
3603-
}
3604-
}
3605-
36063570
impl Gen for TSTypeParameterInstantiation<'_> {
36073571
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
36083572
p.print_str("<");

‎crates/oxc_parser/src/js/expression.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a> ParserImpl<'a> {
172172
// ArrayLiteral
173173
Kind::LBrack => self.parse_array_expression(),
174174
// ObjectLiteral
175-
Kind::LCurly => self.parse_object_expression(),
175+
Kind::LCurly => self.parse_object_expression().map(Expression::ObjectExpression),
176176
// ClassExpression
177177
Kind::Class => self.parse_class_expression(),
178178
// This

‎crates/oxc_parser/src/js/object.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<'a> ParserImpl<'a> {
1212
/// { }
1313
/// { `PropertyDefinitionList`[?Yield, ?Await] }
1414
/// { `PropertyDefinitionList`[?Yield, ?Await] , }
15-
pub(crate) fn parse_object_expression(&mut self) -> Result<Expression<'a>> {
15+
pub(crate) fn parse_object_expression(&mut self) -> Result<Box<'a, ObjectExpression<'a>>> {
1616
let span = self.start_span();
1717
self.expect(Kind::LCurly)?;
1818
let object_expression_properties = self.context(Context::In, Context::empty(), |p| {
@@ -29,7 +29,7 @@ impl<'a> ParserImpl<'a> {
2929
self.end_span(span)
3030
});
3131
self.expect(Kind::RCurly)?;
32-
Ok(self.ast.expression_object(
32+
Ok(self.ast.alloc_object_expression(
3333
self.end_span(span),
3434
object_expression_properties,
3535
trailing_comma,

‎crates/oxc_parser/src/ts/types.rs

+1-36
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ impl<'a> ParserImpl<'a> {
982982
self.expect(Kind::LParen)?;
983983
let argument = self.parse_ts_type()?;
984984
let options =
985-
if self.eat(Kind::Comma) { Some(self.parse_ts_import_attributes()?) } else { None };
985+
if self.eat(Kind::Comma) { Some(self.parse_object_expression()?) } else { None };
986986
self.expect(Kind::RParen)?;
987987
let qualifier = if self.eat(Kind::Dot) { Some(self.parse_ts_type_name()?) } else { None };
988988
let type_arguments = self.parse_type_arguments_of_type_reference()?;
@@ -996,41 +996,6 @@ impl<'a> ParserImpl<'a> {
996996
))
997997
}
998998

999-
fn parse_ts_import_attributes(&mut self) -> Result<TSImportAttributes<'a>> {
1000-
let span = self.start_span();
1001-
self.expect(Kind::LCurly)?;
1002-
let attributes_keyword = match self.cur_kind() {
1003-
Kind::Assert if !self.cur_token().is_on_new_line => self.parse_identifier_name()?,
1004-
Kind::With => self.parse_identifier_name()?,
1005-
_ => {
1006-
return Err(self.unexpected());
1007-
}
1008-
};
1009-
self.expect(Kind::Colon)?;
1010-
self.expect(Kind::LCurly)?;
1011-
let elements = self.parse_delimited_list(
1012-
Kind::RCurly,
1013-
Kind::Comma,
1014-
/* trailing_separator */ true,
1015-
Self::parse_ts_import_attribute,
1016-
)?;
1017-
self.expect(Kind::RCurly)?;
1018-
self.expect(Kind::RCurly)?;
1019-
Ok(self.ast.ts_import_attributes(self.end_span(span), attributes_keyword, elements))
1020-
}
1021-
1022-
fn parse_ts_import_attribute(&mut self) -> Result<TSImportAttribute<'a>> {
1023-
let span = self.start_span();
1024-
let name = match self.cur_kind() {
1025-
Kind::Str => TSImportAttributeName::StringLiteral(self.parse_literal_string()?),
1026-
_ => TSImportAttributeName::Identifier(self.parse_identifier_name()?),
1027-
};
1028-
1029-
self.expect(Kind::Colon)?;
1030-
let value = self.parse_expr()?;
1031-
Ok(self.ast.ts_import_attribute(self.end_span(span), name, value))
1032-
}
1033-
1034999
fn try_parse_constraint_of_infer_type(&mut self) -> Result<Option<TSType<'a>>> {
10351000
if self.eat(Kind::Extends) {
10361001
let constraint = self.context(

‎crates/oxc_traverse/src/generated/ancestor.rs

+35-195
Original file line numberDiff line numberDiff line change
@@ -285,39 +285,35 @@ pub(crate) enum AncestorType {
285285
TSImportTypeOptions = 262,
286286
TSImportTypeQualifier = 263,
287287
TSImportTypeTypeArguments = 264,
288-
TSImportAttributesAttributesKeyword = 265,
289-
TSImportAttributesElements = 266,
290-
TSImportAttributeName = 267,
291-
TSImportAttributeValue = 268,
292-
TSFunctionTypeTypeParameters = 269,
293-
TSFunctionTypeThisParam = 270,
294-
TSFunctionTypeParams = 271,
295-
TSFunctionTypeReturnType = 272,
296-
TSConstructorTypeTypeParameters = 273,
297-
TSConstructorTypeParams = 274,
298-
TSConstructorTypeReturnType = 275,
299-
TSMappedTypeTypeParameter = 276,
300-
TSMappedTypeNameType = 277,
301-
TSMappedTypeTypeAnnotation = 278,
302-
TSTemplateLiteralTypeQuasis = 279,
303-
TSTemplateLiteralTypeTypes = 280,
304-
TSAsExpressionExpression = 281,
305-
TSAsExpressionTypeAnnotation = 282,
306-
TSSatisfiesExpressionExpression = 283,
307-
TSSatisfiesExpressionTypeAnnotation = 284,
308-
TSTypeAssertionExpression = 285,
309-
TSTypeAssertionTypeAnnotation = 286,
310-
TSImportEqualsDeclarationId = 287,
311-
TSImportEqualsDeclarationModuleReference = 288,
312-
TSExternalModuleReferenceExpression = 289,
313-
TSNonNullExpressionExpression = 290,
314-
DecoratorExpression = 291,
315-
TSExportAssignmentExpression = 292,
316-
TSNamespaceExportDeclarationId = 293,
317-
TSInstantiationExpressionExpression = 294,
318-
TSInstantiationExpressionTypeParameters = 295,
319-
JSDocNullableTypeTypeAnnotation = 296,
320-
JSDocNonNullableTypeTypeAnnotation = 297,
288+
TSFunctionTypeTypeParameters = 265,
289+
TSFunctionTypeThisParam = 266,
290+
TSFunctionTypeParams = 267,
291+
TSFunctionTypeReturnType = 268,
292+
TSConstructorTypeTypeParameters = 269,
293+
TSConstructorTypeParams = 270,
294+
TSConstructorTypeReturnType = 271,
295+
TSMappedTypeTypeParameter = 272,
296+
TSMappedTypeNameType = 273,
297+
TSMappedTypeTypeAnnotation = 274,
298+
TSTemplateLiteralTypeQuasis = 275,
299+
TSTemplateLiteralTypeTypes = 276,
300+
TSAsExpressionExpression = 277,
301+
TSAsExpressionTypeAnnotation = 278,
302+
TSSatisfiesExpressionExpression = 279,
303+
TSSatisfiesExpressionTypeAnnotation = 280,
304+
TSTypeAssertionExpression = 281,
305+
TSTypeAssertionTypeAnnotation = 282,
306+
TSImportEqualsDeclarationId = 283,
307+
TSImportEqualsDeclarationModuleReference = 284,
308+
TSExternalModuleReferenceExpression = 285,
309+
TSNonNullExpressionExpression = 286,
310+
DecoratorExpression = 287,
311+
TSExportAssignmentExpression = 288,
312+
TSNamespaceExportDeclarationId = 289,
313+
TSInstantiationExpressionExpression = 290,
314+
TSInstantiationExpressionTypeParameters = 291,
315+
JSDocNullableTypeTypeAnnotation = 292,
316+
JSDocNonNullableTypeTypeAnnotation = 293,
321317
}
322318

323319
/// Ancestor type used in AST traversal.
@@ -829,14 +825,6 @@ pub enum Ancestor<'a, 't> {
829825
AncestorType::TSImportTypeQualifier as u16,
830826
TSImportTypeTypeArguments(TSImportTypeWithoutTypeArguments<'a, 't>) =
831827
AncestorType::TSImportTypeTypeArguments as u16,
832-
TSImportAttributesAttributesKeyword(TSImportAttributesWithoutAttributesKeyword<'a, 't>) =
833-
AncestorType::TSImportAttributesAttributesKeyword as u16,
834-
TSImportAttributesElements(TSImportAttributesWithoutElements<'a, 't>) =
835-
AncestorType::TSImportAttributesElements as u16,
836-
TSImportAttributeName(TSImportAttributeWithoutName<'a, 't>) =
837-
AncestorType::TSImportAttributeName as u16,
838-
TSImportAttributeValue(TSImportAttributeWithoutValue<'a, 't>) =
839-
AncestorType::TSImportAttributeValue as u16,
840828
TSFunctionTypeTypeParameters(TSFunctionTypeWithoutTypeParameters<'a, 't>) =
841829
AncestorType::TSFunctionTypeTypeParameters as u16,
842830
TSFunctionTypeThisParam(TSFunctionTypeWithoutThisParam<'a, 't>) =
@@ -1756,19 +1744,6 @@ impl<'a, 't> Ancestor<'a, 't> {
17561744
)
17571745
}
17581746

1759-
#[inline]
1760-
pub fn is_ts_import_attributes(self) -> bool {
1761-
matches!(
1762-
self,
1763-
Self::TSImportAttributesAttributesKeyword(_) | Self::TSImportAttributesElements(_)
1764-
)
1765-
}
1766-
1767-
#[inline]
1768-
pub fn is_ts_import_attribute(self) -> bool {
1769-
matches!(self, Self::TSImportAttributeName(_) | Self::TSImportAttributeValue(_))
1770-
}
1771-
17721747
#[inline]
17731748
pub fn is_ts_function_type(self) -> bool {
17741749
matches!(
@@ -1977,7 +1952,6 @@ impl<'a, 't> Ancestor<'a, 't> {
19771952
| Self::JSXSpreadChildExpression(_)
19781953
| Self::TSEnumMemberInitializer(_)
19791954
| Self::TSInterfaceHeritageExpression(_)
1980-
| Self::TSImportAttributeValue(_)
19811955
| Self::TSAsExpressionExpression(_)
19821956
| Self::TSSatisfiesExpressionExpression(_)
19831957
| Self::TSTypeAssertionExpression(_)
@@ -2204,11 +2178,6 @@ impl<'a, 't> Ancestor<'a, 't> {
22042178
matches!(self, Self::TSTypeQueryExprName(_))
22052179
}
22062180

2207-
#[inline]
2208-
pub fn is_parent_of_ts_import_attribute_name(self) -> bool {
2209-
matches!(self, Self::TSImportAttributeName(_))
2210-
}
2211-
22122181
#[inline]
22132182
pub fn is_parent_of_ts_module_reference(self) -> bool {
22142183
matches!(self, Self::TSImportEqualsDeclarationModuleReference(_))
@@ -2486,10 +2455,6 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> {
24862455
Self::TSImportTypeOptions(a) => a.address(),
24872456
Self::TSImportTypeQualifier(a) => a.address(),
24882457
Self::TSImportTypeTypeArguments(a) => a.address(),
2489-
Self::TSImportAttributesAttributesKeyword(a) => a.address(),
2490-
Self::TSImportAttributesElements(a) => a.address(),
2491-
Self::TSImportAttributeName(a) => a.address(),
2492-
Self::TSImportAttributeValue(a) => a.address(),
24932458
Self::TSFunctionTypeTypeParameters(a) => a.address(),
24942459
Self::TSFunctionTypeThisParam(a) => a.address(),
24952460
Self::TSFunctionTypeParams(a) => a.address(),
@@ -14266,10 +14231,10 @@ impl<'a, 't> TSImportTypeWithoutArgument<'a, 't> {
1426614231
}
1426714232

1426814233
#[inline]
14269-
pub fn options(self) -> &'t Option<Box<'a, TSImportAttributes<'a>>> {
14234+
pub fn options(self) -> &'t Option<Box<'a, ObjectExpression<'a>>> {
1427014235
unsafe {
1427114236
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_OPTIONS)
14272-
as *const Option<Box<'a, TSImportAttributes<'a>>>)
14237+
as *const Option<Box<'a, ObjectExpression<'a>>>)
1427314238
}
1427414239
}
1427514240

@@ -14372,10 +14337,10 @@ impl<'a, 't> TSImportTypeWithoutQualifier<'a, 't> {
1437214337
}
1437314338

1437414339
#[inline]
14375-
pub fn options(self) -> &'t Option<Box<'a, TSImportAttributes<'a>>> {
14340+
pub fn options(self) -> &'t Option<Box<'a, ObjectExpression<'a>>> {
1437614341
unsafe {
1437714342
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_OPTIONS)
14378-
as *const Option<Box<'a, TSImportAttributes<'a>>>)
14343+
as *const Option<Box<'a, ObjectExpression<'a>>>)
1437914344
}
1438014345
}
1438114346

@@ -14421,10 +14386,10 @@ impl<'a, 't> TSImportTypeWithoutTypeArguments<'a, 't> {
1442114386
}
1442214387

1442314388
#[inline]
14424-
pub fn options(self) -> &'t Option<Box<'a, TSImportAttributes<'a>>> {
14389+
pub fn options(self) -> &'t Option<Box<'a, ObjectExpression<'a>>> {
1442514390
unsafe {
1442614391
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_OPTIONS)
14427-
as *const Option<Box<'a, TSImportAttributes<'a>>>)
14392+
as *const Option<Box<'a, ObjectExpression<'a>>>)
1442814393
}
1442914394
}
1443014395

@@ -14449,131 +14414,6 @@ impl<'a, 't> GetAddress for TSImportTypeWithoutTypeArguments<'a, 't> {
1444914414
}
1445014415
}
1445114416

14452-
pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTES_SPAN: usize = offset_of!(TSImportAttributes, span);
14453-
pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTES_ATTRIBUTES_KEYWORD: usize =
14454-
offset_of!(TSImportAttributes, attributes_keyword);
14455-
pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTES_ELEMENTS: usize =
14456-
offset_of!(TSImportAttributes, elements);
14457-
14458-
#[repr(transparent)]
14459-
#[derive(Clone, Copy, Debug)]
14460-
pub struct TSImportAttributesWithoutAttributesKeyword<'a, 't>(
14461-
pub(crate) *const TSImportAttributes<'a>,
14462-
pub(crate) PhantomData<&'t ()>,
14463-
);
14464-
14465-
impl<'a, 't> TSImportAttributesWithoutAttributesKeyword<'a, 't> {
14466-
#[inline]
14467-
pub fn span(self) -> &'t Span {
14468-
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_SPAN) as *const Span) }
14469-
}
14470-
14471-
#[inline]
14472-
pub fn elements(self) -> &'t Vec<'a, TSImportAttribute<'a>> {
14473-
unsafe {
14474-
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_ELEMENTS)
14475-
as *const Vec<'a, TSImportAttribute<'a>>)
14476-
}
14477-
}
14478-
}
14479-
14480-
impl<'a, 't> GetAddress for TSImportAttributesWithoutAttributesKeyword<'a, 't> {
14481-
#[inline]
14482-
fn address(&self) -> Address {
14483-
Address::from_ptr(self.0)
14484-
}
14485-
}
14486-
14487-
#[repr(transparent)]
14488-
#[derive(Clone, Copy, Debug)]
14489-
pub struct TSImportAttributesWithoutElements<'a, 't>(
14490-
pub(crate) *const TSImportAttributes<'a>,
14491-
pub(crate) PhantomData<&'t ()>,
14492-
);
14493-
14494-
impl<'a, 't> TSImportAttributesWithoutElements<'a, 't> {
14495-
#[inline]
14496-
pub fn span(self) -> &'t Span {
14497-
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_SPAN) as *const Span) }
14498-
}
14499-
14500-
#[inline]
14501-
pub fn attributes_keyword(self) -> &'t IdentifierName<'a> {
14502-
unsafe {
14503-
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_ATTRIBUTES_KEYWORD)
14504-
as *const IdentifierName<'a>)
14505-
}
14506-
}
14507-
}
14508-
14509-
impl<'a, 't> GetAddress for TSImportAttributesWithoutElements<'a, 't> {
14510-
#[inline]
14511-
fn address(&self) -> Address {
14512-
Address::from_ptr(self.0)
14513-
}
14514-
}
14515-
14516-
pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTE_SPAN: usize = offset_of!(TSImportAttribute, span);
14517-
pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTE_NAME: usize = offset_of!(TSImportAttribute, name);
14518-
pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTE_VALUE: usize = offset_of!(TSImportAttribute, value);
14519-
14520-
#[repr(transparent)]
14521-
#[derive(Clone, Copy, Debug)]
14522-
pub struct TSImportAttributeWithoutName<'a, 't>(
14523-
pub(crate) *const TSImportAttribute<'a>,
14524-
pub(crate) PhantomData<&'t ()>,
14525-
);
14526-
14527-
impl<'a, 't> TSImportAttributeWithoutName<'a, 't> {
14528-
#[inline]
14529-
pub fn span(self) -> &'t Span {
14530-
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_SPAN) as *const Span) }
14531-
}
14532-
14533-
#[inline]
14534-
pub fn value(self) -> &'t Expression<'a> {
14535-
unsafe {
14536-
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_VALUE) as *const Expression<'a>)
14537-
}
14538-
}
14539-
}
14540-
14541-
impl<'a, 't> GetAddress for TSImportAttributeWithoutName<'a, 't> {
14542-
#[inline]
14543-
fn address(&self) -> Address {
14544-
Address::from_ptr(self.0)
14545-
}
14546-
}
14547-
14548-
#[repr(transparent)]
14549-
#[derive(Clone, Copy, Debug)]
14550-
pub struct TSImportAttributeWithoutValue<'a, 't>(
14551-
pub(crate) *const TSImportAttribute<'a>,
14552-
pub(crate) PhantomData<&'t ()>,
14553-
);
14554-
14555-
impl<'a, 't> TSImportAttributeWithoutValue<'a, 't> {
14556-
#[inline]
14557-
pub fn span(self) -> &'t Span {
14558-
unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_SPAN) as *const Span) }
14559-
}
14560-
14561-
#[inline]
14562-
pub fn name(self) -> &'t TSImportAttributeName<'a> {
14563-
unsafe {
14564-
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_NAME)
14565-
as *const TSImportAttributeName<'a>)
14566-
}
14567-
}
14568-
}
14569-
14570-
impl<'a, 't> GetAddress for TSImportAttributeWithoutValue<'a, 't> {
14571-
#[inline]
14572-
fn address(&self) -> Address {
14573-
Address::from_ptr(self.0)
14574-
}
14575-
}
14576-
1457714417
pub(crate) const OFFSET_TS_FUNCTION_TYPE_SPAN: usize = offset_of!(TSFunctionType, span);
1457814418
pub(crate) const OFFSET_TS_FUNCTION_TYPE_TYPE_PARAMETERS: usize =
1457914419
offset_of!(TSFunctionType, type_parameters);

‎crates/oxc_traverse/src/generated/traverse.rs

-45
Original file line numberDiff line numberDiff line change
@@ -2204,51 +2204,6 @@ pub trait Traverse<'a> {
22042204
#[inline]
22052205
fn exit_ts_import_type(&mut self, node: &mut TSImportType<'a>, ctx: &mut TraverseCtx<'a>) {}
22062206

2207-
#[inline]
2208-
fn enter_ts_import_attributes(
2209-
&mut self,
2210-
node: &mut TSImportAttributes<'a>,
2211-
ctx: &mut TraverseCtx<'a>,
2212-
) {
2213-
}
2214-
#[inline]
2215-
fn exit_ts_import_attributes(
2216-
&mut self,
2217-
node: &mut TSImportAttributes<'a>,
2218-
ctx: &mut TraverseCtx<'a>,
2219-
) {
2220-
}
2221-
2222-
#[inline]
2223-
fn enter_ts_import_attribute(
2224-
&mut self,
2225-
node: &mut TSImportAttribute<'a>,
2226-
ctx: &mut TraverseCtx<'a>,
2227-
) {
2228-
}
2229-
#[inline]
2230-
fn exit_ts_import_attribute(
2231-
&mut self,
2232-
node: &mut TSImportAttribute<'a>,
2233-
ctx: &mut TraverseCtx<'a>,
2234-
) {
2235-
}
2236-
2237-
#[inline]
2238-
fn enter_ts_import_attribute_name(
2239-
&mut self,
2240-
node: &mut TSImportAttributeName<'a>,
2241-
ctx: &mut TraverseCtx<'a>,
2242-
) {
2243-
}
2244-
#[inline]
2245-
fn exit_ts_import_attribute_name(
2246-
&mut self,
2247-
node: &mut TSImportAttributeName<'a>,
2248-
ctx: &mut TraverseCtx<'a>,
2249-
) {
2250-
}
2251-
22522207
#[inline]
22532208
fn enter_ts_function_type(&mut self, node: &mut TSFunctionType<'a>, ctx: &mut TraverseCtx<'a>) {
22542209
}

‎crates/oxc_traverse/src/generated/walk.rs

+2-69
Original file line numberDiff line numberDiff line change
@@ -5130,10 +5130,10 @@ unsafe fn walk_ts_import_type<'a, Tr: Traverse<'a>>(
51305130
ctx,
51315131
);
51325132
if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_TYPE_OPTIONS)
5133-
as *mut Option<Box<TSImportAttributes>>)
5133+
as *mut Option<Box<ObjectExpression>>)
51345134
{
51355135
ctx.retag_stack(AncestorType::TSImportTypeOptions);
5136-
walk_ts_import_attributes(traverser, (&mut **field) as *mut _, ctx);
5136+
walk_object_expression(traverser, (&mut **field) as *mut _, ctx);
51375137
}
51385138
if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_TYPE_QUALIFIER)
51395139
as *mut Option<TSTypeName>)
@@ -5152,73 +5152,6 @@ unsafe fn walk_ts_import_type<'a, Tr: Traverse<'a>>(
51525152
traverser.exit_ts_import_type(&mut *node, ctx);
51535153
}
51545154

5155-
unsafe fn walk_ts_import_attributes<'a, Tr: Traverse<'a>>(
5156-
traverser: &mut Tr,
5157-
node: *mut TSImportAttributes<'a>,
5158-
ctx: &mut TraverseCtx<'a>,
5159-
) {
5160-
traverser.enter_ts_import_attributes(&mut *node, ctx);
5161-
let pop_token = ctx.push_stack(Ancestor::TSImportAttributesAttributesKeyword(
5162-
ancestor::TSImportAttributesWithoutAttributesKeyword(node, PhantomData),
5163-
));
5164-
walk_identifier_name(
5165-
traverser,
5166-
(node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTES_ATTRIBUTES_KEYWORD)
5167-
as *mut IdentifierName,
5168-
ctx,
5169-
);
5170-
ctx.retag_stack(AncestorType::TSImportAttributesElements);
5171-
for item in &mut *((node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTES_ELEMENTS)
5172-
as *mut Vec<TSImportAttribute>)
5173-
{
5174-
walk_ts_import_attribute(traverser, item as *mut _, ctx);
5175-
}
5176-
ctx.pop_stack(pop_token);
5177-
traverser.exit_ts_import_attributes(&mut *node, ctx);
5178-
}
5179-
5180-
unsafe fn walk_ts_import_attribute<'a, Tr: Traverse<'a>>(
5181-
traverser: &mut Tr,
5182-
node: *mut TSImportAttribute<'a>,
5183-
ctx: &mut TraverseCtx<'a>,
5184-
) {
5185-
traverser.enter_ts_import_attribute(&mut *node, ctx);
5186-
let pop_token = ctx.push_stack(Ancestor::TSImportAttributeName(
5187-
ancestor::TSImportAttributeWithoutName(node, PhantomData),
5188-
));
5189-
walk_ts_import_attribute_name(
5190-
traverser,
5191-
(node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTE_NAME)
5192-
as *mut TSImportAttributeName,
5193-
ctx,
5194-
);
5195-
ctx.retag_stack(AncestorType::TSImportAttributeValue);
5196-
walk_expression(
5197-
traverser,
5198-
(node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTE_VALUE) as *mut Expression,
5199-
ctx,
5200-
);
5201-
ctx.pop_stack(pop_token);
5202-
traverser.exit_ts_import_attribute(&mut *node, ctx);
5203-
}
5204-
5205-
unsafe fn walk_ts_import_attribute_name<'a, Tr: Traverse<'a>>(
5206-
traverser: &mut Tr,
5207-
node: *mut TSImportAttributeName<'a>,
5208-
ctx: &mut TraverseCtx<'a>,
5209-
) {
5210-
traverser.enter_ts_import_attribute_name(&mut *node, ctx);
5211-
match &mut *node {
5212-
TSImportAttributeName::Identifier(node) => {
5213-
walk_identifier_name(traverser, node as *mut _, ctx)
5214-
}
5215-
TSImportAttributeName::StringLiteral(node) => {
5216-
walk_string_literal(traverser, node as *mut _, ctx)
5217-
}
5218-
}
5219-
traverser.exit_ts_import_attribute_name(&mut *node, ctx);
5220-
}
5221-
52225155
unsafe fn walk_ts_function_type<'a, Tr: Traverse<'a>>(
52235156
traverser: &mut Tr,
52245157
node: *mut TSFunctionType<'a>,

‎napi/parser/deserialize-js.js

+3-50
Original file line numberDiff line numberDiff line change
@@ -1775,33 +1775,13 @@ function deserializeTSImportType(pos) {
17751775
start: deserializeU32(pos),
17761776
end: deserializeU32(pos + 4),
17771777
argument: deserializeTSType(pos + 8),
1778-
options: deserializeOptionBoxTSImportAttributes(pos + 24),
1778+
options: deserializeOptionBoxObjectExpression(pos + 24),
17791779
qualifier: deserializeOptionTSTypeName(pos + 32),
17801780
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
17811781
isTypeOf: deserializeBool(pos + 56),
17821782
};
17831783
}
17841784

1785-
function deserializeTSImportAttributes(pos) {
1786-
return {
1787-
type: 'TSImportAttributes',
1788-
start: deserializeU32(pos),
1789-
end: deserializeU32(pos + 4),
1790-
attributesKeyword: deserializeIdentifierName(pos + 8),
1791-
elements: deserializeVecTSImportAttribute(pos + 32),
1792-
};
1793-
}
1794-
1795-
function deserializeTSImportAttribute(pos) {
1796-
return {
1797-
type: 'TSImportAttribute',
1798-
start: deserializeU32(pos),
1799-
end: deserializeU32(pos + 4),
1800-
name: deserializeTSImportAttributeName(pos + 8),
1801-
value: deserializeExpression(pos + 56),
1802-
};
1803-
}
1804-
18051785
function deserializeTSFunctionType(pos) {
18061786
return {
18071787
type: 'TSFunctionType',
@@ -3860,17 +3840,6 @@ function deserializeTSTypeQueryExprName(pos) {
38603840
}
38613841
}
38623842

3863-
function deserializeTSImportAttributeName(pos) {
3864-
switch (uint8[pos]) {
3865-
case 0:
3866-
return deserializeIdentifierName(pos + 8);
3867-
case 1:
3868-
return deserializeStringLiteral(pos + 8);
3869-
default:
3870-
throw new Error(`Unexpected discriminant ${uint8[pos]} for TSImportAttributeName`);
3871-
}
3872-
}
3873-
38743843
function deserializeTSMappedTypeModifierOperator(pos) {
38753844
switch (uint8[pos]) {
38763845
case 0:
@@ -5516,32 +5485,16 @@ function deserializeBoxTSTypeParameter(pos) {
55165485
return deserializeTSTypeParameter(uint32[pos >> 2]);
55175486
}
55185487

5519-
function deserializeBoxTSImportAttributes(pos) {
5520-
return deserializeTSImportAttributes(uint32[pos >> 2]);
5521-
}
5522-
5523-
function deserializeOptionBoxTSImportAttributes(pos) {
5488+
function deserializeOptionBoxObjectExpression(pos) {
55245489
if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
5525-
return deserializeBoxTSImportAttributes(pos);
5490+
return deserializeBoxObjectExpression(pos);
55265491
}
55275492

55285493
function deserializeOptionTSTypeName(pos) {
55295494
if (uint8[pos] === 2) return null;
55305495
return deserializeTSTypeName(pos);
55315496
}
55325497

5533-
function deserializeVecTSImportAttribute(pos) {
5534-
const arr = [],
5535-
pos32 = pos >> 2,
5536-
len = uint32[pos32 + 6];
5537-
pos = uint32[pos32];
5538-
for (let i = 0; i < len; i++) {
5539-
arr.push(deserializeTSImportAttribute(pos));
5540-
pos += 72;
5541-
}
5542-
return arr;
5543-
}
5544-
55455498
function deserializeBoxTSExternalModuleReference(pos) {
55465499
return deserializeTSExternalModuleReference(uint32[pos >> 2]);
55475500
}

‎napi/parser/deserialize-ts.js

+3-50
Original file line numberDiff line numberDiff line change
@@ -1836,33 +1836,13 @@ function deserializeTSImportType(pos) {
18361836
start: deserializeU32(pos),
18371837
end: deserializeU32(pos + 4),
18381838
argument: deserializeTSType(pos + 8),
1839-
options: deserializeOptionBoxTSImportAttributes(pos + 24),
1839+
options: deserializeOptionBoxObjectExpression(pos + 24),
18401840
qualifier: deserializeOptionTSTypeName(pos + 32),
18411841
typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48),
18421842
isTypeOf: deserializeBool(pos + 56),
18431843
};
18441844
}
18451845

1846-
function deserializeTSImportAttributes(pos) {
1847-
return {
1848-
type: 'TSImportAttributes',
1849-
start: deserializeU32(pos),
1850-
end: deserializeU32(pos + 4),
1851-
attributesKeyword: deserializeIdentifierName(pos + 8),
1852-
elements: deserializeVecTSImportAttribute(pos + 32),
1853-
};
1854-
}
1855-
1856-
function deserializeTSImportAttribute(pos) {
1857-
return {
1858-
type: 'TSImportAttribute',
1859-
start: deserializeU32(pos),
1860-
end: deserializeU32(pos + 4),
1861-
name: deserializeTSImportAttributeName(pos + 8),
1862-
value: deserializeExpression(pos + 56),
1863-
};
1864-
}
1865-
18661846
function deserializeTSFunctionType(pos) {
18671847
return {
18681848
type: 'TSFunctionType',
@@ -3921,17 +3901,6 @@ function deserializeTSTypeQueryExprName(pos) {
39213901
}
39223902
}
39233903

3924-
function deserializeTSImportAttributeName(pos) {
3925-
switch (uint8[pos]) {
3926-
case 0:
3927-
return deserializeIdentifierName(pos + 8);
3928-
case 1:
3929-
return deserializeStringLiteral(pos + 8);
3930-
default:
3931-
throw new Error(`Unexpected discriminant ${uint8[pos]} for TSImportAttributeName`);
3932-
}
3933-
}
3934-
39353904
function deserializeTSMappedTypeModifierOperator(pos) {
39363905
switch (uint8[pos]) {
39373906
case 0:
@@ -5577,32 +5546,16 @@ function deserializeBoxTSTypeParameter(pos) {
55775546
return deserializeTSTypeParameter(uint32[pos >> 2]);
55785547
}
55795548

5580-
function deserializeBoxTSImportAttributes(pos) {
5581-
return deserializeTSImportAttributes(uint32[pos >> 2]);
5582-
}
5583-
5584-
function deserializeOptionBoxTSImportAttributes(pos) {
5549+
function deserializeOptionBoxObjectExpression(pos) {
55855550
if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
5586-
return deserializeBoxTSImportAttributes(pos);
5551+
return deserializeBoxObjectExpression(pos);
55875552
}
55885553

55895554
function deserializeOptionTSTypeName(pos) {
55905555
if (uint8[pos] === 2) return null;
55915556
return deserializeTSTypeName(pos);
55925557
}
55935558

5594-
function deserializeVecTSImportAttribute(pos) {
5595-
const arr = [],
5596-
pos32 = pos >> 2,
5597-
len = uint32[pos32 + 6];
5598-
pos = uint32[pos32];
5599-
for (let i = 0; i < len; i++) {
5600-
arr.push(deserializeTSImportAttribute(pos));
5601-
pos += 72;
5602-
}
5603-
return arr;
5604-
}
5605-
56065559
function deserializeBoxTSExternalModuleReference(pos) {
56075560
return deserializeTSExternalModuleReference(uint32[pos >> 2]);
56085561
}

‎npm/oxc-types/types.d.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -1292,26 +1292,12 @@ export type TSTypeQueryExprName = TSImportType | TSTypeName;
12921292
export interface TSImportType extends Span {
12931293
type: 'TSImportType';
12941294
argument: TSType;
1295-
options: TSImportAttributes | null;
1295+
options: ObjectExpression | null;
12961296
qualifier: TSTypeName | null;
12971297
typeArguments: TSTypeParameterInstantiation | null;
12981298
isTypeOf: boolean;
12991299
}
13001300

1301-
export interface TSImportAttributes extends Span {
1302-
type: 'TSImportAttributes';
1303-
attributesKeyword: IdentifierName;
1304-
elements: Array<TSImportAttribute>;
1305-
}
1306-
1307-
export interface TSImportAttribute extends Span {
1308-
type: 'TSImportAttribute';
1309-
name: TSImportAttributeName;
1310-
value: Expression;
1311-
}
1312-
1313-
export type TSImportAttributeName = IdentifierName | StringLiteral;
1314-
13151301
export interface TSFunctionType extends Span {
13161302
type: 'TSFunctionType';
13171303
typeParameters: TSTypeParameterDeclaration | null;
@@ -1799,8 +1785,6 @@ export type Node =
17991785
| TSInferType
18001786
| TSTypeQuery
18011787
| TSImportType
1802-
| TSImportAttributes
1803-
| TSImportAttribute
18041788
| TSFunctionType
18051789
| TSConstructorType
18061790
| TSMappedType

‎tasks/ast_tools/src/generators/ast_kind.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::define_generator;
2222
/// Types to omit creating an `AstKind` for.
2323
///
2424
/// Apart from this list every type with `#[ast(visit)]` attr gets an `AstKind`.
25-
const BLACK_LIST: [&str; 64] = [
25+
const BLACK_LIST: [&str; 61] = [
2626
"Span",
2727
"Expression",
2828
"ObjectPropertyKind",
@@ -71,9 +71,6 @@ const BLACK_LIST: [&str; 64] = [
7171
"TSModuleDeclarationName",
7272
"TSModuleDeclarationBody",
7373
"TSTypeQueryExprName",
74-
"TSImportAttribute",
75-
"TSImportAttributes",
76-
"TSImportAttributeName",
7774
"TSFunctionType",
7875
"TSConstructorType",
7976
"TSNamespaceExportDeclaration",

‎tasks/coverage/snapshots/parser_misc.snap

+7-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ Negative Passed: 30/30 (100.00%)
9090
· ─────────
9191
╰────
9292

93-
× Unexpected token
94-
╭─[misc/fail/oxc-2394.ts:20:22]
95-
19export type LocalInterface =
96-
20& import("pkg", {"resolution-mode": "require"}).RequireInterface
97-
· ─────────────────
98-
21& import("pkg", {"resolution-mode": "import"}).ImportInterface;
93+
× Expected `{` but found `[`
94+
╭─[misc/fail/oxc-2394.ts:38:21]
95+
37 │ export type LocalInterface =
96+
38 │ & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface
97+
· ┬
98+
· ╰── `{` expected
99+
39 │ & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface;
99100
╰────
100101
101102
× Unexpected token

0 commit comments

Comments
 (0)
Please sign in to comment.