diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 50532c5c440ff..075b0578bdd00 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -453,10 +453,10 @@ pub struct PrivateFieldExpression<'a> { pub struct CallExpression<'a> { #[cfg_attr(feature = "serialize", serde(flatten))] pub span: Span, - pub callee: Expression<'a>, pub arguments: Vec<'a, Argument<'a>>, - pub optional: bool, // for optional chaining + pub callee: Expression<'a>, pub type_parameters: Option>>, + pub optional: bool, // for optional chaining } /// New Expression @@ -1659,6 +1659,7 @@ pub struct PropertyDefinition<'a> { pub r#type: PropertyDefinitionType, #[cfg_attr(feature = "serialize", serde(flatten))] pub span: Span, + pub decorators: Vec<'a, Decorator<'a>>, pub key: PropertyKey<'a>, pub value: Option>, pub computed: bool, @@ -1670,7 +1671,6 @@ pub struct PropertyDefinition<'a> { pub readonly: bool, pub type_annotation: Option>>, pub accessibility: Option, - pub decorators: Vec<'a, Decorator<'a>>, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index d9669d6d07858..af9683a9981d8 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -612,8 +612,8 @@ pub struct TSTypeAliasDeclaration<'a> { #[cfg_attr(feature = "serialize", serde(flatten))] pub span: Span, pub id: BindingIdentifier<'a>, - pub type_annotation: TSType<'a>, pub type_parameters: Option>>, + pub type_annotation: TSType<'a>, pub declare: bool, } @@ -648,9 +648,9 @@ pub struct TSInterfaceDeclaration<'a> { #[cfg_attr(feature = "serialize", serde(flatten))] pub span: Span, pub id: BindingIdentifier<'a>, - pub body: Box<'a, TSInterfaceBody<'a>>, - pub type_parameters: Option>>, pub extends: Option>>, + pub type_parameters: Option>>, + pub body: Box<'a, TSInterfaceBody<'a>>, pub declare: bool, } diff --git a/crates/oxc_ast/src/ast_builder.rs b/crates/oxc_ast/src/ast_builder.rs index e2a535522c6f5..20a46da769df3 100644 --- a/crates/oxc_ast/src/ast_builder.rs +++ b/crates/oxc_ast/src/ast_builder.rs @@ -608,10 +608,10 @@ impl<'a> AstBuilder<'a> { ) -> Expression<'a> { Expression::CallExpression(self.alloc(CallExpression { span, - callee, arguments, - optional, + callee, type_parameters, + optional, })) } @@ -1067,6 +1067,7 @@ impl<'a> AstBuilder<'a> { ClassElement::PropertyDefinition(self.alloc(PropertyDefinition { r#type, span, + decorators, key, value, computed, @@ -1078,7 +1079,6 @@ impl<'a> AstBuilder<'a> { readonly, type_annotation, accessibility, - decorators, })) } @@ -1860,9 +1860,9 @@ impl<'a> AstBuilder<'a> { Declaration::TSInterfaceDeclaration(self.alloc(TSInterfaceDeclaration { span, id, - body, - type_parameters, extends, + type_parameters, + body, declare, })) } @@ -1879,8 +1879,8 @@ impl<'a> AstBuilder<'a> { Declaration::TSTypeAliasDeclaration(self.alloc(TSTypeAliasDeclaration { span, id, - type_annotation, type_parameters, + type_annotation, declare, })) } diff --git a/crates/oxc_traverse/src/ancestor.rs b/crates/oxc_traverse/src/ancestor.rs index 45e5e901c7d85..64ad19fa170b0 100644 --- a/crates/oxc_traverse/src/ancestor.rs +++ b/crates/oxc_traverse/src/ancestor.rs @@ -49,8 +49,8 @@ pub(crate) enum AncestorType { StaticMemberExpressionProperty = 17, PrivateFieldExpressionObject = 18, PrivateFieldExpressionField = 19, - CallExpressionCallee = 20, - CallExpressionArguments = 21, + CallExpressionArguments = 20, + CallExpressionCallee = 21, CallExpressionTypeParameters = 22, NewExpressionCallee = 23, NewExpressionArguments = 24, @@ -167,10 +167,10 @@ pub(crate) enum AncestorType { MethodDefinitionDecorators = 135, MethodDefinitionKey = 136, MethodDefinitionValue = 137, - PropertyDefinitionKey = 138, - PropertyDefinitionValue = 139, - PropertyDefinitionTypeAnnotation = 140, - PropertyDefinitionDecorators = 141, + PropertyDefinitionDecorators = 138, + PropertyDefinitionKey = 139, + PropertyDefinitionValue = 140, + PropertyDefinitionTypeAnnotation = 141, StaticBlockBody = 142, AccessorPropertyKey = 143, AccessorPropertyValue = 144, @@ -250,14 +250,14 @@ pub(crate) enum AncestorType { TSTypeParameterDefault = 218, TSTypeParameterDeclarationParams = 219, TSTypeAliasDeclarationId = 220, - TSTypeAliasDeclarationTypeAnnotation = 221, - TSTypeAliasDeclarationTypeParameters = 222, + TSTypeAliasDeclarationTypeParameters = 221, + TSTypeAliasDeclarationTypeAnnotation = 222, TSClassImplementsExpression = 223, TSClassImplementsTypeParameters = 224, TSInterfaceDeclarationId = 225, - TSInterfaceDeclarationBody = 226, + TSInterfaceDeclarationExtends = 226, TSInterfaceDeclarationTypeParameters = 227, - TSInterfaceDeclarationExtends = 228, + TSInterfaceDeclarationBody = 228, TSInterfaceBodyBody = 229, TSPropertySignatureKey = 230, TSPropertySignatureTypeAnnotation = 231, @@ -375,10 +375,10 @@ pub enum Ancestor<'a> { AncestorType::PrivateFieldExpressionObject as u16, PrivateFieldExpressionField(PrivateFieldExpressionWithoutField<'a>) = AncestorType::PrivateFieldExpressionField as u16, - CallExpressionCallee(CallExpressionWithoutCallee<'a>) = - AncestorType::CallExpressionCallee as u16, CallExpressionArguments(CallExpressionWithoutArguments<'a>) = AncestorType::CallExpressionArguments as u16, + CallExpressionCallee(CallExpressionWithoutCallee<'a>) = + AncestorType::CallExpressionCallee as u16, CallExpressionTypeParameters(CallExpressionWithoutTypeParameters<'a>) = AncestorType::CallExpressionTypeParameters as u16, NewExpressionCallee(NewExpressionWithoutCallee<'a>) = AncestorType::NewExpressionCallee as u16, @@ -569,14 +569,14 @@ pub enum Ancestor<'a> { MethodDefinitionKey(MethodDefinitionWithoutKey<'a>) = AncestorType::MethodDefinitionKey as u16, MethodDefinitionValue(MethodDefinitionWithoutValue<'a>) = AncestorType::MethodDefinitionValue as u16, + PropertyDefinitionDecorators(PropertyDefinitionWithoutDecorators<'a>) = + AncestorType::PropertyDefinitionDecorators as u16, PropertyDefinitionKey(PropertyDefinitionWithoutKey<'a>) = AncestorType::PropertyDefinitionKey as u16, PropertyDefinitionValue(PropertyDefinitionWithoutValue<'a>) = AncestorType::PropertyDefinitionValue as u16, PropertyDefinitionTypeAnnotation(PropertyDefinitionWithoutTypeAnnotation<'a>) = AncestorType::PropertyDefinitionTypeAnnotation as u16, - PropertyDefinitionDecorators(PropertyDefinitionWithoutDecorators<'a>) = - AncestorType::PropertyDefinitionDecorators as u16, StaticBlockBody(StaticBlockWithoutBody<'a>) = AncestorType::StaticBlockBody as u16, AccessorPropertyKey(AccessorPropertyWithoutKey<'a>) = AncestorType::AccessorPropertyKey as u16, AccessorPropertyValue(AccessorPropertyWithoutValue<'a>) = @@ -722,22 +722,22 @@ pub enum Ancestor<'a> { AncestorType::TSTypeParameterDeclarationParams as u16, TSTypeAliasDeclarationId(TSTypeAliasDeclarationWithoutId<'a>) = AncestorType::TSTypeAliasDeclarationId as u16, - TSTypeAliasDeclarationTypeAnnotation(TSTypeAliasDeclarationWithoutTypeAnnotation<'a>) = - AncestorType::TSTypeAliasDeclarationTypeAnnotation as u16, TSTypeAliasDeclarationTypeParameters(TSTypeAliasDeclarationWithoutTypeParameters<'a>) = AncestorType::TSTypeAliasDeclarationTypeParameters as u16, + TSTypeAliasDeclarationTypeAnnotation(TSTypeAliasDeclarationWithoutTypeAnnotation<'a>) = + AncestorType::TSTypeAliasDeclarationTypeAnnotation as u16, TSClassImplementsExpression(TSClassImplementsWithoutExpression<'a>) = AncestorType::TSClassImplementsExpression as u16, TSClassImplementsTypeParameters(TSClassImplementsWithoutTypeParameters<'a>) = AncestorType::TSClassImplementsTypeParameters as u16, TSInterfaceDeclarationId(TSInterfaceDeclarationWithoutId<'a>) = AncestorType::TSInterfaceDeclarationId as u16, - TSInterfaceDeclarationBody(TSInterfaceDeclarationWithoutBody<'a>) = - AncestorType::TSInterfaceDeclarationBody as u16, - TSInterfaceDeclarationTypeParameters(TSInterfaceDeclarationWithoutTypeParameters<'a>) = - AncestorType::TSInterfaceDeclarationTypeParameters as u16, TSInterfaceDeclarationExtends(TSInterfaceDeclarationWithoutExtends<'a>) = AncestorType::TSInterfaceDeclarationExtends as u16, + TSInterfaceDeclarationTypeParameters(TSInterfaceDeclarationWithoutTypeParameters<'a>) = + AncestorType::TSInterfaceDeclarationTypeParameters as u16, + TSInterfaceDeclarationBody(TSInterfaceDeclarationWithoutBody<'a>) = + AncestorType::TSInterfaceDeclarationBody as u16, TSInterfaceBodyBody(TSInterfaceBodyWithoutBody<'a>) = AncestorType::TSInterfaceBodyBody as u16, TSPropertySignatureKey(TSPropertySignatureWithoutKey<'a>) = AncestorType::TSPropertySignatureKey as u16, @@ -933,8 +933,8 @@ impl<'a> Ancestor<'a> { pub fn is_call_expression(&self) -> bool { matches!( self, - Self::CallExpressionCallee(_) - | Self::CallExpressionArguments(_) + Self::CallExpressionArguments(_) + | Self::CallExpressionCallee(_) | Self::CallExpressionTypeParameters(_) ) } @@ -1311,10 +1311,10 @@ impl<'a> Ancestor<'a> { pub fn is_property_definition(&self) -> bool { matches!( self, - Self::PropertyDefinitionKey(_) + Self::PropertyDefinitionDecorators(_) + | Self::PropertyDefinitionKey(_) | Self::PropertyDefinitionValue(_) | Self::PropertyDefinitionTypeAnnotation(_) - | Self::PropertyDefinitionDecorators(_) ) } @@ -1592,8 +1592,8 @@ impl<'a> Ancestor<'a> { matches!( self, Self::TSTypeAliasDeclarationId(_) - | Self::TSTypeAliasDeclarationTypeAnnotation(_) | Self::TSTypeAliasDeclarationTypeParameters(_) + | Self::TSTypeAliasDeclarationTypeAnnotation(_) ) } @@ -1610,9 +1610,9 @@ impl<'a> Ancestor<'a> { matches!( self, Self::TSInterfaceDeclarationId(_) - | Self::TSInterfaceDeclarationBody(_) - | Self::TSInterfaceDeclarationTypeParameters(_) | Self::TSInterfaceDeclarationExtends(_) + | Self::TSInterfaceDeclarationTypeParameters(_) + | Self::TSInterfaceDeclarationBody(_) ) } @@ -2832,35 +2832,29 @@ impl<'a> PrivateFieldExpressionWithoutField<'a> { } pub(crate) const OFFSET_CALL_EXPRESSION_SPAN: usize = offset_of!(CallExpression, span); -pub(crate) const OFFSET_CALL_EXPRESSION_CALLEE: usize = offset_of!(CallExpression, callee); pub(crate) const OFFSET_CALL_EXPRESSION_ARGUMENTS: usize = offset_of!(CallExpression, arguments); -pub(crate) const OFFSET_CALL_EXPRESSION_OPTIONAL: usize = offset_of!(CallExpression, optional); +pub(crate) const OFFSET_CALL_EXPRESSION_CALLEE: usize = offset_of!(CallExpression, callee); pub(crate) const OFFSET_CALL_EXPRESSION_TYPE_PARAMETERS: usize = offset_of!(CallExpression, type_parameters); +pub(crate) const OFFSET_CALL_EXPRESSION_OPTIONAL: usize = offset_of!(CallExpression, optional); #[repr(transparent)] #[derive(Debug)] -pub struct CallExpressionWithoutCallee<'a>(pub(crate) *const CallExpression<'a>); +pub struct CallExpressionWithoutArguments<'a>(pub(crate) *const CallExpression<'a>); -impl<'a> CallExpressionWithoutCallee<'a> { +impl<'a> CallExpressionWithoutArguments<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_SPAN) as *const Span) } } #[inline] - pub fn arguments(&self) -> &Vec<'a, Argument<'a>> { + pub fn callee(&self) -> &Expression<'a> { unsafe { - &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_ARGUMENTS) - as *const Vec<'a, Argument<'a>>) + &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_CALLEE) as *const Expression<'a>) } } - #[inline] - pub fn optional(&self) -> &bool { - unsafe { &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_OPTIONAL) as *const bool) } - } - #[inline] pub fn type_parameters(&self) -> &Option>> { unsafe { @@ -2868,30 +2862,31 @@ impl<'a> CallExpressionWithoutCallee<'a> { as *const Option>>) } } + + #[inline] + pub fn optional(&self) -> &bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_OPTIONAL) as *const bool) } + } } #[repr(transparent)] #[derive(Debug)] -pub struct CallExpressionWithoutArguments<'a>(pub(crate) *const CallExpression<'a>); +pub struct CallExpressionWithoutCallee<'a>(pub(crate) *const CallExpression<'a>); -impl<'a> CallExpressionWithoutArguments<'a> { +impl<'a> CallExpressionWithoutCallee<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_SPAN) as *const Span) } } #[inline] - pub fn callee(&self) -> &Expression<'a> { + pub fn arguments(&self) -> &Vec<'a, Argument<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_CALLEE) as *const Expression<'a>) + &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_ARGUMENTS) + as *const Vec<'a, Argument<'a>>) } } - #[inline] - pub fn optional(&self) -> &bool { - unsafe { &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_OPTIONAL) as *const bool) } - } - #[inline] pub fn type_parameters(&self) -> &Option>> { unsafe { @@ -2899,6 +2894,11 @@ impl<'a> CallExpressionWithoutArguments<'a> { as *const Option>>) } } + + #[inline] + pub fn optional(&self) -> &bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_OPTIONAL) as *const bool) } + } } #[repr(transparent)] @@ -2912,17 +2912,17 @@ impl<'a> CallExpressionWithoutTypeParameters<'a> { } #[inline] - pub fn callee(&self) -> &Expression<'a> { + pub fn arguments(&self) -> &Vec<'a, Argument<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_CALLEE) as *const Expression<'a>) + &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_ARGUMENTS) + as *const Vec<'a, Argument<'a>>) } } #[inline] - pub fn arguments(&self) -> &Vec<'a, Argument<'a>> { + pub fn callee(&self) -> &Expression<'a> { unsafe { - &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_ARGUMENTS) - as *const Vec<'a, Argument<'a>>) + &*((self.0 as *const u8).add(OFFSET_CALL_EXPRESSION_CALLEE) as *const Expression<'a>) } } @@ -6918,6 +6918,8 @@ impl<'a> MethodDefinitionWithoutValue<'a> { pub(crate) const OFFSET_PROPERTY_DEFINITION_TYPE: usize = offset_of!(PropertyDefinition, r#type); pub(crate) const OFFSET_PROPERTY_DEFINITION_SPAN: usize = offset_of!(PropertyDefinition, span); +pub(crate) const OFFSET_PROPERTY_DEFINITION_DECORATORS: usize = + offset_of!(PropertyDefinition, decorators); pub(crate) const OFFSET_PROPERTY_DEFINITION_KEY: usize = offset_of!(PropertyDefinition, key); pub(crate) const OFFSET_PROPERTY_DEFINITION_VALUE: usize = offset_of!(PropertyDefinition, value); pub(crate) const OFFSET_PROPERTY_DEFINITION_COMPUTED: usize = @@ -6938,14 +6940,12 @@ pub(crate) const OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION: usize = offset_of!(PropertyDefinition, type_annotation); pub(crate) const OFFSET_PROPERTY_DEFINITION_ACCESSIBILITY: usize = offset_of!(PropertyDefinition, accessibility); -pub(crate) const OFFSET_PROPERTY_DEFINITION_DECORATORS: usize = - offset_of!(PropertyDefinition, decorators); #[repr(transparent)] #[derive(Debug)] -pub struct PropertyDefinitionWithoutKey<'a>(pub(crate) *const PropertyDefinition<'a>); +pub struct PropertyDefinitionWithoutDecorators<'a>(pub(crate) *const PropertyDefinition<'a>); -impl<'a> PropertyDefinitionWithoutKey<'a> { +impl<'a> PropertyDefinitionWithoutDecorators<'a> { #[inline] pub fn r#type(&self) -> &PropertyDefinitionType { unsafe { @@ -6959,6 +6959,13 @@ impl<'a> PropertyDefinitionWithoutKey<'a> { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_SPAN) as *const Span) } } + #[inline] + pub fn key(&self) -> &PropertyKey<'a> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_KEY) as *const PropertyKey<'a>) + } + } + #[inline] pub fn value(&self) -> &Option> { unsafe { @@ -7017,21 +7024,13 @@ impl<'a> PropertyDefinitionWithoutKey<'a> { as *const Option) } } - - #[inline] - pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_DECORATORS) - as *const Vec<'a, Decorator<'a>>) - } - } } #[repr(transparent)] #[derive(Debug)] -pub struct PropertyDefinitionWithoutValue<'a>(pub(crate) *const PropertyDefinition<'a>); +pub struct PropertyDefinitionWithoutKey<'a>(pub(crate) *const PropertyDefinition<'a>); -impl<'a> PropertyDefinitionWithoutValue<'a> { +impl<'a> PropertyDefinitionWithoutKey<'a> { #[inline] pub fn r#type(&self) -> &PropertyDefinitionType { unsafe { @@ -7046,9 +7045,18 @@ impl<'a> PropertyDefinitionWithoutValue<'a> { } #[inline] - pub fn key(&self) -> &PropertyKey<'a> { + pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_KEY) as *const PropertyKey<'a>) + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_DECORATORS) + as *const Vec<'a, Decorator<'a>>) + } + } + + #[inline] + pub fn value(&self) -> &Option> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_VALUE) + as *const Option>) } } @@ -7102,21 +7110,13 @@ impl<'a> PropertyDefinitionWithoutValue<'a> { as *const Option) } } - - #[inline] - pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_DECORATORS) - as *const Vec<'a, Decorator<'a>>) - } - } } #[repr(transparent)] #[derive(Debug)] -pub struct PropertyDefinitionWithoutTypeAnnotation<'a>(pub(crate) *const PropertyDefinition<'a>); +pub struct PropertyDefinitionWithoutValue<'a>(pub(crate) *const PropertyDefinition<'a>); -impl<'a> PropertyDefinitionWithoutTypeAnnotation<'a> { +impl<'a> PropertyDefinitionWithoutValue<'a> { #[inline] pub fn r#type(&self) -> &PropertyDefinitionType { unsafe { @@ -7131,17 +7131,17 @@ impl<'a> PropertyDefinitionWithoutTypeAnnotation<'a> { } #[inline] - pub fn key(&self) -> &PropertyKey<'a> { + pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_KEY) as *const PropertyKey<'a>) + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_DECORATORS) + as *const Vec<'a, Decorator<'a>>) } } #[inline] - pub fn value(&self) -> &Option> { + pub fn key(&self) -> &PropertyKey<'a> { unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_VALUE) - as *const Option>) + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_KEY) as *const PropertyKey<'a>) } } @@ -7181,27 +7181,27 @@ impl<'a> PropertyDefinitionWithoutTypeAnnotation<'a> { } #[inline] - pub fn accessibility(&self) -> &Option { + pub fn type_annotation(&self) -> &Option>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_ACCESSIBILITY) - as *const Option) + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) + as *const Option>>) } } #[inline] - pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { + pub fn accessibility(&self) -> &Option { unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_DECORATORS) - as *const Vec<'a, Decorator<'a>>) + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_ACCESSIBILITY) + as *const Option) } } } #[repr(transparent)] #[derive(Debug)] -pub struct PropertyDefinitionWithoutDecorators<'a>(pub(crate) *const PropertyDefinition<'a>); +pub struct PropertyDefinitionWithoutTypeAnnotation<'a>(pub(crate) *const PropertyDefinition<'a>); -impl<'a> PropertyDefinitionWithoutDecorators<'a> { +impl<'a> PropertyDefinitionWithoutTypeAnnotation<'a> { #[inline] pub fn r#type(&self) -> &PropertyDefinitionType { unsafe { @@ -7215,6 +7215,14 @@ impl<'a> PropertyDefinitionWithoutDecorators<'a> { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_SPAN) as *const Span) } } + #[inline] + pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_DECORATORS) + as *const Vec<'a, Decorator<'a>>) + } + } + #[inline] pub fn key(&self) -> &PropertyKey<'a> { unsafe { @@ -7265,14 +7273,6 @@ impl<'a> PropertyDefinitionWithoutDecorators<'a> { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_READONLY) as *const bool) } } - #[inline] - pub fn type_annotation(&self) -> &Option>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) - as *const Option>>) - } - } - #[inline] pub fn accessibility(&self) -> &Option { unsafe { @@ -9494,10 +9494,10 @@ pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_SPAN: usize = offset_of!(TSTypeAliasDeclaration, span); pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_ID: usize = offset_of!(TSTypeAliasDeclaration, id); -pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION: usize = - offset_of!(TSTypeAliasDeclaration, type_annotation); pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_PARAMETERS: usize = offset_of!(TSTypeAliasDeclaration, type_parameters); +pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION: usize = + offset_of!(TSTypeAliasDeclaration, type_annotation); pub(crate) const OFFSET_TS_TYPE_ALIAS_DECLARATION_DECLARE: usize = offset_of!(TSTypeAliasDeclaration, declare); @@ -9514,18 +9514,18 @@ impl<'a> TSTypeAliasDeclarationWithoutId<'a> { } #[inline] - pub fn type_annotation(&self) -> &TSType<'a> { + pub fn type_parameters(&self) -> &Option>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION) - as *const TSType<'a>) + &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_PARAMETERS) + as *const Option>>) } } #[inline] - pub fn type_parameters(&self) -> &Option>> { + pub fn type_annotation(&self) -> &TSType<'a> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_PARAMETERS) - as *const Option>>) + &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION) + as *const TSType<'a>) } } @@ -9539,11 +9539,11 @@ impl<'a> TSTypeAliasDeclarationWithoutId<'a> { #[repr(transparent)] #[derive(Debug)] -pub struct TSTypeAliasDeclarationWithoutTypeAnnotation<'a>( +pub struct TSTypeAliasDeclarationWithoutTypeParameters<'a>( pub(crate) *const TSTypeAliasDeclaration<'a>, ); -impl<'a> TSTypeAliasDeclarationWithoutTypeAnnotation<'a> { +impl<'a> TSTypeAliasDeclarationWithoutTypeParameters<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { @@ -9560,10 +9560,10 @@ impl<'a> TSTypeAliasDeclarationWithoutTypeAnnotation<'a> { } #[inline] - pub fn type_parameters(&self) -> &Option>> { + pub fn type_annotation(&self) -> &TSType<'a> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_PARAMETERS) - as *const Option>>) + &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION) + as *const TSType<'a>) } } @@ -9577,11 +9577,11 @@ impl<'a> TSTypeAliasDeclarationWithoutTypeAnnotation<'a> { #[repr(transparent)] #[derive(Debug)] -pub struct TSTypeAliasDeclarationWithoutTypeParameters<'a>( +pub struct TSTypeAliasDeclarationWithoutTypeAnnotation<'a>( pub(crate) *const TSTypeAliasDeclaration<'a>, ); -impl<'a> TSTypeAliasDeclarationWithoutTypeParameters<'a> { +impl<'a> TSTypeAliasDeclarationWithoutTypeAnnotation<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { @@ -9598,10 +9598,10 @@ impl<'a> TSTypeAliasDeclarationWithoutTypeParameters<'a> { } #[inline] - pub fn type_annotation(&self) -> &TSType<'a> { + pub fn type_parameters(&self) -> &Option>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION) - as *const TSType<'a>) + &*((self.0 as *const u8).add(OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_PARAMETERS) + as *const Option>>) } } @@ -9660,12 +9660,12 @@ impl<'a> TSClassImplementsWithoutTypeParameters<'a> { pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_SPAN: usize = offset_of!(TSInterfaceDeclaration, span); pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_ID: usize = offset_of!(TSInterfaceDeclaration, id); -pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_BODY: usize = - offset_of!(TSInterfaceDeclaration, body); -pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_TYPE_PARAMETERS: usize = - offset_of!(TSInterfaceDeclaration, type_parameters); pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_EXTENDS: usize = offset_of!(TSInterfaceDeclaration, extends); +pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_TYPE_PARAMETERS: usize = + offset_of!(TSInterfaceDeclaration, type_parameters); +pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_BODY: usize = + offset_of!(TSInterfaceDeclaration, body); pub(crate) const OFFSET_TS_INTERFACE_DECLARATION_DECLARE: usize = offset_of!(TSInterfaceDeclaration, declare); @@ -9682,10 +9682,10 @@ impl<'a> TSInterfaceDeclarationWithoutId<'a> { } #[inline] - pub fn body(&self) -> &Box<'a, TSInterfaceBody<'a>> { + pub fn extends(&self) -> &Option>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_BODY) - as *const Box<'a, TSInterfaceBody<'a>>) + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) + as *const Option>>) } } @@ -9698,10 +9698,10 @@ impl<'a> TSInterfaceDeclarationWithoutId<'a> { } #[inline] - pub fn extends(&self) -> &Option>> { + pub fn body(&self) -> &Box<'a, TSInterfaceBody<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) - as *const Option>>) + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_BODY) + as *const Box<'a, TSInterfaceBody<'a>>) } } @@ -9715,9 +9715,9 @@ impl<'a> TSInterfaceDeclarationWithoutId<'a> { #[repr(transparent)] #[derive(Debug)] -pub struct TSInterfaceDeclarationWithoutBody<'a>(pub(crate) *const TSInterfaceDeclaration<'a>); +pub struct TSInterfaceDeclarationWithoutExtends<'a>(pub(crate) *const TSInterfaceDeclaration<'a>); -impl<'a> TSInterfaceDeclarationWithoutBody<'a> { +impl<'a> TSInterfaceDeclarationWithoutExtends<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { @@ -9742,10 +9742,10 @@ impl<'a> TSInterfaceDeclarationWithoutBody<'a> { } #[inline] - pub fn extends(&self) -> &Option>> { + pub fn body(&self) -> &Box<'a, TSInterfaceBody<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) - as *const Option>>) + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_BODY) + as *const Box<'a, TSInterfaceBody<'a>>) } } @@ -9780,18 +9780,18 @@ impl<'a> TSInterfaceDeclarationWithoutTypeParameters<'a> { } #[inline] - pub fn body(&self) -> &Box<'a, TSInterfaceBody<'a>> { + pub fn extends(&self) -> &Option>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_BODY) - as *const Box<'a, TSInterfaceBody<'a>>) + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) + as *const Option>>) } } #[inline] - pub fn extends(&self) -> &Option>> { + pub fn body(&self) -> &Box<'a, TSInterfaceBody<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) - as *const Option>>) + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_BODY) + as *const Box<'a, TSInterfaceBody<'a>>) } } @@ -9805,9 +9805,9 @@ impl<'a> TSInterfaceDeclarationWithoutTypeParameters<'a> { #[repr(transparent)] #[derive(Debug)] -pub struct TSInterfaceDeclarationWithoutExtends<'a>(pub(crate) *const TSInterfaceDeclaration<'a>); +pub struct TSInterfaceDeclarationWithoutBody<'a>(pub(crate) *const TSInterfaceDeclaration<'a>); -impl<'a> TSInterfaceDeclarationWithoutExtends<'a> { +impl<'a> TSInterfaceDeclarationWithoutBody<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { @@ -9824,10 +9824,10 @@ impl<'a> TSInterfaceDeclarationWithoutExtends<'a> { } #[inline] - pub fn body(&self) -> &Box<'a, TSInterfaceBody<'a>> { + pub fn extends(&self) -> &Option>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_BODY) - as *const Box<'a, TSInterfaceBody<'a>>) + &*((self.0 as *const u8).add(OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) + as *const Option>>) } } diff --git a/crates/oxc_traverse/src/walk.rs b/crates/oxc_traverse/src/walk.rs index 3284189f9981f..ddba49a48b65f 100644 --- a/crates/oxc_traverse/src/walk.rs +++ b/crates/oxc_traverse/src/walk.rs @@ -608,19 +608,21 @@ pub(crate) unsafe fn walk_call_expression<'a, Tr: Traverse<'a>>( ctx: &mut TraverseCtx<'a>, ) { traverser.enter_call_expression(&mut *node, ctx); - ctx.push_stack(Ancestor::CallExpressionCallee(ancestor::CallExpressionWithoutCallee(node))); - walk_expression( - traverser, - (node as *mut u8).add(ancestor::OFFSET_CALL_EXPRESSION_CALLEE) as *mut Expression, - ctx, - ); - ctx.retag_stack(AncestorType::CallExpressionArguments); + ctx.push_stack(Ancestor::CallExpressionArguments(ancestor::CallExpressionWithoutArguments( + node, + ))); for item in (*((node as *mut u8).add(ancestor::OFFSET_CALL_EXPRESSION_ARGUMENTS) as *mut Vec)) .iter_mut() { walk_argument(traverser, item as *mut _, ctx); } + ctx.retag_stack(AncestorType::CallExpressionCallee); + walk_expression( + traverser, + (node as *mut u8).add(ancestor::OFFSET_CALL_EXPRESSION_CALLEE) as *mut Expression, + ctx, + ); if let Some(field) = &mut *((node as *mut u8) .add(ancestor::OFFSET_CALL_EXPRESSION_TYPE_PARAMETERS) as *mut Option>) @@ -2590,7 +2592,16 @@ pub(crate) unsafe fn walk_property_definition<'a, Tr: Traverse<'a>>( ctx: &mut TraverseCtx<'a>, ) { traverser.enter_property_definition(&mut *node, ctx); - ctx.push_stack(Ancestor::PropertyDefinitionKey(ancestor::PropertyDefinitionWithoutKey(node))); + ctx.push_stack(Ancestor::PropertyDefinitionDecorators( + ancestor::PropertyDefinitionWithoutDecorators(node), + )); + for item in (*((node as *mut u8).add(ancestor::OFFSET_PROPERTY_DEFINITION_DECORATORS) + as *mut Vec)) + .iter_mut() + { + walk_decorator(traverser, item as *mut _, ctx); + } + ctx.retag_stack(AncestorType::PropertyDefinitionKey); walk_property_key( traverser, (node as *mut u8).add(ancestor::OFFSET_PROPERTY_DEFINITION_KEY) as *mut PropertyKey, @@ -2609,13 +2620,6 @@ pub(crate) unsafe fn walk_property_definition<'a, Tr: Traverse<'a>>( ctx.retag_stack(AncestorType::PropertyDefinitionTypeAnnotation); walk_ts_type_annotation(traverser, (&mut **field) as *mut _, ctx); } - ctx.retag_stack(AncestorType::PropertyDefinitionDecorators); - for item in (*((node as *mut u8).add(ancestor::OFFSET_PROPERTY_DEFINITION_DECORATORS) - as *mut Vec)) - .iter_mut() - { - walk_decorator(traverser, item as *mut _, ctx); - } ctx.pop_stack(); traverser.exit_property_definition(&mut *node, ctx); } @@ -4477,13 +4481,6 @@ pub(crate) unsafe fn walk_ts_type_alias_declaration<'a, Tr: Traverse<'a>>( as *mut BindingIdentifier, ctx, ); - ctx.retag_stack(AncestorType::TSTypeAliasDeclarationTypeAnnotation); - walk_ts_type( - traverser, - (node as *mut u8).add(ancestor::OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION) - as *mut TSType, - ctx, - ); if let Some(field) = &mut *((node as *mut u8) .add(ancestor::OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_PARAMETERS) as *mut Option>) @@ -4491,6 +4488,13 @@ pub(crate) unsafe fn walk_ts_type_alias_declaration<'a, Tr: Traverse<'a>>( ctx.retag_stack(AncestorType::TSTypeAliasDeclarationTypeParameters); walk_ts_type_parameter_declaration(traverser, (&mut **field) as *mut _, ctx); } + ctx.retag_stack(AncestorType::TSTypeAliasDeclarationTypeAnnotation); + walk_ts_type( + traverser, + (node as *mut u8).add(ancestor::OFFSET_TS_TYPE_ALIAS_DECLARATION_TYPE_ANNOTATION) + as *mut TSType, + ctx, + ); ctx.pop_stack(); traverser.exit_ts_type_alias_declaration(&mut *node, ctx); } @@ -4535,20 +4539,6 @@ pub(crate) unsafe fn walk_ts_interface_declaration<'a, Tr: Traverse<'a>>( as *mut BindingIdentifier, ctx, ); - ctx.retag_stack(AncestorType::TSInterfaceDeclarationBody); - walk_ts_interface_body( - traverser, - (&mut **((node as *mut u8).add(ancestor::OFFSET_TS_INTERFACE_DECLARATION_BODY) - as *mut Box)) as *mut _, - ctx, - ); - if let Some(field) = &mut *((node as *mut u8) - .add(ancestor::OFFSET_TS_INTERFACE_DECLARATION_TYPE_PARAMETERS) - as *mut Option>) - { - ctx.retag_stack(AncestorType::TSInterfaceDeclarationTypeParameters); - walk_ts_type_parameter_declaration(traverser, (&mut **field) as *mut _, ctx); - } if let Some(field) = &mut *((node as *mut u8) .add(ancestor::OFFSET_TS_INTERFACE_DECLARATION_EXTENDS) as *mut Option>) @@ -4558,6 +4548,20 @@ pub(crate) unsafe fn walk_ts_interface_declaration<'a, Tr: Traverse<'a>>( walk_ts_interface_heritage(traverser, item as *mut _, ctx); } } + if let Some(field) = &mut *((node as *mut u8) + .add(ancestor::OFFSET_TS_INTERFACE_DECLARATION_TYPE_PARAMETERS) + as *mut Option>) + { + ctx.retag_stack(AncestorType::TSInterfaceDeclarationTypeParameters); + walk_ts_type_parameter_declaration(traverser, (&mut **field) as *mut _, ctx); + } + ctx.retag_stack(AncestorType::TSInterfaceDeclarationBody); + walk_ts_interface_body( + traverser, + (&mut **((node as *mut u8).add(ancestor::OFFSET_TS_INTERFACE_DECLARATION_BODY) + as *mut Box)) as *mut _, + ctx, + ); ctx.pop_stack(); traverser.exit_ts_interface_declaration(&mut *node, ctx); }