diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 4da188efa7af0..23876a7ae2a29 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -2112,6 +2112,13 @@ pub struct PropertyDefinition<'a> { pub decorators: Vec<'a, Decorator<'a>>, /// The expression used to declare the property. pub key: PropertyKey<'a>, + /// Type annotation on the property. + /// + /// e.g. `class Foo { x: number; }` + /// + /// Will only ever be [`Some`] for TypeScript files. + #[ts] + pub type_annotation: Option>>, /// Initialized value in the declaration. /// /// ## Example @@ -2164,11 +2171,6 @@ pub struct PropertyDefinition<'a> { /// `true` when declared with a `readonly` modifier #[ts] pub readonly: bool, - /// Type annotation on the property. - /// - /// Will only ever be [`Some`] for TypeScript files. - #[ts] - pub type_annotation: Option>>, /// Accessibility modifier. /// /// Only ever [`Some`] for TypeScript files. diff --git a/crates/oxc_ast/src/generated/assert_layouts.rs b/crates/oxc_ast/src/generated/assert_layouts.rs index 0ecf88f4fe166..1d15d0767fdfc 100644 --- a/crates/oxc_ast/src/generated/assert_layouts.rs +++ b/crates/oxc_ast/src/generated/assert_layouts.rs @@ -604,22 +604,22 @@ const _: () = { assert!(size_of::() == 1); assert!(align_of::() == 1); - assert!(size_of::() == 104); + assert!(size_of::() == 96); assert!(align_of::() == 8); assert!(offset_of!(PropertyDefinition, span) == 0); assert!(offset_of!(PropertyDefinition, r#type) == 8); assert!(offset_of!(PropertyDefinition, decorators) == 16); assert!(offset_of!(PropertyDefinition, key) == 48); - assert!(offset_of!(PropertyDefinition, value) == 64); - assert!(offset_of!(PropertyDefinition, computed) == 80); - assert!(offset_of!(PropertyDefinition, r#static) == 81); - assert!(offset_of!(PropertyDefinition, declare) == 82); - assert!(offset_of!(PropertyDefinition, r#override) == 83); - assert!(offset_of!(PropertyDefinition, optional) == 84); - assert!(offset_of!(PropertyDefinition, definite) == 85); - assert!(offset_of!(PropertyDefinition, readonly) == 86); - assert!(offset_of!(PropertyDefinition, type_annotation) == 88); - assert!(offset_of!(PropertyDefinition, accessibility) == 96); + assert!(offset_of!(PropertyDefinition, type_annotation) == 64); + assert!(offset_of!(PropertyDefinition, value) == 72); + assert!(offset_of!(PropertyDefinition, computed) == 88); + assert!(offset_of!(PropertyDefinition, r#static) == 89); + assert!(offset_of!(PropertyDefinition, declare) == 90); + assert!(offset_of!(PropertyDefinition, r#override) == 91); + assert!(offset_of!(PropertyDefinition, optional) == 92); + assert!(offset_of!(PropertyDefinition, definite) == 93); + assert!(offset_of!(PropertyDefinition, readonly) == 94); + assert!(offset_of!(PropertyDefinition, accessibility) == 95); assert!(size_of::() == 1); assert!(align_of::() == 1); @@ -1999,22 +1999,22 @@ const _: () = { assert!(size_of::() == 1); assert!(align_of::() == 1); - assert!(size_of::() == 60); + assert!(size_of::() == 56); assert!(align_of::() == 4); assert!(offset_of!(PropertyDefinition, span) == 0); assert!(offset_of!(PropertyDefinition, r#type) == 8); assert!(offset_of!(PropertyDefinition, decorators) == 12); assert!(offset_of!(PropertyDefinition, key) == 28); - assert!(offset_of!(PropertyDefinition, value) == 36); - assert!(offset_of!(PropertyDefinition, computed) == 44); - assert!(offset_of!(PropertyDefinition, r#static) == 45); - assert!(offset_of!(PropertyDefinition, declare) == 46); - assert!(offset_of!(PropertyDefinition, r#override) == 47); - assert!(offset_of!(PropertyDefinition, optional) == 48); - assert!(offset_of!(PropertyDefinition, definite) == 49); - assert!(offset_of!(PropertyDefinition, readonly) == 50); - assert!(offset_of!(PropertyDefinition, type_annotation) == 52); - assert!(offset_of!(PropertyDefinition, accessibility) == 56); + assert!(offset_of!(PropertyDefinition, type_annotation) == 36); + assert!(offset_of!(PropertyDefinition, value) == 40); + assert!(offset_of!(PropertyDefinition, computed) == 48); + assert!(offset_of!(PropertyDefinition, r#static) == 49); + assert!(offset_of!(PropertyDefinition, declare) == 50); + assert!(offset_of!(PropertyDefinition, r#override) == 51); + assert!(offset_of!(PropertyDefinition, optional) == 52); + assert!(offset_of!(PropertyDefinition, definite) == 53); + assert!(offset_of!(PropertyDefinition, readonly) == 54); + assert!(offset_of!(PropertyDefinition, accessibility) == 55); assert!(size_of::() == 1); assert!(align_of::() == 1); diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 13e7ea08e4c72..63b9d77d0d63f 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -6590,6 +6590,7 @@ impl<'a> AstBuilder<'a> { /// * `type` /// * `decorators`: Decorators applied to the property. /// * `key`: The expression used to declare the property. + /// * `type_annotation`: Type annotation on the property. /// * `value`: Initialized value in the declaration. /// * `computed`: Property was declared with a computed key /// * `static`: Property was declared with a `static` modifier @@ -6598,7 +6599,6 @@ impl<'a> AstBuilder<'a> { /// * `optional`: `true` when created with an optional modifier (`?`) /// * `definite` /// * `readonly`: `true` when declared with a `readonly` modifier - /// * `type_annotation`: Type annotation on the property. /// * `accessibility`: Accessibility modifier. #[inline] pub fn class_element_property_definition( @@ -6607,6 +6607,7 @@ impl<'a> AstBuilder<'a> { r#type: PropertyDefinitionType, decorators: Vec<'a, Decorator<'a>>, key: PropertyKey<'a>, + type_annotation: T1, value: Option>, computed: bool, r#static: bool, @@ -6615,7 +6616,6 @@ impl<'a> AstBuilder<'a> { optional: bool, definite: bool, readonly: bool, - type_annotation: T1, accessibility: Option, ) -> ClassElement<'a> where @@ -6626,6 +6626,7 @@ impl<'a> AstBuilder<'a> { r#type, decorators, key, + type_annotation, value, computed, r#static, @@ -6634,7 +6635,6 @@ impl<'a> AstBuilder<'a> { optional, definite, readonly, - type_annotation, accessibility, )) } @@ -6832,6 +6832,7 @@ impl<'a> AstBuilder<'a> { /// * `type` /// * `decorators`: Decorators applied to the property. /// * `key`: The expression used to declare the property. + /// * `type_annotation`: Type annotation on the property. /// * `value`: Initialized value in the declaration. /// * `computed`: Property was declared with a computed key /// * `static`: Property was declared with a `static` modifier @@ -6840,7 +6841,6 @@ impl<'a> AstBuilder<'a> { /// * `optional`: `true` when created with an optional modifier (`?`) /// * `definite` /// * `readonly`: `true` when declared with a `readonly` modifier - /// * `type_annotation`: Type annotation on the property. /// * `accessibility`: Accessibility modifier. #[inline] pub fn property_definition( @@ -6849,6 +6849,7 @@ impl<'a> AstBuilder<'a> { r#type: PropertyDefinitionType, decorators: Vec<'a, Decorator<'a>>, key: PropertyKey<'a>, + type_annotation: T1, value: Option>, computed: bool, r#static: bool, @@ -6857,7 +6858,6 @@ impl<'a> AstBuilder<'a> { optional: bool, definite: bool, readonly: bool, - type_annotation: T1, accessibility: Option, ) -> PropertyDefinition<'a> where @@ -6868,6 +6868,7 @@ impl<'a> AstBuilder<'a> { r#type, decorators, key, + type_annotation: type_annotation.into_in(self.allocator), value, computed, r#static, @@ -6876,7 +6877,6 @@ impl<'a> AstBuilder<'a> { optional, definite, readonly, - type_annotation: type_annotation.into_in(self.allocator), accessibility, } } @@ -6891,6 +6891,7 @@ impl<'a> AstBuilder<'a> { /// * `type` /// * `decorators`: Decorators applied to the property. /// * `key`: The expression used to declare the property. + /// * `type_annotation`: Type annotation on the property. /// * `value`: Initialized value in the declaration. /// * `computed`: Property was declared with a computed key /// * `static`: Property was declared with a `static` modifier @@ -6899,7 +6900,6 @@ impl<'a> AstBuilder<'a> { /// * `optional`: `true` when created with an optional modifier (`?`) /// * `definite` /// * `readonly`: `true` when declared with a `readonly` modifier - /// * `type_annotation`: Type annotation on the property. /// * `accessibility`: Accessibility modifier. #[inline] pub fn alloc_property_definition( @@ -6908,6 +6908,7 @@ impl<'a> AstBuilder<'a> { r#type: PropertyDefinitionType, decorators: Vec<'a, Decorator<'a>>, key: PropertyKey<'a>, + type_annotation: T1, value: Option>, computed: bool, r#static: bool, @@ -6916,7 +6917,6 @@ impl<'a> AstBuilder<'a> { optional: bool, definite: bool, readonly: bool, - type_annotation: T1, accessibility: Option, ) -> Box<'a, PropertyDefinition<'a>> where @@ -6928,6 +6928,7 @@ impl<'a> AstBuilder<'a> { r#type, decorators, key, + type_annotation, value, computed, r#static, @@ -6936,7 +6937,6 @@ impl<'a> AstBuilder<'a> { optional, definite, readonly, - type_annotation, accessibility, ), self.allocator, diff --git a/crates/oxc_ast/src/generated/derive_clone_in.rs b/crates/oxc_ast/src/generated/derive_clone_in.rs index ed49d7a7f47e7..cf45a2be27614 100644 --- a/crates/oxc_ast/src/generated/derive_clone_in.rs +++ b/crates/oxc_ast/src/generated/derive_clone_in.rs @@ -3889,6 +3889,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for PropertyDefinition<'_> { r#type: CloneIn::clone_in(&self.r#type, allocator), decorators: CloneIn::clone_in(&self.decorators, allocator), key: CloneIn::clone_in(&self.key, allocator), + type_annotation: CloneIn::clone_in(&self.type_annotation, allocator), value: CloneIn::clone_in(&self.value, allocator), computed: CloneIn::clone_in(&self.computed, allocator), r#static: CloneIn::clone_in(&self.r#static, allocator), @@ -3897,7 +3898,6 @@ impl<'new_alloc> CloneIn<'new_alloc> for PropertyDefinition<'_> { optional: CloneIn::clone_in(&self.optional, allocator), definite: CloneIn::clone_in(&self.definite, allocator), readonly: CloneIn::clone_in(&self.readonly, allocator), - type_annotation: CloneIn::clone_in(&self.type_annotation, allocator), accessibility: CloneIn::clone_in(&self.accessibility, allocator), } } @@ -3908,6 +3908,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for PropertyDefinition<'_> { r#type: CloneIn::clone_in_with_semantic_ids(&self.r#type, allocator), decorators: CloneIn::clone_in_with_semantic_ids(&self.decorators, allocator), key: CloneIn::clone_in_with_semantic_ids(&self.key, allocator), + type_annotation: CloneIn::clone_in_with_semantic_ids(&self.type_annotation, allocator), value: CloneIn::clone_in_with_semantic_ids(&self.value, allocator), computed: CloneIn::clone_in_with_semantic_ids(&self.computed, allocator), r#static: CloneIn::clone_in_with_semantic_ids(&self.r#static, allocator), @@ -3916,7 +3917,6 @@ impl<'new_alloc> CloneIn<'new_alloc> for PropertyDefinition<'_> { optional: CloneIn::clone_in_with_semantic_ids(&self.optional, allocator), definite: CloneIn::clone_in_with_semantic_ids(&self.definite, allocator), readonly: CloneIn::clone_in_with_semantic_ids(&self.readonly, allocator), - type_annotation: CloneIn::clone_in_with_semantic_ids(&self.type_annotation, allocator), accessibility: CloneIn::clone_in_with_semantic_ids(&self.accessibility, allocator), } } diff --git a/crates/oxc_ast/src/generated/derive_content_eq.rs b/crates/oxc_ast/src/generated/derive_content_eq.rs index 235299899a1e7..66bd4d4a52538 100644 --- a/crates/oxc_ast/src/generated/derive_content_eq.rs +++ b/crates/oxc_ast/src/generated/derive_content_eq.rs @@ -1183,6 +1183,7 @@ impl ContentEq for PropertyDefinition<'_> { ContentEq::content_eq(&self.r#type, &other.r#type) && ContentEq::content_eq(&self.decorators, &other.decorators) && ContentEq::content_eq(&self.key, &other.key) + && ContentEq::content_eq(&self.type_annotation, &other.type_annotation) && ContentEq::content_eq(&self.value, &other.value) && ContentEq::content_eq(&self.computed, &other.computed) && ContentEq::content_eq(&self.r#static, &other.r#static) @@ -1191,7 +1192,6 @@ impl ContentEq for PropertyDefinition<'_> { && ContentEq::content_eq(&self.optional, &other.optional) && ContentEq::content_eq(&self.definite, &other.definite) && ContentEq::content_eq(&self.readonly, &other.readonly) - && ContentEq::content_eq(&self.type_annotation, &other.type_annotation) && ContentEq::content_eq(&self.accessibility, &other.accessibility) } } diff --git a/crates/oxc_ast/src/generated/derive_dummy.rs b/crates/oxc_ast/src/generated/derive_dummy.rs index 559a43d5cfec6..054bc2b8d9d05 100644 --- a/crates/oxc_ast/src/generated/derive_dummy.rs +++ b/crates/oxc_ast/src/generated/derive_dummy.rs @@ -1248,6 +1248,7 @@ impl<'a> Dummy<'a> for PropertyDefinition<'a> { r#type: Dummy::dummy(allocator), decorators: Dummy::dummy(allocator), key: Dummy::dummy(allocator), + type_annotation: Dummy::dummy(allocator), value: Dummy::dummy(allocator), computed: Dummy::dummy(allocator), r#static: Dummy::dummy(allocator), @@ -1256,7 +1257,6 @@ impl<'a> Dummy<'a> for PropertyDefinition<'a> { optional: Dummy::dummy(allocator), definite: Dummy::dummy(allocator), readonly: Dummy::dummy(allocator), - type_annotation: Dummy::dummy(allocator), accessibility: Dummy::dummy(allocator), } } diff --git a/crates/oxc_ast_visit/src/generated/visit.rs b/crates/oxc_ast_visit/src/generated/visit.rs index 0a9148a2cc79f..429f710fc9080 100644 --- a/crates/oxc_ast_visit/src/generated/visit.rs +++ b/crates/oxc_ast_visit/src/generated/visit.rs @@ -2598,12 +2598,12 @@ pub mod walk { visitor.visit_span(&it.span); visitor.visit_decorators(&it.decorators); visitor.visit_property_key(&it.key); - if let Some(value) = &it.value { - visitor.visit_expression(value); - } if let Some(type_annotation) = &it.type_annotation { visitor.visit_ts_type_annotation(type_annotation); } + if let Some(value) = &it.value { + visitor.visit_expression(value); + } visitor.leave_node(kind); } diff --git a/crates/oxc_ast_visit/src/generated/visit_mut.rs b/crates/oxc_ast_visit/src/generated/visit_mut.rs index 0f839efb7169b..dfe95237fd486 100644 --- a/crates/oxc_ast_visit/src/generated/visit_mut.rs +++ b/crates/oxc_ast_visit/src/generated/visit_mut.rs @@ -2687,12 +2687,12 @@ pub mod walk_mut { visitor.visit_span(&mut it.span); visitor.visit_decorators(&mut it.decorators); visitor.visit_property_key(&mut it.key); - if let Some(value) = &mut it.value { - visitor.visit_expression(value); - } if let Some(type_annotation) = &mut it.type_annotation { visitor.visit_ts_type_annotation(type_annotation); } + if let Some(value) = &mut it.value { + visitor.visit_expression(value); + } visitor.leave_node(kind); } diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index 3c38500b60784..0cad42aaeb3e2 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -76,12 +76,12 @@ impl<'a> IsolatedDeclarations<'a> { &self, property: &PropertyDefinition<'a>, ) -> ClassElement<'a> { - let mut type_annotations = None; + let mut type_annotation = None; let mut value = None; if property.accessibility.is_none_or(|a| !a.is_private()) { if property.type_annotation.is_some() { - type_annotations = property.type_annotation.clone_in(self.ast.allocator); + type_annotation = property.type_annotation.clone_in(self.ast.allocator); } else if let Some(expr) = property.value.as_ref() { let ts_type = if property.readonly { // `field = 'string'` remain `field = 'string'` instead of `field: 'string'` @@ -101,10 +101,10 @@ impl<'a> IsolatedDeclarations<'a> { self.infer_type_from_expression(expr) }; - type_annotations = ts_type.map(|t| self.ast.alloc_ts_type_annotation(SPAN, t)); + type_annotation = ts_type.map(|t| self.ast.alloc_ts_type_annotation(SPAN, t)); } - if type_annotations.is_none() && value.is_none() { + if type_annotation.is_none() && value.is_none() { self.error(property_must_have_explicit_type(property.key.span())); } } @@ -114,6 +114,7 @@ impl<'a> IsolatedDeclarations<'a> { property.r#type, self.ast.vec(), property.key.clone_in(self.ast.allocator), + type_annotation, value, property.computed, property.r#static, @@ -122,7 +123,6 @@ impl<'a> IsolatedDeclarations<'a> { property.optional, property.definite, property.readonly, - type_annotations, Self::transform_accessibility(property.accessibility), ) } @@ -178,6 +178,7 @@ impl<'a> IsolatedDeclarations<'a> { r#type, self.ast.vec(), key, + NONE, None, false, r#static, @@ -186,7 +187,6 @@ impl<'a> IsolatedDeclarations<'a> { false, false, false, - NONE, accessibility, ) } @@ -206,6 +206,7 @@ impl<'a> IsolatedDeclarations<'a> { PropertyDefinitionType::PropertyDefinition, self.ast.vec(), key, + type_annotation, None, false, false, @@ -214,7 +215,6 @@ impl<'a> IsolatedDeclarations<'a> { param.pattern.optional, false, param.readonly, - type_annotation, Self::transform_accessibility(param.accessibility), )) } @@ -540,8 +540,8 @@ impl<'a> IsolatedDeclarations<'a> { let r#type = PropertyDefinitionType::PropertyDefinition; let decorators = self.ast.vec(); let element = self.ast.class_element_property_definition( - SPAN, r#type, decorators, ident, None, false, false, false, false, false, false, - false, NONE, None, + SPAN, r#type, decorators, ident, NONE, None, false, false, false, false, false, + false, false, None, ); elements.insert(0, element); diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index e1840bd5c1124..f58622d8f5849 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -482,6 +482,7 @@ impl<'a> ParserImpl<'a> { r#type, decorators, key, + type_annotation, value, computed, r#static, @@ -490,7 +491,6 @@ impl<'a> ParserImpl<'a> { optional, definite, readonly, - type_annotation, accessibility, ) } diff --git a/crates/oxc_transformer/src/es2022/class_static_block.rs b/crates/oxc_transformer/src/es2022/class_static_block.rs index d714355de5cde..42a6290d74dcb 100644 --- a/crates/oxc_transformer/src/es2022/class_static_block.rs +++ b/crates/oxc_transformer/src/es2022/class_static_block.rs @@ -116,6 +116,7 @@ impl ClassStaticBlock { PropertyDefinitionType::PropertyDefinition, ctx.ast.vec(), key, + NONE, Some(expr), false, true, @@ -124,7 +125,6 @@ impl ClassStaticBlock { false, false, false, - NONE, None, ) } diff --git a/crates/oxc_traverse/src/generated/ancestor.rs b/crates/oxc_traverse/src/generated/ancestor.rs index 244a1d5df3aff..bce5a26c7dba3 100644 --- a/crates/oxc_traverse/src/generated/ancestor.rs +++ b/crates/oxc_traverse/src/generated/ancestor.rs @@ -158,8 +158,8 @@ pub(crate) enum AncestorType { MethodDefinitionValue = 135, PropertyDefinitionDecorators = 136, PropertyDefinitionKey = 137, - PropertyDefinitionValue = 138, - PropertyDefinitionTypeAnnotation = 139, + PropertyDefinitionTypeAnnotation = 138, + PropertyDefinitionValue = 139, StaticBlockBody = 140, AccessorPropertyDecorators = 141, AccessorPropertyKey = 142, @@ -577,10 +577,10 @@ pub enum Ancestor<'a, 't> { AncestorType::PropertyDefinitionDecorators as u16, PropertyDefinitionKey(PropertyDefinitionWithoutKey<'a, 't>) = AncestorType::PropertyDefinitionKey as u16, - PropertyDefinitionValue(PropertyDefinitionWithoutValue<'a, 't>) = - AncestorType::PropertyDefinitionValue as u16, PropertyDefinitionTypeAnnotation(PropertyDefinitionWithoutTypeAnnotation<'a, 't>) = AncestorType::PropertyDefinitionTypeAnnotation as u16, + PropertyDefinitionValue(PropertyDefinitionWithoutValue<'a, 't>) = + AncestorType::PropertyDefinitionValue as u16, StaticBlockBody(StaticBlockWithoutBody<'a, 't>) = AncestorType::StaticBlockBody as u16, AccessorPropertyDecorators(AccessorPropertyWithoutDecorators<'a, 't>) = AncestorType::AccessorPropertyDecorators as u16, @@ -1324,8 +1324,8 @@ impl<'a, 't> Ancestor<'a, 't> { self, Self::PropertyDefinitionDecorators(_) | Self::PropertyDefinitionKey(_) - | Self::PropertyDefinitionValue(_) | Self::PropertyDefinitionTypeAnnotation(_) + | Self::PropertyDefinitionValue(_) ) } @@ -2335,8 +2335,8 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> { Self::MethodDefinitionValue(a) => a.address(), Self::PropertyDefinitionDecorators(a) => a.address(), Self::PropertyDefinitionKey(a) => a.address(), - Self::PropertyDefinitionValue(a) => a.address(), Self::PropertyDefinitionTypeAnnotation(a) => a.address(), + Self::PropertyDefinitionValue(a) => a.address(), Self::StaticBlockBody(a) => a.address(), Self::AccessorPropertyDecorators(a) => a.address(), Self::AccessorPropertyKey(a) => a.address(), @@ -8562,6 +8562,8 @@ pub(crate) const OFFSET_PROPERTY_DEFINITION_TYPE: usize = offset_of!(PropertyDef 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_TYPE_ANNOTATION: usize = + offset_of!(PropertyDefinition, type_annotation); pub(crate) const OFFSET_PROPERTY_DEFINITION_VALUE: usize = offset_of!(PropertyDefinition, value); pub(crate) const OFFSET_PROPERTY_DEFINITION_COMPUTED: usize = offset_of!(PropertyDefinition, computed); @@ -8577,8 +8579,6 @@ pub(crate) const OFFSET_PROPERTY_DEFINITION_DEFINITE: usize = offset_of!(PropertyDefinition, definite); pub(crate) const OFFSET_PROPERTY_DEFINITION_READONLY: usize = offset_of!(PropertyDefinition, readonly); -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); @@ -8610,6 +8610,14 @@ impl<'a, 't> PropertyDefinitionWithoutDecorators<'a, 't> { } } + #[inline] + pub fn type_annotation(self) -> &'t Option>> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) + as *const Option>>) + } + } + #[inline] pub fn value(self) -> &'t Option> { unsafe { @@ -8653,14 +8661,6 @@ impl<'a, 't> PropertyDefinitionWithoutDecorators<'a, 't> { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_READONLY) as *const bool) } } - #[inline] - pub fn type_annotation(self) -> &'t Option>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) - as *const Option>>) - } - } - #[inline] pub fn accessibility(self) -> &'t Option { unsafe { @@ -8706,6 +8706,14 @@ impl<'a, 't> PropertyDefinitionWithoutKey<'a, 't> { } } + #[inline] + pub fn type_annotation(self) -> &'t Option>> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) + as *const Option>>) + } + } + #[inline] pub fn value(self) -> &'t Option> { unsafe { @@ -8749,14 +8757,6 @@ impl<'a, 't> PropertyDefinitionWithoutKey<'a, 't> { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_READONLY) as *const bool) } } - #[inline] - pub fn type_annotation(self) -> &'t Option>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) - as *const Option>>) - } - } - #[inline] pub fn accessibility(self) -> &'t Option { unsafe { @@ -8775,12 +8775,12 @@ impl<'a, 't> GetAddress for PropertyDefinitionWithoutKey<'a, 't> { #[repr(transparent)] #[derive(Clone, Copy, Debug)] -pub struct PropertyDefinitionWithoutValue<'a, 't>( +pub struct PropertyDefinitionWithoutTypeAnnotation<'a, 't>( pub(crate) *const PropertyDefinition<'a>, pub(crate) PhantomData<&'t ()>, ); -impl<'a, 't> PropertyDefinitionWithoutValue<'a, 't> { +impl<'a, 't> PropertyDefinitionWithoutTypeAnnotation<'a, 't> { #[inline] pub fn span(self) -> &'t Span { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_SPAN) as *const Span) } @@ -8809,6 +8809,14 @@ impl<'a, 't> PropertyDefinitionWithoutValue<'a, 't> { } } + #[inline] + pub fn value(self) -> &'t Option> { + unsafe { + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_VALUE) + as *const Option>) + } + } + #[inline] pub fn computed(self) -> &'t bool { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_COMPUTED) as *const bool) } @@ -8844,14 +8852,6 @@ impl<'a, 't> PropertyDefinitionWithoutValue<'a, 't> { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_READONLY) as *const bool) } } - #[inline] - pub fn type_annotation(self) -> &'t Option>> { - unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) - as *const Option>>) - } - } - #[inline] pub fn accessibility(self) -> &'t Option { unsafe { @@ -8861,7 +8861,7 @@ impl<'a, 't> PropertyDefinitionWithoutValue<'a, 't> { } } -impl<'a, 't> GetAddress for PropertyDefinitionWithoutValue<'a, 't> { +impl<'a, 't> GetAddress for PropertyDefinitionWithoutTypeAnnotation<'a, 't> { #[inline] fn address(&self) -> Address { Address::from_ptr(self.0) @@ -8870,12 +8870,12 @@ impl<'a, 't> GetAddress for PropertyDefinitionWithoutValue<'a, 't> { #[repr(transparent)] #[derive(Clone, Copy, Debug)] -pub struct PropertyDefinitionWithoutTypeAnnotation<'a, 't>( +pub struct PropertyDefinitionWithoutValue<'a, 't>( pub(crate) *const PropertyDefinition<'a>, pub(crate) PhantomData<&'t ()>, ); -impl<'a, 't> PropertyDefinitionWithoutTypeAnnotation<'a, 't> { +impl<'a, 't> PropertyDefinitionWithoutValue<'a, 't> { #[inline] pub fn span(self) -> &'t Span { unsafe { &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_SPAN) as *const Span) } @@ -8905,10 +8905,10 @@ impl<'a, 't> PropertyDefinitionWithoutTypeAnnotation<'a, 't> { } #[inline] - pub fn value(self) -> &'t Option> { + pub fn type_annotation(self) -> &'t Option>> { unsafe { - &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_VALUE) - as *const Option>) + &*((self.0 as *const u8).add(OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) + as *const Option>>) } } @@ -8956,7 +8956,7 @@ impl<'a, 't> PropertyDefinitionWithoutTypeAnnotation<'a, 't> { } } -impl<'a, 't> GetAddress for PropertyDefinitionWithoutTypeAnnotation<'a, 't> { +impl<'a, 't> GetAddress for PropertyDefinitionWithoutValue<'a, 't> { #[inline] fn address(&self) -> Address { Address::from_ptr(self.0) diff --git a/crates/oxc_traverse/src/generated/scopes_collector.rs b/crates/oxc_traverse/src/generated/scopes_collector.rs index cad9220cd779d..243699e951906 100644 --- a/crates/oxc_traverse/src/generated/scopes_collector.rs +++ b/crates/oxc_traverse/src/generated/scopes_collector.rs @@ -1006,12 +1006,12 @@ impl<'a> Visit<'a> for ChildScopeCollector { fn visit_property_definition(&mut self, it: &PropertyDefinition<'a>) { self.visit_decorators(&it.decorators); self.visit_property_key(&it.key); - if let Some(value) = &it.value { - self.visit_expression(value); - } if let Some(type_annotation) = &it.type_annotation { self.visit_ts_type_annotation(type_annotation); } + if let Some(value) = &it.value { + self.visit_expression(value); + } } #[inline(always)] diff --git a/crates/oxc_traverse/src/generated/walk.rs b/crates/oxc_traverse/src/generated/walk.rs index 8e843340f2b2f..7b1597cf7a268 100644 --- a/crates/oxc_traverse/src/generated/walk.rs +++ b/crates/oxc_traverse/src/generated/walk.rs @@ -2621,12 +2621,6 @@ unsafe fn walk_property_definition<'a, Tr: Traverse<'a>>( (node as *mut u8).add(ancestor::OFFSET_PROPERTY_DEFINITION_KEY) as *mut PropertyKey, ctx, ); - if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_PROPERTY_DEFINITION_VALUE) - as *mut Option) - { - ctx.retag_stack(AncestorType::PropertyDefinitionValue); - walk_expression(traverser, field as *mut _, ctx); - } if let Some(field) = &mut *((node as *mut u8) .add(ancestor::OFFSET_PROPERTY_DEFINITION_TYPE_ANNOTATION) as *mut Option>) @@ -2634,6 +2628,12 @@ unsafe fn walk_property_definition<'a, Tr: Traverse<'a>>( ctx.retag_stack(AncestorType::PropertyDefinitionTypeAnnotation); walk_ts_type_annotation(traverser, (&mut **field) as *mut _, ctx); } + if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_PROPERTY_DEFINITION_VALUE) + as *mut Option) + { + ctx.retag_stack(AncestorType::PropertyDefinitionValue); + walk_expression(traverser, field as *mut _, ctx); + } ctx.pop_stack(pop_token); traverser.exit_property_definition(&mut *node, ctx); } diff --git a/napi/parser/generated/deserialize/js.js b/napi/parser/generated/deserialize/js.js index 0a57d5937d520..e29a34c1033d9 100644 --- a/napi/parser/generated/deserialize/js.js +++ b/napi/parser/generated/deserialize/js.js @@ -866,10 +866,10 @@ function deserializePropertyDefinition(pos) { type: deserializePropertyDefinitionType(pos + 8), start: deserializeU32(pos), end: deserializeU32(pos + 4), - static: deserializeBool(pos + 81), - computed: deserializeBool(pos + 80), + static: deserializeBool(pos + 89), + computed: deserializeBool(pos + 88), key: deserializePropertyKey(pos + 48), - value: deserializeOptionExpression(pos + 64), + value: deserializeOptionExpression(pos + 72), }; } diff --git a/napi/parser/generated/deserialize/ts.js b/napi/parser/generated/deserialize/ts.js index ae7c932dec5ca..924a6185d5e06 100644 --- a/napi/parser/generated/deserialize/ts.js +++ b/napi/parser/generated/deserialize/ts.js @@ -997,18 +997,18 @@ function deserializePropertyDefinition(pos) { type: deserializePropertyDefinitionType(pos + 8), start: deserializeU32(pos), end: deserializeU32(pos + 4), - static: deserializeBool(pos + 81), - computed: deserializeBool(pos + 80), + static: deserializeBool(pos + 89), + computed: deserializeBool(pos + 88), key: deserializePropertyKey(pos + 48), - value: deserializeOptionExpression(pos + 64), + value: deserializeOptionExpression(pos + 72), decorators: deserializeVecDecorator(pos + 16), - declare: deserializeBool(pos + 82), - override: deserializeBool(pos + 83), - optional: deserializeBool(pos + 84), - definite: deserializeBool(pos + 85), - readonly: deserializeBool(pos + 86), - typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 88), - accessibility: deserializeOptionTSAccessibility(pos + 96), + declare: deserializeBool(pos + 90), + override: deserializeBool(pos + 91), + optional: deserializeBool(pos + 92), + definite: deserializeBool(pos + 93), + readonly: deserializeBool(pos + 94), + typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 64), + accessibility: deserializeOptionTSAccessibility(pos + 95), }; } diff --git a/tasks/coverage/snapshots/semantic_typescript.snap b/tasks/coverage/snapshots/semantic_typescript.snap index f1634f44f585e..c512ec724f781 100644 --- a/tasks/coverage/snapshots/semantic_typescript.snap +++ b/tasks/coverage/snapshots/semantic_typescript.snap @@ -5210,7 +5210,7 @@ rebuilt : ScopeId(0): [ScopeId(1)] semantic Error: tasks/coverage/typescript/tests/cases/compiler/contextualTyping14.ts Scope children mismatch: -after transform: ScopeId(1): [ScopeId(3), ScopeId(4)] +after transform: ScopeId(1): [ScopeId(2), ScopeId(4)] rebuilt : ScopeId(1): [ScopeId(2)] semantic Error: tasks/coverage/typescript/tests/cases/compiler/contextualTyping22.ts @@ -12469,7 +12469,7 @@ Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(4), ScopeId(5)] rebuilt : ScopeId(0): [ScopeId(1), ScopeId(4)] Scope children mismatch: -after transform: ScopeId(1): [ScopeId(3), ScopeId(6)] +after transform: ScopeId(1): [ScopeId(2), ScopeId(6)] rebuilt : ScopeId(1): [ScopeId(2)] semantic Error: tasks/coverage/typescript/tests/cases/compiler/es6ClassTest7.ts @@ -15582,7 +15582,7 @@ rebuilt : [] semantic Error: tasks/coverage/typescript/tests/cases/compiler/getAndSetAsMemberNames.ts Scope children mismatch: -after transform: ScopeId(6): [ScopeId(8), ScopeId(9), ScopeId(10), ScopeId(14)] +after transform: ScopeId(6): [ScopeId(7), ScopeId(9), ScopeId(10), ScopeId(14)] rebuilt : ScopeId(9): [ScopeId(10), ScopeId(12), ScopeId(13)] semantic Error: tasks/coverage/typescript/tests/cases/compiler/getParameterNameAtPosition.ts @@ -19027,7 +19027,7 @@ Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(4), ScopeId(7), ScopeId(8)] rebuilt : ScopeId(0): [ScopeId(1), ScopeId(4)] Scope children mismatch: -after transform: ScopeId(4): [ScopeId(6), ScopeId(9)] +after transform: ScopeId(4): [ScopeId(5), ScopeId(9)] rebuilt : ScopeId(1): [ScopeId(2)] Symbol reference IDs mismatch for "TestObject": after transform: SymbolId(4): [ReferenceId(11), ReferenceId(15)] @@ -19302,7 +19302,7 @@ Symbol span mismatch for "Editor": after transform: SymbolId(0): Span { start: 7, end: 13 } rebuilt : SymbolId(1): Span { start: 0, end: 0 } Symbol reference IDs mismatch for "List": -after transform: SymbolId(13): [ReferenceId(2), ReferenceId(4), ReferenceId(10), ReferenceId(12), ReferenceId(15), ReferenceId(18), ReferenceId(20), ReferenceId(23), ReferenceId(27), ReferenceId(29)] +after transform: SymbolId(13): [ReferenceId(0), ReferenceId(4), ReferenceId(10), ReferenceId(12), ReferenceId(15), ReferenceId(18), ReferenceId(20), ReferenceId(23), ReferenceId(27), ReferenceId(29)] rebuilt : SymbolId(12): [] Symbol reference IDs mismatch for "Line": after transform: SymbolId(17): [ReferenceId(1), ReferenceId(3), ReferenceId(5), ReferenceId(6), ReferenceId(7), ReferenceId(41)] @@ -29532,7 +29532,7 @@ rebuilt : ["B"] semantic Error: tasks/coverage/typescript/tests/cases/compiler/superElementAccess.ts Scope children mismatch: -after transform: ScopeId(1): [ScopeId(2), ScopeId(3), ScopeId(5), ScopeId(6), ScopeId(7), ScopeId(12)] +after transform: ScopeId(1): [ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(6), ScopeId(7), ScopeId(12)] rebuilt : ScopeId(1): [ScopeId(2), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7)] Scope children mismatch: after transform: ScopeId(9): [ScopeId(10), ScopeId(11)] @@ -30032,7 +30032,7 @@ rebuilt : SymbolId(0): Span { start: 0, end: 0 } semantic Error: tasks/coverage/typescript/tests/cases/compiler/thisInPropertyBoundDeclarations.ts Symbol reference IDs mismatch for "Bug": -after transform: SymbolId(0): [ReferenceId(0), ReferenceId(6)] +after transform: SymbolId(0): [ReferenceId(1), ReferenceId(6)] rebuilt : SymbolId(1): [ReferenceId(4)] Unresolved references mismatch: after transform: ["Function", "require"] @@ -34623,7 +34623,7 @@ rebuilt : ScopeId(7): ScopeFlags(Function) semantic Error: tasks/coverage/typescript/tests/cases/conformance/classes/members/privateNames/privateNamesAssertion.ts Scope children mismatch: -after transform: ScopeId(1): [ScopeId(4), ScopeId(5), ScopeId(10)] +after transform: ScopeId(1): [ScopeId(2), ScopeId(5), ScopeId(10)] rebuilt : ScopeId(1): [ScopeId(2), ScopeId(5)] Scope flags mismatch: after transform: ScopeId(8): ScopeFlags(StrictMode)