diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index bb914e5654343..a47c254c62907 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -1279,41 +1279,13 @@ pub enum TSTypeQueryExprName<'a> { pub struct TSImportType<'a> { pub span: Span, pub argument: TSType<'a>, - pub options: Option>>, + pub options: Option>>, pub qualifier: Option>, pub type_arguments: Option>>, /// `true` for `typeof import("foo")` pub is_type_of: bool, } -#[ast(visit)] -#[derive(Debug)] -#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)] -pub struct TSImportAttributes<'a> { - pub span: Span, - pub attributes_keyword: IdentifierName<'a>, // `with` or `assert` - pub elements: Vec<'a, TSImportAttribute<'a>>, -} - -#[ast(visit)] -#[derive(Debug)] -#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)] -// Pluralize as `TSImportAttributeList` to avoid naming clash with `TSImportAttributes`. -#[plural(TSImportAttributeList)] -pub struct TSImportAttribute<'a> { - pub span: Span, - pub name: TSImportAttributeName<'a>, - pub value: Expression<'a>, -} - -#[ast(visit)] -#[derive(Debug)] -#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)] -pub enum TSImportAttributeName<'a> { - Identifier(IdentifierName<'a>) = 0, - StringLiteral(StringLiteral<'a>) = 1, -} - /// TypeScript Function Type /// /// ## Examples diff --git a/crates/oxc_ast/src/generated/assert_layouts.rs b/crates/oxc_ast/src/generated/assert_layouts.rs index 52b22d3413d48..028b94c6a9971 100644 --- a/crates/oxc_ast/src/generated/assert_layouts.rs +++ b/crates/oxc_ast/src/generated/assert_layouts.rs @@ -1263,21 +1263,6 @@ const _: () = { assert!(offset_of!(TSImportType, type_arguments) == 48); assert!(offset_of!(TSImportType, is_type_of) == 56); - assert!(size_of::() == 64); - assert!(align_of::() == 8); - assert!(offset_of!(TSImportAttributes, span) == 0); - assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8); - assert!(offset_of!(TSImportAttributes, elements) == 32); - - assert!(size_of::() == 72); - assert!(align_of::() == 8); - assert!(offset_of!(TSImportAttribute, span) == 0); - assert!(offset_of!(TSImportAttribute, name) == 8); - assert!(offset_of!(TSImportAttribute, value) == 56); - - assert!(size_of::() == 48); - assert!(align_of::() == 8); - assert!(size_of::() == 48); assert!(align_of::() == 8); assert!(offset_of!(TSFunctionType, span) == 0); @@ -2668,21 +2653,6 @@ const _: () = { assert!(offset_of!(TSImportType, type_arguments) == 28); assert!(offset_of!(TSImportType, is_type_of) == 32); - assert!(size_of::() == 40); - assert!(align_of::() == 4); - assert!(offset_of!(TSImportAttributes, span) == 0); - assert!(offset_of!(TSImportAttributes, attributes_keyword) == 8); - assert!(offset_of!(TSImportAttributes, elements) == 24); - - assert!(size_of::() == 44); - assert!(align_of::() == 4); - assert!(offset_of!(TSImportAttribute, span) == 0); - assert!(offset_of!(TSImportAttribute, name) == 8); - assert!(offset_of!(TSImportAttribute, value) == 36); - - assert!(size_of::() == 28); - assert!(align_of::() == 4); - assert!(size_of::() == 28); assert!(align_of::() == 4); assert!(offset_of!(TSFunctionType, span) == 0); diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index a76c81cfa1a81..c26c008ef8a99 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -10323,7 +10323,7 @@ impl<'a> AstBuilder<'a> { is_type_of: bool, ) -> TSType<'a> where - T1: IntoIn<'a, Option>>>, + T1: IntoIn<'a, Option>>>, T2: IntoIn<'a, Option>>>, { TSType::TSImportType(self.alloc_ts_import_type( @@ -13435,7 +13435,7 @@ impl<'a> AstBuilder<'a> { is_type_of: bool, ) -> TSTypeQueryExprName<'a> where - T1: IntoIn<'a, Option>>>, + T1: IntoIn<'a, Option>>>, T2: IntoIn<'a, Option>>>, { TSTypeQueryExprName::TSImportType(self.alloc_ts_import_type( @@ -13470,7 +13470,7 @@ impl<'a> AstBuilder<'a> { is_type_of: bool, ) -> TSImportType<'a> where - T1: IntoIn<'a, Option>>>, + T1: IntoIn<'a, Option>>>, T2: IntoIn<'a, Option>>>, { TSImportType { @@ -13505,7 +13505,7 @@ impl<'a> AstBuilder<'a> { is_type_of: bool, ) -> Box<'a, TSImportType<'a>> where - T1: IntoIn<'a, Option>>>, + T1: IntoIn<'a, Option>>>, T2: IntoIn<'a, Option>>>, { Box::new_in( @@ -13514,114 +13514,6 @@ impl<'a> AstBuilder<'a> { ) } - /// Build a [`TSImportAttributes`]. - /// - /// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_ts_import_attributes`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `attributes_keyword` - /// * `elements` - #[inline] - pub fn ts_import_attributes( - self, - span: Span, - attributes_keyword: IdentifierName<'a>, - elements: Vec<'a, TSImportAttribute<'a>>, - ) -> TSImportAttributes<'a> { - TSImportAttributes { span, attributes_keyword, elements } - } - - /// Build a [`TSImportAttributes`], 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_attributes`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `attributes_keyword` - /// * `elements` - #[inline] - pub fn alloc_ts_import_attributes( - self, - span: Span, - attributes_keyword: IdentifierName<'a>, - elements: Vec<'a, TSImportAttribute<'a>>, - ) -> Box<'a, TSImportAttributes<'a>> { - Box::new_in(self.ts_import_attributes(span, attributes_keyword, elements), self.allocator) - } - - /// Build a [`TSImportAttribute`]. - /// - /// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_ts_import_attribute`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `name` - /// * `value` - #[inline] - pub fn ts_import_attribute( - self, - span: Span, - name: TSImportAttributeName<'a>, - value: Expression<'a>, - ) -> TSImportAttribute<'a> { - TSImportAttribute { span, name, value } - } - - /// Build a [`TSImportAttribute`], 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_attribute`] instead. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `name` - /// * `value` - #[inline] - pub fn alloc_ts_import_attribute( - self, - span: Span, - name: TSImportAttributeName<'a>, - value: Expression<'a>, - ) -> Box<'a, TSImportAttribute<'a>> { - Box::new_in(self.ts_import_attribute(span, name, value), self.allocator) - } - - /// Build a [`TSImportAttributeName::Identifier`]. - /// - /// ## Parameters - /// * `span`: The [`Span`] covering this node - /// * `name` - #[inline] - pub fn ts_import_attribute_name_identifier( - self, - span: Span, - name: A, - ) -> TSImportAttributeName<'a> - where - A: IntoIn<'a, Atom<'a>>, - { - TSImportAttributeName::Identifier(self.identifier_name(span, name)) - } - - /// Build a [`TSImportAttributeName::StringLiteral`]. - /// - /// ## Parameters - /// * `span`: Node location in source code - /// * `value`: The value of the string. - /// * `raw`: The raw string as it appears in source code. - #[inline] - pub fn ts_import_attribute_name_string_literal( - self, - span: Span, - value: A, - raw: Option>, - ) -> TSImportAttributeName<'a> - where - A: IntoIn<'a, Atom<'a>>, - { - TSImportAttributeName::StringLiteral(self.string_literal(span, value, raw)) - } - /// Build a [`TSFunctionType`]. /// /// If you want the built node to be allocated in the memory arena, use [`AstBuilder::alloc_ts_function_type`] instead. diff --git a/crates/oxc_ast/src/generated/derive_clone_in.rs b/crates/oxc_ast/src/generated/derive_clone_in.rs index 5122522eaf021..6c77cbcb942e8 100644 --- a/crates/oxc_ast/src/generated/derive_clone_in.rs +++ b/crates/oxc_ast/src/generated/derive_clone_in.rs @@ -3859,42 +3859,6 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSImportType<'_> { } } -impl<'new_alloc> CloneIn<'new_alloc> for TSImportAttributes<'_> { - type Cloned = TSImportAttributes<'new_alloc>; - fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { - TSImportAttributes { - span: CloneIn::clone_in(&self.span, allocator), - attributes_keyword: CloneIn::clone_in(&self.attributes_keyword, allocator), - elements: CloneIn::clone_in(&self.elements, allocator), - } - } -} - -impl<'new_alloc> CloneIn<'new_alloc> for TSImportAttribute<'_> { - type Cloned = TSImportAttribute<'new_alloc>; - fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { - TSImportAttribute { - span: CloneIn::clone_in(&self.span, allocator), - name: CloneIn::clone_in(&self.name, allocator), - value: CloneIn::clone_in(&self.value, allocator), - } - } -} - -impl<'new_alloc> CloneIn<'new_alloc> for TSImportAttributeName<'_> { - type Cloned = TSImportAttributeName<'new_alloc>; - fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { - match self { - Self::Identifier(it) => { - TSImportAttributeName::Identifier(CloneIn::clone_in(it, allocator)) - } - Self::StringLiteral(it) => { - TSImportAttributeName::StringLiteral(CloneIn::clone_in(it, allocator)) - } - } - } -} - impl<'new_alloc> CloneIn<'new_alloc> for TSFunctionType<'_> { type Cloned = TSFunctionType<'new_alloc>; fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { diff --git a/crates/oxc_ast/src/generated/derive_content_eq.rs b/crates/oxc_ast/src/generated/derive_content_eq.rs index f0ca45f9b7cec..8296b11df136d 100644 --- a/crates/oxc_ast/src/generated/derive_content_eq.rs +++ b/crates/oxc_ast/src/generated/derive_content_eq.rs @@ -2305,30 +2305,6 @@ impl ContentEq for TSImportType<'_> { } } -impl ContentEq for TSImportAttributes<'_> { - fn content_eq(&self, other: &Self) -> bool { - ContentEq::content_eq(&self.attributes_keyword, &other.attributes_keyword) - && ContentEq::content_eq(&self.elements, &other.elements) - } -} - -impl ContentEq for TSImportAttribute<'_> { - fn content_eq(&self, other: &Self) -> bool { - ContentEq::content_eq(&self.name, &other.name) - && ContentEq::content_eq(&self.value, &other.value) - } -} - -impl ContentEq for TSImportAttributeName<'_> { - fn content_eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Identifier(a), Self::Identifier(b)) => a.content_eq(b), - (Self::StringLiteral(a), Self::StringLiteral(b)) => a.content_eq(b), - _ => false, - } - } -} - impl ContentEq for TSFunctionType<'_> { fn content_eq(&self, other: &Self) -> bool { ContentEq::content_eq(&self.type_parameters, &other.type_parameters) diff --git a/crates/oxc_ast/src/generated/derive_estree.rs b/crates/oxc_ast/src/generated/derive_estree.rs index a65d41cfdc83b..3e87ad68b2c43 100644 --- a/crates/oxc_ast/src/generated/derive_estree.rs +++ b/crates/oxc_ast/src/generated/derive_estree.rs @@ -3111,39 +3111,6 @@ impl ESTree for TSImportType<'_> { } } -impl ESTree for TSImportAttributes<'_> { - fn serialize(&self, serializer: S) { - let mut state = serializer.serialize_struct(); - state.serialize_field("type", &JsonSafeString("TSImportAttributes")); - state.serialize_field("start", &self.span.start); - state.serialize_field("end", &self.span.end); - state.serialize_field("attributesKeyword", &self.attributes_keyword); - state.serialize_field("elements", &self.elements); - state.end(); - } -} - -impl ESTree for TSImportAttribute<'_> { - fn serialize(&self, serializer: S) { - let mut state = serializer.serialize_struct(); - state.serialize_field("type", &JsonSafeString("TSImportAttribute")); - state.serialize_field("start", &self.span.start); - state.serialize_field("end", &self.span.end); - state.serialize_field("name", &self.name); - state.serialize_field("value", &self.value); - state.end(); - } -} - -impl ESTree for TSImportAttributeName<'_> { - fn serialize(&self, serializer: S) { - match self { - Self::Identifier(it) => it.serialize(serializer), - Self::StringLiteral(it) => it.serialize(serializer), - } - } -} - impl ESTree for TSFunctionType<'_> { fn serialize(&self, serializer: S) { let mut state = serializer.serialize_struct(); diff --git a/crates/oxc_ast/src/generated/derive_get_span.rs b/crates/oxc_ast/src/generated/derive_get_span.rs index 3a6b2eb0d1a74..d183aadebceff 100644 --- a/crates/oxc_ast/src/generated/derive_get_span.rs +++ b/crates/oxc_ast/src/generated/derive_get_span.rs @@ -2015,29 +2015,6 @@ impl GetSpan for TSImportType<'_> { } } -impl GetSpan for TSImportAttributes<'_> { - #[inline] - fn span(&self) -> Span { - self.span - } -} - -impl GetSpan for TSImportAttribute<'_> { - #[inline] - fn span(&self) -> Span { - self.span - } -} - -impl GetSpan for TSImportAttributeName<'_> { - fn span(&self) -> Span { - match self { - Self::Identifier(it) => GetSpan::span(it), - Self::StringLiteral(it) => GetSpan::span(it), - } - } -} - impl GetSpan for TSFunctionType<'_> { #[inline] fn span(&self) -> Span { diff --git a/crates/oxc_ast/src/generated/derive_get_span_mut.rs b/crates/oxc_ast/src/generated/derive_get_span_mut.rs index adad9c171e77f..e9181bbd21218 100644 --- a/crates/oxc_ast/src/generated/derive_get_span_mut.rs +++ b/crates/oxc_ast/src/generated/derive_get_span_mut.rs @@ -2015,29 +2015,6 @@ impl GetSpanMut for TSImportType<'_> { } } -impl GetSpanMut for TSImportAttributes<'_> { - #[inline] - fn span_mut(&mut self) -> &mut Span { - &mut self.span - } -} - -impl GetSpanMut for TSImportAttribute<'_> { - #[inline] - fn span_mut(&mut self) -> &mut Span { - &mut self.span - } -} - -impl GetSpanMut for TSImportAttributeName<'_> { - fn span_mut(&mut self) -> &mut Span { - match self { - Self::Identifier(it) => GetSpanMut::span_mut(it), - Self::StringLiteral(it) => GetSpanMut::span_mut(it), - } - } -} - impl GetSpanMut for TSFunctionType<'_> { #[inline] fn span_mut(&mut self) -> &mut Span { diff --git a/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs b/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs index 16e192535362a..a911a9bb7e88e 100644 --- a/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs +++ b/crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs @@ -983,18 +983,6 @@ impl<'a> VisitMut<'a> for Utf8ToUtf16Converter<'_> { self.convert_offset(&mut it.span.end); } - fn visit_ts_import_attributes(&mut self, it: &mut TSImportAttributes<'a>) { - self.convert_offset(&mut it.span.start); - walk_mut::walk_ts_import_attributes(self, it); - self.convert_offset(&mut it.span.end); - } - - fn visit_ts_import_attribute(&mut self, it: &mut TSImportAttribute<'a>) { - self.convert_offset(&mut it.span.start); - walk_mut::walk_ts_import_attribute(self, it); - self.convert_offset(&mut it.span.end); - } - fn visit_ts_function_type(&mut self, it: &mut TSFunctionType<'a>) { self.convert_offset(&mut it.span.start); walk_mut::walk_ts_function_type(self, it); diff --git a/crates/oxc_ast_visit/src/generated/visit.rs b/crates/oxc_ast_visit/src/generated/visit.rs index de6b7c0942aed..dec6eaa7a7888 100644 --- a/crates/oxc_ast_visit/src/generated/visit.rs +++ b/crates/oxc_ast_visit/src/generated/visit.rs @@ -1088,21 +1088,6 @@ pub trait Visit<'a>: Sized { walk_ts_import_type(self, it); } - #[inline] - fn visit_ts_import_attributes(&mut self, it: &TSImportAttributes<'a>) { - walk_ts_import_attributes(self, it); - } - - #[inline] - fn visit_ts_import_attribute(&mut self, it: &TSImportAttribute<'a>) { - walk_ts_import_attribute(self, it); - } - - #[inline] - fn visit_ts_import_attribute_name(&mut self, it: &TSImportAttributeName<'a>) { - walk_ts_import_attribute_name(self, it); - } - #[inline] fn visit_ts_function_type(&mut self, it: &TSFunctionType<'a>) { walk_ts_function_type(self, it); @@ -1336,11 +1321,6 @@ pub trait Visit<'a>: Sized { walk_ts_index_signature_names(self, it); } - #[inline] - fn visit_ts_import_attribute_list(&mut self, it: &Vec<'a, TSImportAttribute<'a>>) { - walk_ts_import_attribute_list(self, it); - } - #[inline] fn visit_spans(&mut self, it: &Vec<'a, Span>) { walk_spans(self, it); @@ -3911,7 +3891,7 @@ pub mod walk { visitor.visit_span(&it.span); visitor.visit_ts_type(&it.argument); if let Some(options) = &it.options { - visitor.visit_ts_import_attributes(options); + visitor.visit_object_expression(options); } if let Some(qualifier) = &it.qualifier { visitor.visit_ts_type_name(qualifier); @@ -3922,37 +3902,6 @@ pub mod walk { visitor.leave_node(kind); } - #[inline] - pub fn walk_ts_import_attributes<'a, V: Visit<'a>>( - visitor: &mut V, - it: &TSImportAttributes<'a>, - ) { - // No `AstKind` for this type - visitor.visit_span(&it.span); - visitor.visit_identifier_name(&it.attributes_keyword); - visitor.visit_ts_import_attribute_list(&it.elements); - } - - #[inline] - pub fn walk_ts_import_attribute<'a, V: Visit<'a>>(visitor: &mut V, it: &TSImportAttribute<'a>) { - // No `AstKind` for this type - visitor.visit_span(&it.span); - visitor.visit_ts_import_attribute_name(&it.name); - visitor.visit_expression(&it.value); - } - - #[inline] - pub fn walk_ts_import_attribute_name<'a, V: Visit<'a>>( - visitor: &mut V, - it: &TSImportAttributeName<'a>, - ) { - // No `AstKind` for this type - match it { - TSImportAttributeName::Identifier(it) => visitor.visit_identifier_name(it), - TSImportAttributeName::StringLiteral(it) => visitor.visit_string_literal(it), - } - } - #[inline] pub fn walk_ts_function_type<'a, V: Visit<'a>>(visitor: &mut V, it: &TSFunctionType<'a>) { // No `AstKind` for this type @@ -4407,16 +4356,6 @@ pub mod walk { } } - #[inline] - pub fn walk_ts_import_attribute_list<'a, V: Visit<'a>>( - visitor: &mut V, - it: &Vec<'a, TSImportAttribute<'a>>, - ) { - for el in it { - visitor.visit_ts_import_attribute(el); - } - } - #[inline] pub fn walk_spans<'a, V: Visit<'a>>(visitor: &mut V, it: &Vec<'a, Span>) { for el in it { diff --git a/crates/oxc_ast_visit/src/generated/visit_mut.rs b/crates/oxc_ast_visit/src/generated/visit_mut.rs index 09dc6f1ededac..c9c1bd59e66d8 100644 --- a/crates/oxc_ast_visit/src/generated/visit_mut.rs +++ b/crates/oxc_ast_visit/src/generated/visit_mut.rs @@ -1080,21 +1080,6 @@ pub trait VisitMut<'a>: Sized { walk_ts_import_type(self, it); } - #[inline] - fn visit_ts_import_attributes(&mut self, it: &mut TSImportAttributes<'a>) { - walk_ts_import_attributes(self, it); - } - - #[inline] - fn visit_ts_import_attribute(&mut self, it: &mut TSImportAttribute<'a>) { - walk_ts_import_attribute(self, it); - } - - #[inline] - fn visit_ts_import_attribute_name(&mut self, it: &mut TSImportAttributeName<'a>) { - walk_ts_import_attribute_name(self, it); - } - #[inline] fn visit_ts_function_type(&mut self, it: &mut TSFunctionType<'a>) { walk_ts_function_type(self, it); @@ -1331,11 +1316,6 @@ pub trait VisitMut<'a>: Sized { walk_ts_index_signature_names(self, it); } - #[inline] - fn visit_ts_import_attribute_list(&mut self, it: &mut Vec<'a, TSImportAttribute<'a>>) { - walk_ts_import_attribute_list(self, it); - } - #[inline] fn visit_spans(&mut self, it: &mut Vec<'a, Span>) { walk_spans(self, it); @@ -4120,7 +4100,7 @@ pub mod walk_mut { visitor.visit_span(&mut it.span); visitor.visit_ts_type(&mut it.argument); if let Some(options) = &mut it.options { - visitor.visit_ts_import_attributes(options); + visitor.visit_object_expression(options); } if let Some(qualifier) = &mut it.qualifier { visitor.visit_ts_type_name(qualifier); @@ -4131,40 +4111,6 @@ pub mod walk_mut { visitor.leave_node(kind); } - #[inline] - pub fn walk_ts_import_attributes<'a, V: VisitMut<'a>>( - visitor: &mut V, - it: &mut TSImportAttributes<'a>, - ) { - // No `AstType` for this type - visitor.visit_span(&mut it.span); - visitor.visit_identifier_name(&mut it.attributes_keyword); - visitor.visit_ts_import_attribute_list(&mut it.elements); - } - - #[inline] - pub fn walk_ts_import_attribute<'a, V: VisitMut<'a>>( - visitor: &mut V, - it: &mut TSImportAttribute<'a>, - ) { - // No `AstType` for this type - visitor.visit_span(&mut it.span); - visitor.visit_ts_import_attribute_name(&mut it.name); - visitor.visit_expression(&mut it.value); - } - - #[inline] - pub fn walk_ts_import_attribute_name<'a, V: VisitMut<'a>>( - visitor: &mut V, - it: &mut TSImportAttributeName<'a>, - ) { - // No `AstType` for this type - match it { - TSImportAttributeName::Identifier(it) => visitor.visit_identifier_name(it), - TSImportAttributeName::StringLiteral(it) => visitor.visit_string_literal(it), - } - } - #[inline] pub fn walk_ts_function_type<'a, V: VisitMut<'a>>( visitor: &mut V, @@ -4652,16 +4598,6 @@ pub mod walk_mut { } } - #[inline] - pub fn walk_ts_import_attribute_list<'a, V: VisitMut<'a>>( - visitor: &mut V, - it: &mut Vec<'a, TSImportAttribute<'a>>, - ) { - for el in it { - visitor.visit_ts_import_attribute(el); - } - } - #[inline] pub fn walk_spans<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Vec<'a, Span>) { for el in it { diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 7f5b295f43bfd..67b2daf90276b 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -3552,9 +3552,9 @@ impl Gen for TSImportType<'_> { } p.print_str("import("); self.argument.print(p, ctx); - if let Some(attributes) = &self.options { + if let Some(options) = &self.options { p.print_str(", "); - attributes.print(p, ctx); + options.print_expr(p, Precedence::Lowest, ctx); } p.print_str(")"); if let Some(qualifier) = &self.qualifier { @@ -3567,42 +3567,6 @@ impl Gen for TSImportType<'_> { } } -impl Gen for TSImportAttributes<'_> { - fn r#gen(&self, p: &mut Codegen, ctx: Context) { - p.print_ascii_byte(b'{'); - p.print_soft_space(); - self.attributes_keyword.print(p, ctx); - p.print_str(":"); - p.print_soft_space(); - p.print_ascii_byte(b'{'); - p.print_soft_space(); - p.print_list(&self.elements, ctx); - p.print_soft_space(); - p.print_ascii_byte(b'}'); - p.print_soft_space(); - p.print_ascii_byte(b'}'); - } -} - -impl Gen for TSImportAttribute<'_> { - fn r#gen(&self, p: &mut Codegen, ctx: Context) { - self.name.print(p, ctx); - p.print_str(": "); - self.value.print_expr(p, Precedence::Member, ctx); - } -} - -impl Gen for TSImportAttributeName<'_> { - fn r#gen(&self, p: &mut Codegen, ctx: Context) { - match self { - TSImportAttributeName::Identifier(ident) => ident.print(p, ctx), - TSImportAttributeName::StringLiteral(literal) => { - p.print_string_literal(literal, false); - } - } - } -} - impl Gen for TSTypeParameterInstantiation<'_> { fn r#gen(&self, p: &mut Codegen, ctx: Context) { p.print_str("<"); diff --git a/crates/oxc_parser/src/js/expression.rs b/crates/oxc_parser/src/js/expression.rs index 61a1e1794b544..52d5c400dacce 100644 --- a/crates/oxc_parser/src/js/expression.rs +++ b/crates/oxc_parser/src/js/expression.rs @@ -172,7 +172,7 @@ impl<'a> ParserImpl<'a> { // ArrayLiteral Kind::LBrack => self.parse_array_expression(), // ObjectLiteral - Kind::LCurly => self.parse_object_expression(), + Kind::LCurly => self.parse_object_expression().map(Expression::ObjectExpression), // ClassExpression Kind::Class => self.parse_class_expression(), // This diff --git a/crates/oxc_parser/src/js/object.rs b/crates/oxc_parser/src/js/object.rs index 13219f5ae6813..1b6bc221887cd 100644 --- a/crates/oxc_parser/src/js/object.rs +++ b/crates/oxc_parser/src/js/object.rs @@ -12,7 +12,7 @@ impl<'a> ParserImpl<'a> { /// { } /// { `PropertyDefinitionList`[?Yield, ?Await] } /// { `PropertyDefinitionList`[?Yield, ?Await] , } - pub(crate) fn parse_object_expression(&mut self) -> Result> { + pub(crate) fn parse_object_expression(&mut self) -> Result>> { let span = self.start_span(); self.expect(Kind::LCurly)?; let object_expression_properties = self.context(Context::In, Context::empty(), |p| { @@ -29,7 +29,7 @@ impl<'a> ParserImpl<'a> { self.end_span(span) }); self.expect(Kind::RCurly)?; - Ok(self.ast.expression_object( + Ok(self.ast.alloc_object_expression( self.end_span(span), object_expression_properties, trailing_comma, diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index 99eba60233fee..2a27da705a058 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -982,7 +982,7 @@ impl<'a> ParserImpl<'a> { self.expect(Kind::LParen)?; let argument = self.parse_ts_type()?; let options = - if self.eat(Kind::Comma) { Some(self.parse_ts_import_attributes()?) } else { None }; + if self.eat(Kind::Comma) { Some(self.parse_object_expression()?) } else { None }; self.expect(Kind::RParen)?; let qualifier = if self.eat(Kind::Dot) { Some(self.parse_ts_type_name()?) } else { None }; let type_arguments = self.parse_type_arguments_of_type_reference()?; @@ -996,41 +996,6 @@ impl<'a> ParserImpl<'a> { )) } - fn parse_ts_import_attributes(&mut self) -> Result> { - let span = self.start_span(); - self.expect(Kind::LCurly)?; - let attributes_keyword = match self.cur_kind() { - Kind::Assert if !self.cur_token().is_on_new_line => self.parse_identifier_name()?, - Kind::With => self.parse_identifier_name()?, - _ => { - return Err(self.unexpected()); - } - }; - self.expect(Kind::Colon)?; - self.expect(Kind::LCurly)?; - let elements = self.parse_delimited_list( - Kind::RCurly, - Kind::Comma, - /* trailing_separator */ true, - Self::parse_ts_import_attribute, - )?; - self.expect(Kind::RCurly)?; - self.expect(Kind::RCurly)?; - Ok(self.ast.ts_import_attributes(self.end_span(span), attributes_keyword, elements)) - } - - fn parse_ts_import_attribute(&mut self) -> Result> { - let span = self.start_span(); - let name = match self.cur_kind() { - Kind::Str => TSImportAttributeName::StringLiteral(self.parse_literal_string()?), - _ => TSImportAttributeName::Identifier(self.parse_identifier_name()?), - }; - - self.expect(Kind::Colon)?; - let value = self.parse_expr()?; - Ok(self.ast.ts_import_attribute(self.end_span(span), name, value)) - } - fn try_parse_constraint_of_infer_type(&mut self) -> Result>> { if self.eat(Kind::Extends) { let constraint = self.context( diff --git a/crates/oxc_traverse/src/generated/ancestor.rs b/crates/oxc_traverse/src/generated/ancestor.rs index 142f0669a8745..0966b56a3fa5b 100644 --- a/crates/oxc_traverse/src/generated/ancestor.rs +++ b/crates/oxc_traverse/src/generated/ancestor.rs @@ -285,39 +285,35 @@ pub(crate) enum AncestorType { TSImportTypeOptions = 262, TSImportTypeQualifier = 263, TSImportTypeTypeArguments = 264, - TSImportAttributesAttributesKeyword = 265, - TSImportAttributesElements = 266, - TSImportAttributeName = 267, - TSImportAttributeValue = 268, - TSFunctionTypeTypeParameters = 269, - TSFunctionTypeThisParam = 270, - TSFunctionTypeParams = 271, - TSFunctionTypeReturnType = 272, - TSConstructorTypeTypeParameters = 273, - TSConstructorTypeParams = 274, - TSConstructorTypeReturnType = 275, - TSMappedTypeTypeParameter = 276, - TSMappedTypeNameType = 277, - TSMappedTypeTypeAnnotation = 278, - TSTemplateLiteralTypeQuasis = 279, - TSTemplateLiteralTypeTypes = 280, - TSAsExpressionExpression = 281, - TSAsExpressionTypeAnnotation = 282, - TSSatisfiesExpressionExpression = 283, - TSSatisfiesExpressionTypeAnnotation = 284, - TSTypeAssertionExpression = 285, - TSTypeAssertionTypeAnnotation = 286, - TSImportEqualsDeclarationId = 287, - TSImportEqualsDeclarationModuleReference = 288, - TSExternalModuleReferenceExpression = 289, - TSNonNullExpressionExpression = 290, - DecoratorExpression = 291, - TSExportAssignmentExpression = 292, - TSNamespaceExportDeclarationId = 293, - TSInstantiationExpressionExpression = 294, - TSInstantiationExpressionTypeParameters = 295, - JSDocNullableTypeTypeAnnotation = 296, - JSDocNonNullableTypeTypeAnnotation = 297, + TSFunctionTypeTypeParameters = 265, + TSFunctionTypeThisParam = 266, + TSFunctionTypeParams = 267, + TSFunctionTypeReturnType = 268, + TSConstructorTypeTypeParameters = 269, + TSConstructorTypeParams = 270, + TSConstructorTypeReturnType = 271, + TSMappedTypeTypeParameter = 272, + TSMappedTypeNameType = 273, + TSMappedTypeTypeAnnotation = 274, + TSTemplateLiteralTypeQuasis = 275, + TSTemplateLiteralTypeTypes = 276, + TSAsExpressionExpression = 277, + TSAsExpressionTypeAnnotation = 278, + TSSatisfiesExpressionExpression = 279, + TSSatisfiesExpressionTypeAnnotation = 280, + TSTypeAssertionExpression = 281, + TSTypeAssertionTypeAnnotation = 282, + TSImportEqualsDeclarationId = 283, + TSImportEqualsDeclarationModuleReference = 284, + TSExternalModuleReferenceExpression = 285, + TSNonNullExpressionExpression = 286, + DecoratorExpression = 287, + TSExportAssignmentExpression = 288, + TSNamespaceExportDeclarationId = 289, + TSInstantiationExpressionExpression = 290, + TSInstantiationExpressionTypeParameters = 291, + JSDocNullableTypeTypeAnnotation = 292, + JSDocNonNullableTypeTypeAnnotation = 293, } /// Ancestor type used in AST traversal. @@ -829,14 +825,6 @@ pub enum Ancestor<'a, 't> { AncestorType::TSImportTypeQualifier as u16, TSImportTypeTypeArguments(TSImportTypeWithoutTypeArguments<'a, 't>) = AncestorType::TSImportTypeTypeArguments as u16, - TSImportAttributesAttributesKeyword(TSImportAttributesWithoutAttributesKeyword<'a, 't>) = - AncestorType::TSImportAttributesAttributesKeyword as u16, - TSImportAttributesElements(TSImportAttributesWithoutElements<'a, 't>) = - AncestorType::TSImportAttributesElements as u16, - TSImportAttributeName(TSImportAttributeWithoutName<'a, 't>) = - AncestorType::TSImportAttributeName as u16, - TSImportAttributeValue(TSImportAttributeWithoutValue<'a, 't>) = - AncestorType::TSImportAttributeValue as u16, TSFunctionTypeTypeParameters(TSFunctionTypeWithoutTypeParameters<'a, 't>) = AncestorType::TSFunctionTypeTypeParameters as u16, TSFunctionTypeThisParam(TSFunctionTypeWithoutThisParam<'a, 't>) = @@ -1756,19 +1744,6 @@ impl<'a, 't> Ancestor<'a, 't> { ) } - #[inline] - pub fn is_ts_import_attributes(self) -> bool { - matches!( - self, - Self::TSImportAttributesAttributesKeyword(_) | Self::TSImportAttributesElements(_) - ) - } - - #[inline] - pub fn is_ts_import_attribute(self) -> bool { - matches!(self, Self::TSImportAttributeName(_) | Self::TSImportAttributeValue(_)) - } - #[inline] pub fn is_ts_function_type(self) -> bool { matches!( @@ -1977,7 +1952,6 @@ impl<'a, 't> Ancestor<'a, 't> { | Self::JSXSpreadChildExpression(_) | Self::TSEnumMemberInitializer(_) | Self::TSInterfaceHeritageExpression(_) - | Self::TSImportAttributeValue(_) | Self::TSAsExpressionExpression(_) | Self::TSSatisfiesExpressionExpression(_) | Self::TSTypeAssertionExpression(_) @@ -2204,11 +2178,6 @@ impl<'a, 't> Ancestor<'a, 't> { matches!(self, Self::TSTypeQueryExprName(_)) } - #[inline] - pub fn is_parent_of_ts_import_attribute_name(self) -> bool { - matches!(self, Self::TSImportAttributeName(_)) - } - #[inline] pub fn is_parent_of_ts_module_reference(self) -> bool { matches!(self, Self::TSImportEqualsDeclarationModuleReference(_)) @@ -2486,10 +2455,6 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> { Self::TSImportTypeOptions(a) => a.address(), Self::TSImportTypeQualifier(a) => a.address(), Self::TSImportTypeTypeArguments(a) => a.address(), - Self::TSImportAttributesAttributesKeyword(a) => a.address(), - Self::TSImportAttributesElements(a) => a.address(), - Self::TSImportAttributeName(a) => a.address(), - Self::TSImportAttributeValue(a) => a.address(), Self::TSFunctionTypeTypeParameters(a) => a.address(), Self::TSFunctionTypeThisParam(a) => a.address(), Self::TSFunctionTypeParams(a) => a.address(), @@ -14266,10 +14231,10 @@ impl<'a, 't> TSImportTypeWithoutArgument<'a, 't> { } #[inline] - pub fn options(self) -> &'t Option>> { + pub fn options(self) -> &'t Option>> { unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_OPTIONS) - as *const Option>>) + as *const Option>>) } } @@ -14372,10 +14337,10 @@ impl<'a, 't> TSImportTypeWithoutQualifier<'a, 't> { } #[inline] - pub fn options(self) -> &'t Option>> { + pub fn options(self) -> &'t Option>> { unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_OPTIONS) - as *const Option>>) + as *const Option>>) } } @@ -14421,10 +14386,10 @@ impl<'a, 't> TSImportTypeWithoutTypeArguments<'a, 't> { } #[inline] - pub fn options(self) -> &'t Option>> { + pub fn options(self) -> &'t Option>> { unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_OPTIONS) - as *const Option>>) + as *const Option>>) } } @@ -14449,131 +14414,6 @@ impl<'a, 't> GetAddress for TSImportTypeWithoutTypeArguments<'a, 't> { } } -pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTES_SPAN: usize = offset_of!(TSImportAttributes, span); -pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTES_ATTRIBUTES_KEYWORD: usize = - offset_of!(TSImportAttributes, attributes_keyword); -pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTES_ELEMENTS: usize = - offset_of!(TSImportAttributes, elements); - -#[repr(transparent)] -#[derive(Clone, Copy, Debug)] -pub struct TSImportAttributesWithoutAttributesKeyword<'a, 't>( - pub(crate) *const TSImportAttributes<'a>, - pub(crate) PhantomData<&'t ()>, -); - -impl<'a, 't> TSImportAttributesWithoutAttributesKeyword<'a, 't> { - #[inline] - pub fn span(self) -> &'t Span { - unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_SPAN) as *const Span) } - } - - #[inline] - pub fn elements(self) -> &'t Vec<'a, TSImportAttribute<'a>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_ELEMENTS) - as *const Vec<'a, TSImportAttribute<'a>>) - } - } -} - -impl<'a, 't> GetAddress for TSImportAttributesWithoutAttributesKeyword<'a, 't> { - #[inline] - fn address(&self) -> Address { - Address::from_ptr(self.0) - } -} - -#[repr(transparent)] -#[derive(Clone, Copy, Debug)] -pub struct TSImportAttributesWithoutElements<'a, 't>( - pub(crate) *const TSImportAttributes<'a>, - pub(crate) PhantomData<&'t ()>, -); - -impl<'a, 't> TSImportAttributesWithoutElements<'a, 't> { - #[inline] - pub fn span(self) -> &'t Span { - unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_SPAN) as *const Span) } - } - - #[inline] - pub fn attributes_keyword(self) -> &'t IdentifierName<'a> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTES_ATTRIBUTES_KEYWORD) - as *const IdentifierName<'a>) - } - } -} - -impl<'a, 't> GetAddress for TSImportAttributesWithoutElements<'a, 't> { - #[inline] - fn address(&self) -> Address { - Address::from_ptr(self.0) - } -} - -pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTE_SPAN: usize = offset_of!(TSImportAttribute, span); -pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTE_NAME: usize = offset_of!(TSImportAttribute, name); -pub(crate) const OFFSET_TS_IMPORT_ATTRIBUTE_VALUE: usize = offset_of!(TSImportAttribute, value); - -#[repr(transparent)] -#[derive(Clone, Copy, Debug)] -pub struct TSImportAttributeWithoutName<'a, 't>( - pub(crate) *const TSImportAttribute<'a>, - pub(crate) PhantomData<&'t ()>, -); - -impl<'a, 't> TSImportAttributeWithoutName<'a, 't> { - #[inline] - pub fn span(self) -> &'t Span { - unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_SPAN) as *const Span) } - } - - #[inline] - pub fn value(self) -> &'t Expression<'a> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_VALUE) as *const Expression<'a>) - } - } -} - -impl<'a, 't> GetAddress for TSImportAttributeWithoutName<'a, 't> { - #[inline] - fn address(&self) -> Address { - Address::from_ptr(self.0) - } -} - -#[repr(transparent)] -#[derive(Clone, Copy, Debug)] -pub struct TSImportAttributeWithoutValue<'a, 't>( - pub(crate) *const TSImportAttribute<'a>, - pub(crate) PhantomData<&'t ()>, -); - -impl<'a, 't> TSImportAttributeWithoutValue<'a, 't> { - #[inline] - pub fn span(self) -> &'t Span { - unsafe { &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_SPAN) as *const Span) } - } - - #[inline] - pub fn name(self) -> &'t TSImportAttributeName<'a> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_IMPORT_ATTRIBUTE_NAME) - as *const TSImportAttributeName<'a>) - } - } -} - -impl<'a, 't> GetAddress for TSImportAttributeWithoutValue<'a, 't> { - #[inline] - fn address(&self) -> Address { - Address::from_ptr(self.0) - } -} - pub(crate) const OFFSET_TS_FUNCTION_TYPE_SPAN: usize = offset_of!(TSFunctionType, span); pub(crate) const OFFSET_TS_FUNCTION_TYPE_TYPE_PARAMETERS: usize = offset_of!(TSFunctionType, type_parameters); diff --git a/crates/oxc_traverse/src/generated/traverse.rs b/crates/oxc_traverse/src/generated/traverse.rs index 09b8621060b94..ccba66bf2d491 100644 --- a/crates/oxc_traverse/src/generated/traverse.rs +++ b/crates/oxc_traverse/src/generated/traverse.rs @@ -2204,51 +2204,6 @@ pub trait Traverse<'a> { #[inline] fn exit_ts_import_type(&mut self, node: &mut TSImportType<'a>, ctx: &mut TraverseCtx<'a>) {} - #[inline] - fn enter_ts_import_attributes( - &mut self, - node: &mut TSImportAttributes<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - } - #[inline] - fn exit_ts_import_attributes( - &mut self, - node: &mut TSImportAttributes<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - } - - #[inline] - fn enter_ts_import_attribute( - &mut self, - node: &mut TSImportAttribute<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - } - #[inline] - fn exit_ts_import_attribute( - &mut self, - node: &mut TSImportAttribute<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - } - - #[inline] - fn enter_ts_import_attribute_name( - &mut self, - node: &mut TSImportAttributeName<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - } - #[inline] - fn exit_ts_import_attribute_name( - &mut self, - node: &mut TSImportAttributeName<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - } - #[inline] fn enter_ts_function_type(&mut self, node: &mut TSFunctionType<'a>, ctx: &mut TraverseCtx<'a>) { } diff --git a/crates/oxc_traverse/src/generated/walk.rs b/crates/oxc_traverse/src/generated/walk.rs index ac49286335171..598656544a3ba 100644 --- a/crates/oxc_traverse/src/generated/walk.rs +++ b/crates/oxc_traverse/src/generated/walk.rs @@ -5130,10 +5130,10 @@ unsafe fn walk_ts_import_type<'a, Tr: Traverse<'a>>( ctx, ); if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_TYPE_OPTIONS) - as *mut Option>) + as *mut Option>) { ctx.retag_stack(AncestorType::TSImportTypeOptions); - walk_ts_import_attributes(traverser, (&mut **field) as *mut _, ctx); + walk_object_expression(traverser, (&mut **field) as *mut _, ctx); } if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_TYPE_QUALIFIER) as *mut Option) @@ -5152,73 +5152,6 @@ unsafe fn walk_ts_import_type<'a, Tr: Traverse<'a>>( traverser.exit_ts_import_type(&mut *node, ctx); } -unsafe fn walk_ts_import_attributes<'a, Tr: Traverse<'a>>( - traverser: &mut Tr, - node: *mut TSImportAttributes<'a>, - ctx: &mut TraverseCtx<'a>, -) { - traverser.enter_ts_import_attributes(&mut *node, ctx); - let pop_token = ctx.push_stack(Ancestor::TSImportAttributesAttributesKeyword( - ancestor::TSImportAttributesWithoutAttributesKeyword(node, PhantomData), - )); - walk_identifier_name( - traverser, - (node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTES_ATTRIBUTES_KEYWORD) - as *mut IdentifierName, - ctx, - ); - ctx.retag_stack(AncestorType::TSImportAttributesElements); - for item in &mut *((node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTES_ELEMENTS) - as *mut Vec) - { - walk_ts_import_attribute(traverser, item as *mut _, ctx); - } - ctx.pop_stack(pop_token); - traverser.exit_ts_import_attributes(&mut *node, ctx); -} - -unsafe fn walk_ts_import_attribute<'a, Tr: Traverse<'a>>( - traverser: &mut Tr, - node: *mut TSImportAttribute<'a>, - ctx: &mut TraverseCtx<'a>, -) { - traverser.enter_ts_import_attribute(&mut *node, ctx); - let pop_token = ctx.push_stack(Ancestor::TSImportAttributeName( - ancestor::TSImportAttributeWithoutName(node, PhantomData), - )); - walk_ts_import_attribute_name( - traverser, - (node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTE_NAME) - as *mut TSImportAttributeName, - ctx, - ); - ctx.retag_stack(AncestorType::TSImportAttributeValue); - walk_expression( - traverser, - (node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_ATTRIBUTE_VALUE) as *mut Expression, - ctx, - ); - ctx.pop_stack(pop_token); - traverser.exit_ts_import_attribute(&mut *node, ctx); -} - -unsafe fn walk_ts_import_attribute_name<'a, Tr: Traverse<'a>>( - traverser: &mut Tr, - node: *mut TSImportAttributeName<'a>, - ctx: &mut TraverseCtx<'a>, -) { - traverser.enter_ts_import_attribute_name(&mut *node, ctx); - match &mut *node { - TSImportAttributeName::Identifier(node) => { - walk_identifier_name(traverser, node as *mut _, ctx) - } - TSImportAttributeName::StringLiteral(node) => { - walk_string_literal(traverser, node as *mut _, ctx) - } - } - traverser.exit_ts_import_attribute_name(&mut *node, ctx); -} - unsafe fn walk_ts_function_type<'a, Tr: Traverse<'a>>( traverser: &mut Tr, node: *mut TSFunctionType<'a>, diff --git a/napi/parser/deserialize-js.js b/napi/parser/deserialize-js.js index 3f0e8d68ae940..cad4a76f40c29 100644 --- a/napi/parser/deserialize-js.js +++ b/napi/parser/deserialize-js.js @@ -1775,33 +1775,13 @@ function deserializeTSImportType(pos) { start: deserializeU32(pos), end: deserializeU32(pos + 4), argument: deserializeTSType(pos + 8), - options: deserializeOptionBoxTSImportAttributes(pos + 24), + options: deserializeOptionBoxObjectExpression(pos + 24), qualifier: deserializeOptionTSTypeName(pos + 32), typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48), isTypeOf: deserializeBool(pos + 56), }; } -function deserializeTSImportAttributes(pos) { - return { - type: 'TSImportAttributes', - start: deserializeU32(pos), - end: deserializeU32(pos + 4), - attributesKeyword: deserializeIdentifierName(pos + 8), - elements: deserializeVecTSImportAttribute(pos + 32), - }; -} - -function deserializeTSImportAttribute(pos) { - return { - type: 'TSImportAttribute', - start: deserializeU32(pos), - end: deserializeU32(pos + 4), - name: deserializeTSImportAttributeName(pos + 8), - value: deserializeExpression(pos + 56), - }; -} - function deserializeTSFunctionType(pos) { return { type: 'TSFunctionType', @@ -3860,17 +3840,6 @@ function deserializeTSTypeQueryExprName(pos) { } } -function deserializeTSImportAttributeName(pos) { - switch (uint8[pos]) { - case 0: - return deserializeIdentifierName(pos + 8); - case 1: - return deserializeStringLiteral(pos + 8); - default: - throw new Error(`Unexpected discriminant ${uint8[pos]} for TSImportAttributeName`); - } -} - function deserializeTSMappedTypeModifierOperator(pos) { switch (uint8[pos]) { case 0: @@ -5516,13 +5485,9 @@ function deserializeBoxTSTypeParameter(pos) { return deserializeTSTypeParameter(uint32[pos >> 2]); } -function deserializeBoxTSImportAttributes(pos) { - return deserializeTSImportAttributes(uint32[pos >> 2]); -} - -function deserializeOptionBoxTSImportAttributes(pos) { +function deserializeOptionBoxObjectExpression(pos) { if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null; - return deserializeBoxTSImportAttributes(pos); + return deserializeBoxObjectExpression(pos); } function deserializeOptionTSTypeName(pos) { @@ -5530,18 +5495,6 @@ function deserializeOptionTSTypeName(pos) { return deserializeTSTypeName(pos); } -function deserializeVecTSImportAttribute(pos) { - const arr = [], - pos32 = pos >> 2, - len = uint32[pos32 + 6]; - pos = uint32[pos32]; - for (let i = 0; i < len; i++) { - arr.push(deserializeTSImportAttribute(pos)); - pos += 72; - } - return arr; -} - function deserializeBoxTSExternalModuleReference(pos) { return deserializeTSExternalModuleReference(uint32[pos >> 2]); } diff --git a/napi/parser/deserialize-ts.js b/napi/parser/deserialize-ts.js index 83eb592bf0096..a967fe8920021 100644 --- a/napi/parser/deserialize-ts.js +++ b/napi/parser/deserialize-ts.js @@ -1836,33 +1836,13 @@ function deserializeTSImportType(pos) { start: deserializeU32(pos), end: deserializeU32(pos + 4), argument: deserializeTSType(pos + 8), - options: deserializeOptionBoxTSImportAttributes(pos + 24), + options: deserializeOptionBoxObjectExpression(pos + 24), qualifier: deserializeOptionTSTypeName(pos + 32), typeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 48), isTypeOf: deserializeBool(pos + 56), }; } -function deserializeTSImportAttributes(pos) { - return { - type: 'TSImportAttributes', - start: deserializeU32(pos), - end: deserializeU32(pos + 4), - attributesKeyword: deserializeIdentifierName(pos + 8), - elements: deserializeVecTSImportAttribute(pos + 32), - }; -} - -function deserializeTSImportAttribute(pos) { - return { - type: 'TSImportAttribute', - start: deserializeU32(pos), - end: deserializeU32(pos + 4), - name: deserializeTSImportAttributeName(pos + 8), - value: deserializeExpression(pos + 56), - }; -} - function deserializeTSFunctionType(pos) { return { type: 'TSFunctionType', @@ -3921,17 +3901,6 @@ function deserializeTSTypeQueryExprName(pos) { } } -function deserializeTSImportAttributeName(pos) { - switch (uint8[pos]) { - case 0: - return deserializeIdentifierName(pos + 8); - case 1: - return deserializeStringLiteral(pos + 8); - default: - throw new Error(`Unexpected discriminant ${uint8[pos]} for TSImportAttributeName`); - } -} - function deserializeTSMappedTypeModifierOperator(pos) { switch (uint8[pos]) { case 0: @@ -5577,13 +5546,9 @@ function deserializeBoxTSTypeParameter(pos) { return deserializeTSTypeParameter(uint32[pos >> 2]); } -function deserializeBoxTSImportAttributes(pos) { - return deserializeTSImportAttributes(uint32[pos >> 2]); -} - -function deserializeOptionBoxTSImportAttributes(pos) { +function deserializeOptionBoxObjectExpression(pos) { if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null; - return deserializeBoxTSImportAttributes(pos); + return deserializeBoxObjectExpression(pos); } function deserializeOptionTSTypeName(pos) { @@ -5591,18 +5556,6 @@ function deserializeOptionTSTypeName(pos) { return deserializeTSTypeName(pos); } -function deserializeVecTSImportAttribute(pos) { - const arr = [], - pos32 = pos >> 2, - len = uint32[pos32 + 6]; - pos = uint32[pos32]; - for (let i = 0; i < len; i++) { - arr.push(deserializeTSImportAttribute(pos)); - pos += 72; - } - return arr; -} - function deserializeBoxTSExternalModuleReference(pos) { return deserializeTSExternalModuleReference(uint32[pos >> 2]); } diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index 57209166b2d46..4ba8d59741364 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -1292,26 +1292,12 @@ export type TSTypeQueryExprName = TSImportType | TSTypeName; export interface TSImportType extends Span { type: 'TSImportType'; argument: TSType; - options: TSImportAttributes | null; + options: ObjectExpression | null; qualifier: TSTypeName | null; typeArguments: TSTypeParameterInstantiation | null; isTypeOf: boolean; } -export interface TSImportAttributes extends Span { - type: 'TSImportAttributes'; - attributesKeyword: IdentifierName; - elements: Array; -} - -export interface TSImportAttribute extends Span { - type: 'TSImportAttribute'; - name: TSImportAttributeName; - value: Expression; -} - -export type TSImportAttributeName = IdentifierName | StringLiteral; - export interface TSFunctionType extends Span { type: 'TSFunctionType'; typeParameters: TSTypeParameterDeclaration | null; @@ -1799,8 +1785,6 @@ export type Node = | TSInferType | TSTypeQuery | TSImportType - | TSImportAttributes - | TSImportAttribute | TSFunctionType | TSConstructorType | TSMappedType diff --git a/tasks/ast_tools/src/generators/ast_kind.rs b/tasks/ast_tools/src/generators/ast_kind.rs index 4ca6d58b09176..af774dcd4575a 100644 --- a/tasks/ast_tools/src/generators/ast_kind.rs +++ b/tasks/ast_tools/src/generators/ast_kind.rs @@ -22,7 +22,7 @@ use super::define_generator; /// Types to omit creating an `AstKind` for. /// /// Apart from this list every type with `#[ast(visit)]` attr gets an `AstKind`. -const BLACK_LIST: [&str; 64] = [ +const BLACK_LIST: [&str; 61] = [ "Span", "Expression", "ObjectPropertyKind", @@ -71,9 +71,6 @@ const BLACK_LIST: [&str; 64] = [ "TSModuleDeclarationName", "TSModuleDeclarationBody", "TSTypeQueryExprName", - "TSImportAttribute", - "TSImportAttributes", - "TSImportAttributeName", "TSFunctionType", "TSConstructorType", "TSNamespaceExportDeclaration", diff --git a/tasks/coverage/snapshots/parser_misc.snap b/tasks/coverage/snapshots/parser_misc.snap index b61f8a83f0d52..fc3c1faa0b86c 100644 --- a/tasks/coverage/snapshots/parser_misc.snap +++ b/tasks/coverage/snapshots/parser_misc.snap @@ -90,12 +90,13 @@ Negative Passed: 30/30 (100.00%) · ───────── ╰──── - × Unexpected token - ╭─[misc/fail/oxc-2394.ts:20:22] - 19 │ export type LocalInterface = - 20 │ & import("pkg", {"resolution-mode": "require"}).RequireInterface - · ───────────────── - 21 │ & import("pkg", {"resolution-mode": "import"}).ImportInterface; + × Expected `{` but found `[` + ╭─[misc/fail/oxc-2394.ts:38:21] + 37 │ export type LocalInterface = + 38 │ & import("pkg", [ {"resolution-mode": "require"} ]).RequireInterface + · ┬ + · ╰── `{` expected + 39 │ & import("pkg", [ {"resolution-mode": "import"} ]).ImportInterface; ╰──── × Unexpected token