From 48947a26d22f186801239d001c2f435fa652fa8a Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Wed, 10 Jul 2024 02:03:04 +0000 Subject: [PATCH] fix(ast): put `decorators` before everything else. (#4143) Won't fix #4142 It is similar to #3994 but for those types that weren't relying on this order. It seems to be the right order. technically speaking it is a breaking change but I know as a fact that it won't have a big difference on our downstream. If you want it to be chronically correct feel free to merge as a breaking change. --- crates/oxc_ast/src/ast/js.rs | 4 +- crates/oxc_ast/src/ast_builder_impl.rs | 2 +- crates/oxc_ast/src/generated/ast_builder.rs | 20 +-- crates/oxc_ast/src/generated/visit.rs | 54 ++++---- crates/oxc_ast/src/generated/visit_mut.rs | 54 ++++---- crates/oxc_isolated_declarations/src/class.rs | 4 +- .../oxc_isolated_declarations/src/function.rs | 2 +- crates/oxc_parser/src/js/class.rs | 2 +- crates/oxc_parser/src/js/function.rs | 2 +- crates/oxc_transformer/src/typescript/enum.rs | 2 +- crates/oxc_traverse/src/ancestor.rs | 120 +++++++++--------- crates/oxc_traverse/src/walk.rs | 34 ++--- 12 files changed, 152 insertions(+), 148 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 06981ffc02e9..0a802c1f7423 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1511,11 +1511,11 @@ pub struct FormalParameters<'a> { pub struct FormalParameter<'a> { #[cfg_attr(feature = "serialize", serde(flatten))] pub span: Span, + pub decorators: Vec<'a, Decorator<'a>>, pub pattern: BindingPattern<'a>, pub accessibility: Option, pub readonly: bool, pub r#override: bool, - pub decorators: Vec<'a, Decorator<'a>>, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -1776,11 +1776,11 @@ pub struct AccessorProperty<'a> { pub r#type: AccessorPropertyType, #[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, pub r#static: bool, - pub decorators: Vec<'a, Decorator<'a>>, } #[visited_node] diff --git a/crates/oxc_ast/src/ast_builder_impl.rs b/crates/oxc_ast/src/ast_builder_impl.rs index f3c5fc5d0a91..a56b6ab61ac7 100644 --- a/crates/oxc_ast/src/ast_builder_impl.rs +++ b/crates/oxc_ast/src/ast_builder_impl.rs @@ -128,7 +128,7 @@ impl<'a> AstBuilder<'a> { span: Span, pattern: BindingPattern<'a>, ) -> FormalParameter<'a> { - self.formal_parameter(span, pattern, None, false, false, self.vec()) + self.formal_parameter(span, self.vec(), pattern, None, false, false) } #[inline] diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 205d59a4b885..a254161a2736 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -3814,26 +3814,26 @@ impl<'a> AstBuilder<'a> { pub fn formal_parameter( self, span: Span, + decorators: Vec<'a, Decorator<'a>>, pattern: BindingPattern<'a>, accessibility: Option, readonly: bool, r#override: bool, - decorators: Vec<'a, Decorator<'a>>, ) -> FormalParameter<'a> { - FormalParameter { span, pattern, accessibility, readonly, r#override, decorators } + FormalParameter { span, decorators, pattern, accessibility, readonly, r#override } } #[inline] pub fn alloc_formal_parameter( self, span: Span, + decorators: Vec<'a, Decorator<'a>>, pattern: BindingPattern<'a>, accessibility: Option, readonly: bool, r#override: bool, - decorators: Vec<'a, Decorator<'a>>, ) -> Box<'a, FormalParameter<'a>> { - self.formal_parameter(span, pattern, accessibility, readonly, r#override, decorators) + self.formal_parameter(span, decorators, pattern, accessibility, readonly, r#override) .into_in(self.allocator) } @@ -4131,14 +4131,14 @@ impl<'a> AstBuilder<'a> { self, r#type: AccessorPropertyType, span: Span, + decorators: Vec<'a, Decorator<'a>>, key: PropertyKey<'a>, value: Option>, computed: bool, r#static: bool, - decorators: Vec<'a, Decorator<'a>>, ) -> ClassElement<'a> { ClassElement::AccessorProperty(self.alloc( - self.accessor_property(r#type, span, key, value, computed, r#static, decorators), + self.accessor_property(r#type, span, decorators, key, value, computed, r#static), )) } @@ -4510,13 +4510,13 @@ impl<'a> AstBuilder<'a> { self, r#type: AccessorPropertyType, span: Span, + decorators: Vec<'a, Decorator<'a>>, key: PropertyKey<'a>, value: Option>, computed: bool, r#static: bool, - decorators: Vec<'a, Decorator<'a>>, ) -> AccessorProperty<'a> { - AccessorProperty { r#type, span, key, value, computed, r#static, decorators } + AccessorProperty { r#type, span, decorators, key, value, computed, r#static } } #[inline] @@ -4524,13 +4524,13 @@ impl<'a> AstBuilder<'a> { self, r#type: AccessorPropertyType, span: Span, + decorators: Vec<'a, Decorator<'a>>, key: PropertyKey<'a>, value: Option>, computed: bool, r#static: bool, - decorators: Vec<'a, Decorator<'a>>, ) -> Box<'a, AccessorProperty<'a>> { - self.accessor_property(r#type, span, key, value, computed, r#static, decorators) + self.accessor_property(r#type, span, decorators, key, value, computed, r#static) .into_in(self.allocator) } diff --git a/crates/oxc_ast/src/generated/visit.rs b/crates/oxc_ast/src/generated/visit.rs index ec4ca3e1ed82..4fcfdde11dbb 100644 --- a/crates/oxc_ast/src/generated/visit.rs +++ b/crates/oxc_ast/src/generated/visit.rs @@ -227,6 +227,16 @@ pub trait Visit<'a>: Sized { walk_formal_parameter(self, it); } + #[inline] + fn visit_decorators(&mut self, it: &Vec<'a, Decorator<'a>>) { + walk_decorators(self, it); + } + + #[inline] + fn visit_decorator(&mut self, it: &Decorator<'a>) { + walk_decorator(self, it); + } + #[inline] fn visit_binding_pattern(&mut self, it: &BindingPattern<'a>) { walk_binding_pattern(self, it); @@ -625,16 +635,6 @@ pub trait Visit<'a>: Sized { walk_js_doc_unknown_type(self, it); } - #[inline] - fn visit_decorators(&mut self, it: &Vec<'a, Decorator<'a>>) { - walk_decorators(self, it); - } - - #[inline] - fn visit_decorator(&mut self, it: &Decorator<'a>) { - walk_decorator(self, it); - } - #[inline] fn visit_function_body(&mut self, it: &FunctionBody<'a>) { walk_function_body(self, it); @@ -1745,8 +1745,23 @@ pub mod walk { pub fn walk_formal_parameter<'a, V: Visit<'a>>(visitor: &mut V, it: &FormalParameter<'a>) { let kind = AstKind::FormalParameter(visitor.alloc(it)); visitor.enter_node(kind); - visitor.visit_binding_pattern(&it.pattern); visitor.visit_decorators(&it.decorators); + visitor.visit_binding_pattern(&it.pattern); + visitor.leave_node(kind); + } + + #[inline] + pub fn walk_decorators<'a, V: Visit<'a>>(visitor: &mut V, it: &Vec<'a, Decorator<'a>>) { + for el in it.iter() { + visitor.visit_decorator(el); + } + } + + #[inline] + pub fn walk_decorator<'a, V: Visit<'a>>(visitor: &mut V, it: &Decorator<'a>) { + let kind = AstKind::Decorator(visitor.alloc(it)); + visitor.enter_node(kind); + visitor.visit_expression(&it.expression); visitor.leave_node(kind); } @@ -2543,21 +2558,6 @@ pub mod walk { // NOTE: AstKind doesn't exists! } - #[inline] - pub fn walk_decorators<'a, V: Visit<'a>>(visitor: &mut V, it: &Vec<'a, Decorator<'a>>) { - for el in it.iter() { - visitor.visit_decorator(el); - } - } - - #[inline] - pub fn walk_decorator<'a, V: Visit<'a>>(visitor: &mut V, it: &Decorator<'a>) { - let kind = AstKind::Decorator(visitor.alloc(it)); - visitor.enter_node(kind); - visitor.visit_expression(&it.expression); - visitor.leave_node(kind); - } - #[inline] pub fn walk_function_body<'a, V: Visit<'a>>(visitor: &mut V, it: &FunctionBody<'a>) { let kind = AstKind::FunctionBody(visitor.alloc(it)); @@ -3053,11 +3053,11 @@ pub mod walk { #[inline] pub fn walk_accessor_property<'a, V: Visit<'a>>(visitor: &mut V, it: &AccessorProperty<'a>) { // NOTE: AstKind doesn't exists! + visitor.visit_decorators(&it.decorators); visitor.visit_property_key(&it.key); if let Some(value) = &it.value { visitor.visit_expression(value); } - visitor.visit_decorators(&it.decorators); } #[inline] diff --git a/crates/oxc_ast/src/generated/visit_mut.rs b/crates/oxc_ast/src/generated/visit_mut.rs index 3ce7cfae1805..307c7962733d 100644 --- a/crates/oxc_ast/src/generated/visit_mut.rs +++ b/crates/oxc_ast/src/generated/visit_mut.rs @@ -216,6 +216,16 @@ pub trait VisitMut<'a>: Sized { walk_formal_parameter(self, it); } + #[inline] + fn visit_decorators(&mut self, it: &mut Vec<'a, Decorator<'a>>) { + walk_decorators(self, it); + } + + #[inline] + fn visit_decorator(&mut self, it: &mut Decorator<'a>) { + walk_decorator(self, it); + } + #[inline] fn visit_binding_pattern(&mut self, it: &mut BindingPattern<'a>) { walk_binding_pattern(self, it); @@ -614,16 +624,6 @@ pub trait VisitMut<'a>: Sized { walk_js_doc_unknown_type(self, it); } - #[inline] - fn visit_decorators(&mut self, it: &mut Vec<'a, Decorator<'a>>) { - walk_decorators(self, it); - } - - #[inline] - fn visit_decorator(&mut self, it: &mut Decorator<'a>) { - walk_decorator(self, it); - } - #[inline] fn visit_function_body(&mut self, it: &mut FunctionBody<'a>) { walk_function_body(self, it); @@ -1770,8 +1770,23 @@ pub mod walk_mut { ) { let kind = AstType::FormalParameter; visitor.enter_node(kind); - visitor.visit_binding_pattern(&mut it.pattern); visitor.visit_decorators(&mut it.decorators); + visitor.visit_binding_pattern(&mut it.pattern); + visitor.leave_node(kind); + } + + #[inline] + pub fn walk_decorators<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Vec<'a, Decorator<'a>>) { + for el in it.iter_mut() { + visitor.visit_decorator(el); + } + } + + #[inline] + pub fn walk_decorator<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Decorator<'a>) { + let kind = AstType::Decorator; + visitor.enter_node(kind); + visitor.visit_expression(&mut it.expression); visitor.leave_node(kind); } @@ -2646,21 +2661,6 @@ pub mod walk_mut { // NOTE: AstType doesn't exists! } - #[inline] - pub fn walk_decorators<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Vec<'a, Decorator<'a>>) { - for el in it.iter_mut() { - visitor.visit_decorator(el); - } - } - - #[inline] - pub fn walk_decorator<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut Decorator<'a>) { - let kind = AstType::Decorator; - visitor.enter_node(kind); - visitor.visit_expression(&mut it.expression); - visitor.leave_node(kind); - } - #[inline] pub fn walk_function_body<'a, V: VisitMut<'a>>(visitor: &mut V, it: &mut FunctionBody<'a>) { let kind = AstType::FunctionBody; @@ -3186,11 +3186,11 @@ pub mod walk_mut { it: &mut AccessorProperty<'a>, ) { // NOTE: AstType doesn't exists! + visitor.visit_decorators(&mut it.decorators); visitor.visit_property_key(&mut it.key); if let Some(value) = &mut it.value { visitor.visit_expression(value); } - visitor.visit_decorators(&mut it.decorators); } #[inline] diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index 55479ce141a0..7c93e6f7300f 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -444,11 +444,11 @@ impl<'a> IsolatedDeclarations<'a> { let new_element = self.ast.class_element_accessor_property( property.r#type, property.span, + self.ast.vec(), self.ast.copy(&property.key), None, property.computed, property.r#static, - self.ast.vec(), ); elements.push(new_element); } @@ -525,7 +525,7 @@ impl<'a> IsolatedDeclarations<'a> { ) -> Box<'a, FormalParameters<'a>> { let pattern = BindingPattern { kind, type_annotation, optional: false }; let parameter = - self.ast.formal_parameter(SPAN, pattern, None, false, false, self.ast.vec()); + self.ast.formal_parameter(SPAN, self.ast.vec(), pattern, None, false, false); let items = self.ast.vec1(parameter); self.ast.alloc_formal_parameters( SPAN, diff --git a/crates/oxc_isolated_declarations/src/function.rs b/crates/oxc_isolated_declarations/src/function.rs index 09fcf7578ea2..b5d59835a703 100644 --- a/crates/oxc_isolated_declarations/src/function.rs +++ b/crates/oxc_isolated_declarations/src/function.rs @@ -113,7 +113,7 @@ impl<'a> IsolatedDeclarations<'a> { ); } - Some(self.ast.formal_parameter(param.span, pattern, None, false, false, self.ast.vec())) + Some(self.ast.formal_parameter(param.span, self.ast.vec(), pattern, None, false, false)) } pub fn transform_formal_parameters( diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index 28a0257aaadf..77ab8288b336 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -498,11 +498,11 @@ impl<'a> ParserImpl<'a> { Ok(self.ast.class_element_accessor_property( r#type, self.end_span(span), + decorators, key, value, computed, r#static, - decorators, )) } } diff --git a/crates/oxc_parser/src/js/function.rs b/crates/oxc_parser/src/js/function.rs index a9724707e0b6..d642232c7282 100644 --- a/crates/oxc_parser/src/js/function.rs +++ b/crates/oxc_parser/src/js/function.rs @@ -89,11 +89,11 @@ impl<'a> ParserImpl<'a> { let decorators = self.consume_decorators(); Ok(self.ast.formal_parameter( self.end_span(span), + decorators, pattern, modifiers.accessibility(), modifiers.contains_readonly(), modifiers.contains_override(), - decorators, )) } diff --git a/crates/oxc_transformer/src/typescript/enum.rs b/crates/oxc_transformer/src/typescript/enum.rs index 1674b2559569..ba1de0af4509 100644 --- a/crates/oxc_transformer/src/typescript/enum.rs +++ b/crates/oxc_transformer/src/typescript/enum.rs @@ -89,7 +89,7 @@ impl<'a> TypeScriptEnum<'a> { let id = ast.binding_pattern(kind, Option::::None, false); // ((Foo) => { - let params = ast.formal_parameter(SPAN, id, None, false, false, ast.vec()); + let params = ast.formal_parameter(SPAN, ast.vec(), id, None, false, false); let params = ast.vec1(params); let params = ast.alloc_formal_parameters( SPAN, diff --git a/crates/oxc_traverse/src/ancestor.rs b/crates/oxc_traverse/src/ancestor.rs index 64ad19fa170b..02f78af89c23 100644 --- a/crates/oxc_traverse/src/ancestor.rs +++ b/crates/oxc_traverse/src/ancestor.rs @@ -147,8 +147,8 @@ pub(crate) enum AncestorType { FunctionReturnType = 115, FormalParametersItems = 116, FormalParametersRest = 117, - FormalParameterPattern = 118, - FormalParameterDecorators = 119, + FormalParameterDecorators = 118, + FormalParameterPattern = 119, FunctionBodyDirectives = 120, FunctionBodyStatements = 121, ArrowFunctionExpressionParams = 122, @@ -172,9 +172,9 @@ pub(crate) enum AncestorType { PropertyDefinitionValue = 140, PropertyDefinitionTypeAnnotation = 141, StaticBlockBody = 142, - AccessorPropertyKey = 143, - AccessorPropertyValue = 144, - AccessorPropertyDecorators = 145, + AccessorPropertyDecorators = 143, + AccessorPropertyKey = 144, + AccessorPropertyValue = 145, ImportExpressionSource = 146, ImportExpressionArguments = 147, ImportDeclarationSpecifiers = 148, @@ -537,10 +537,10 @@ pub enum Ancestor<'a> { AncestorType::FormalParametersItems as u16, FormalParametersRest(FormalParametersWithoutRest<'a>) = AncestorType::FormalParametersRest as u16, - FormalParameterPattern(FormalParameterWithoutPattern<'a>) = - AncestorType::FormalParameterPattern as u16, FormalParameterDecorators(FormalParameterWithoutDecorators<'a>) = AncestorType::FormalParameterDecorators as u16, + FormalParameterPattern(FormalParameterWithoutPattern<'a>) = + AncestorType::FormalParameterPattern as u16, FunctionBodyDirectives(FunctionBodyWithoutDirectives<'a>) = AncestorType::FunctionBodyDirectives as u16, FunctionBodyStatements(FunctionBodyWithoutStatements<'a>) = @@ -578,11 +578,11 @@ pub enum Ancestor<'a> { PropertyDefinitionTypeAnnotation(PropertyDefinitionWithoutTypeAnnotation<'a>) = AncestorType::PropertyDefinitionTypeAnnotation as u16, StaticBlockBody(StaticBlockWithoutBody<'a>) = AncestorType::StaticBlockBody as u16, + AccessorPropertyDecorators(AccessorPropertyWithoutDecorators<'a>) = + AncestorType::AccessorPropertyDecorators as u16, AccessorPropertyKey(AccessorPropertyWithoutKey<'a>) = AncestorType::AccessorPropertyKey as u16, AccessorPropertyValue(AccessorPropertyWithoutValue<'a>) = AncestorType::AccessorPropertyValue as u16, - AccessorPropertyDecorators(AccessorPropertyWithoutDecorators<'a>) = - AncestorType::AccessorPropertyDecorators as u16, ImportExpressionSource(ImportExpressionWithoutSource<'a>) = AncestorType::ImportExpressionSource as u16, ImportExpressionArguments(ImportExpressionWithoutArguments<'a>) = @@ -1254,7 +1254,7 @@ impl<'a> Ancestor<'a> { #[inline] pub fn is_formal_parameter(&self) -> bool { - matches!(self, Self::FormalParameterPattern(_) | Self::FormalParameterDecorators(_)) + matches!(self, Self::FormalParameterDecorators(_) | Self::FormalParameterPattern(_)) } #[inline] @@ -1327,9 +1327,9 @@ impl<'a> Ancestor<'a> { pub fn is_accessor_property(&self) -> bool { matches!( self, - Self::AccessorPropertyKey(_) + Self::AccessorPropertyDecorators(_) + | Self::AccessorPropertyKey(_) | Self::AccessorPropertyValue(_) - | Self::AccessorPropertyDecorators(_) ) } @@ -5726,24 +5726,32 @@ impl<'a> FormalParametersWithoutRest<'a> { } pub(crate) const OFFSET_FORMAL_PARAMETER_SPAN: usize = offset_of!(FormalParameter, span); +pub(crate) const OFFSET_FORMAL_PARAMETER_DECORATORS: usize = + offset_of!(FormalParameter, decorators); pub(crate) const OFFSET_FORMAL_PARAMETER_PATTERN: usize = offset_of!(FormalParameter, pattern); pub(crate) const OFFSET_FORMAL_PARAMETER_ACCESSIBILITY: usize = offset_of!(FormalParameter, accessibility); pub(crate) const OFFSET_FORMAL_PARAMETER_READONLY: usize = offset_of!(FormalParameter, readonly); pub(crate) const OFFSET_FORMAL_PARAMETER_OVERRIDE: usize = offset_of!(FormalParameter, r#override); -pub(crate) const OFFSET_FORMAL_PARAMETER_DECORATORS: usize = - offset_of!(FormalParameter, decorators); #[repr(transparent)] #[derive(Debug)] -pub struct FormalParameterWithoutPattern<'a>(pub(crate) *const FormalParameter<'a>); +pub struct FormalParameterWithoutDecorators<'a>(pub(crate) *const FormalParameter<'a>); -impl<'a> FormalParameterWithoutPattern<'a> { +impl<'a> FormalParameterWithoutDecorators<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { &*((self.0 as *const u8).add(OFFSET_FORMAL_PARAMETER_SPAN) as *const Span) } } + #[inline] + pub fn pattern(&self) -> &BindingPattern<'a> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_FORMAL_PARAMETER_PATTERN) + as *const BindingPattern<'a>) + } + } + #[inline] pub fn accessibility(&self) -> &Option { unsafe { @@ -5761,31 +5769,23 @@ impl<'a> FormalParameterWithoutPattern<'a> { pub fn r#override(&self) -> &bool { unsafe { &*((self.0 as *const u8).add(OFFSET_FORMAL_PARAMETER_OVERRIDE) as *const bool) } } - - #[inline] - pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_FORMAL_PARAMETER_DECORATORS) - as *const Vec<'a, Decorator<'a>>) - } - } } #[repr(transparent)] #[derive(Debug)] -pub struct FormalParameterWithoutDecorators<'a>(pub(crate) *const FormalParameter<'a>); +pub struct FormalParameterWithoutPattern<'a>(pub(crate) *const FormalParameter<'a>); -impl<'a> FormalParameterWithoutDecorators<'a> { +impl<'a> FormalParameterWithoutPattern<'a> { #[inline] pub fn span(&self) -> &Span { unsafe { &*((self.0 as *const u8).add(OFFSET_FORMAL_PARAMETER_SPAN) as *const Span) } } #[inline] - pub fn pattern(&self) -> &BindingPattern<'a> { + pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_FORMAL_PARAMETER_PATTERN) - as *const BindingPattern<'a>) + &*((self.0 as *const u8).add(OFFSET_FORMAL_PARAMETER_DECORATORS) + as *const Vec<'a, Decorator<'a>>) } } @@ -7307,18 +7307,18 @@ impl<'a> StaticBlockWithoutBody<'a> { pub(crate) const OFFSET_ACCESSOR_PROPERTY_TYPE: usize = offset_of!(AccessorProperty, r#type); pub(crate) const OFFSET_ACCESSOR_PROPERTY_SPAN: usize = offset_of!(AccessorProperty, span); +pub(crate) const OFFSET_ACCESSOR_PROPERTY_DECORATORS: usize = + offset_of!(AccessorProperty, decorators); pub(crate) const OFFSET_ACCESSOR_PROPERTY_KEY: usize = offset_of!(AccessorProperty, key); pub(crate) const OFFSET_ACCESSOR_PROPERTY_VALUE: usize = offset_of!(AccessorProperty, value); pub(crate) const OFFSET_ACCESSOR_PROPERTY_COMPUTED: usize = offset_of!(AccessorProperty, computed); pub(crate) const OFFSET_ACCESSOR_PROPERTY_STATIC: usize = offset_of!(AccessorProperty, r#static); -pub(crate) const OFFSET_ACCESSOR_PROPERTY_DECORATORS: usize = - offset_of!(AccessorProperty, decorators); #[repr(transparent)] #[derive(Debug)] -pub struct AccessorPropertyWithoutKey<'a>(pub(crate) *const AccessorProperty<'a>); +pub struct AccessorPropertyWithoutDecorators<'a>(pub(crate) *const AccessorProperty<'a>); -impl<'a> AccessorPropertyWithoutKey<'a> { +impl<'a> AccessorPropertyWithoutDecorators<'a> { #[inline] pub fn r#type(&self) -> &AccessorPropertyType { unsafe { @@ -7332,6 +7332,13 @@ impl<'a> AccessorPropertyWithoutKey<'a> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_SPAN) as *const Span) } } + #[inline] + pub fn key(&self) -> &PropertyKey<'a> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_KEY) as *const PropertyKey<'a>) + } + } + #[inline] pub fn value(&self) -> &Option> { unsafe { @@ -7349,21 +7356,13 @@ impl<'a> AccessorPropertyWithoutKey<'a> { pub fn r#static(&self) -> &bool { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } - - #[inline] - pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DECORATORS) - as *const Vec<'a, Decorator<'a>>) - } - } } #[repr(transparent)] #[derive(Debug)] -pub struct AccessorPropertyWithoutValue<'a>(pub(crate) *const AccessorProperty<'a>); +pub struct AccessorPropertyWithoutKey<'a>(pub(crate) *const AccessorProperty<'a>); -impl<'a> AccessorPropertyWithoutValue<'a> { +impl<'a> AccessorPropertyWithoutKey<'a> { #[inline] pub fn r#type(&self) -> &AccessorPropertyType { unsafe { @@ -7378,9 +7377,18 @@ impl<'a> AccessorPropertyWithoutValue<'a> { } #[inline] - pub fn key(&self) -> &PropertyKey<'a> { + pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_KEY) as *const PropertyKey<'a>) + &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DECORATORS) + as *const Vec<'a, Decorator<'a>>) + } + } + + #[inline] + pub fn value(&self) -> &Option> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_VALUE) + as *const Option>) } } @@ -7393,21 +7401,13 @@ impl<'a> AccessorPropertyWithoutValue<'a> { pub fn r#static(&self) -> &bool { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } - - #[inline] - pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DECORATORS) - as *const Vec<'a, Decorator<'a>>) - } - } } #[repr(transparent)] #[derive(Debug)] -pub struct AccessorPropertyWithoutDecorators<'a>(pub(crate) *const AccessorProperty<'a>); +pub struct AccessorPropertyWithoutValue<'a>(pub(crate) *const AccessorProperty<'a>); -impl<'a> AccessorPropertyWithoutDecorators<'a> { +impl<'a> AccessorPropertyWithoutValue<'a> { #[inline] pub fn r#type(&self) -> &AccessorPropertyType { unsafe { @@ -7422,17 +7422,17 @@ impl<'a> AccessorPropertyWithoutDecorators<'a> { } #[inline] - pub fn key(&self) -> &PropertyKey<'a> { + pub fn decorators(&self) -> &Vec<'a, Decorator<'a>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_KEY) as *const PropertyKey<'a>) + &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_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_ACCESSOR_PROPERTY_VALUE) - as *const Option>) + &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_KEY) as *const PropertyKey<'a>) } } diff --git a/crates/oxc_traverse/src/walk.rs b/crates/oxc_traverse/src/walk.rs index ddba49a48b65..9361a1aa78dd 100644 --- a/crates/oxc_traverse/src/walk.rs +++ b/crates/oxc_traverse/src/walk.rs @@ -2335,19 +2335,21 @@ pub(crate) unsafe fn walk_formal_parameter<'a, Tr: Traverse<'a>>( ctx: &mut TraverseCtx<'a>, ) { traverser.enter_formal_parameter(&mut *node, ctx); - ctx.push_stack(Ancestor::FormalParameterPattern(ancestor::FormalParameterWithoutPattern(node))); - walk_binding_pattern( - traverser, - (node as *mut u8).add(ancestor::OFFSET_FORMAL_PARAMETER_PATTERN) as *mut BindingPattern, - ctx, - ); - ctx.retag_stack(AncestorType::FormalParameterDecorators); + ctx.push_stack(Ancestor::FormalParameterDecorators( + ancestor::FormalParameterWithoutDecorators(node), + )); for item in (*((node as *mut u8).add(ancestor::OFFSET_FORMAL_PARAMETER_DECORATORS) as *mut Vec)) .iter_mut() { walk_decorator(traverser, item as *mut _, ctx); } + ctx.retag_stack(AncestorType::FormalParameterPattern); + walk_binding_pattern( + traverser, + (node as *mut u8).add(ancestor::OFFSET_FORMAL_PARAMETER_PATTERN) as *mut BindingPattern, + ctx, + ); ctx.pop_stack(); traverser.exit_formal_parameter(&mut *node, ctx); } @@ -2695,7 +2697,16 @@ pub(crate) unsafe fn walk_accessor_property<'a, Tr: Traverse<'a>>( ctx: &mut TraverseCtx<'a>, ) { traverser.enter_accessor_property(&mut *node, ctx); - ctx.push_stack(Ancestor::AccessorPropertyKey(ancestor::AccessorPropertyWithoutKey(node))); + ctx.push_stack(Ancestor::AccessorPropertyDecorators( + ancestor::AccessorPropertyWithoutDecorators(node), + )); + for item in (*((node as *mut u8).add(ancestor::OFFSET_ACCESSOR_PROPERTY_DECORATORS) + as *mut Vec)) + .iter_mut() + { + walk_decorator(traverser, item as *mut _, ctx); + } + ctx.retag_stack(AncestorType::AccessorPropertyKey); walk_property_key( traverser, (node as *mut u8).add(ancestor::OFFSET_ACCESSOR_PROPERTY_KEY) as *mut PropertyKey, @@ -2707,13 +2718,6 @@ pub(crate) unsafe fn walk_accessor_property<'a, Tr: Traverse<'a>>( ctx.retag_stack(AncestorType::AccessorPropertyValue); walk_expression(traverser, field as *mut _, ctx); } - ctx.retag_stack(AncestorType::AccessorPropertyDecorators); - for item in (*((node as *mut u8).add(ancestor::OFFSET_ACCESSOR_PROPERTY_DECORATORS) - as *mut Vec)) - .iter_mut() - { - walk_decorator(traverser, item as *mut _, ctx); - } ctx.pop_stack(); traverser.exit_accessor_property(&mut *node, ctx); }