diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index d18389f538439..51bbfe7be7ba8 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -2281,6 +2281,8 @@ pub struct AccessorProperty<'a> { pub computed: bool, /// Property was declared with a `static` modifier pub r#static: bool, + /// Property has a `!` after its key. + pub definite: bool, /// Type annotation on the property. /// /// Will only ever be [`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 e689ef636c567..84f15539af469 100644 --- a/crates/oxc_ast/src/generated/assert_layouts.rs +++ b/crates/oxc_ast/src/generated/assert_layouts.rs @@ -696,6 +696,7 @@ const _: () = { assert!(offset_of!(AccessorProperty, value) == 64usize); assert!(offset_of!(AccessorProperty, computed) == 80usize); assert!(offset_of!(AccessorProperty, r#static) == 81usize); + assert!(offset_of!(AccessorProperty, definite) == 82usize); assert!(offset_of!(AccessorProperty, type_annotation) == 88usize); assert!(size_of::() == 56usize); @@ -2101,6 +2102,7 @@ const _: () = { assert!(offset_of!(AccessorProperty, value) == 36usize); assert!(offset_of!(AccessorProperty, computed) == 44usize); assert!(offset_of!(AccessorProperty, r#static) == 45usize); + assert!(offset_of!(AccessorProperty, definite) == 46usize); assert!(offset_of!(AccessorProperty, type_annotation) == 48usize); assert!(size_of::() == 32usize); diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 6b5c325ea0cb2..d0962c38617cb 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -6496,6 +6496,7 @@ impl<'a> AstBuilder<'a> { /// - value: Initialized value in the declaration, if present. /// - computed: Property was declared with a computed key /// - r#static: Property was declared with a `static` modifier + /// - definite: Property has a `!` after its key. /// - type_annotation: Type annotation on the property. #[inline] pub fn class_element_accessor_property( @@ -6507,6 +6508,7 @@ impl<'a> AstBuilder<'a> { value: Option>, computed: bool, r#static: bool, + definite: bool, type_annotation: T1, ) -> ClassElement<'a> where @@ -6520,6 +6522,7 @@ impl<'a> AstBuilder<'a> { value, computed, r#static, + definite, type_annotation, ))) } @@ -7071,6 +7074,7 @@ impl<'a> AstBuilder<'a> { /// - value: Initialized value in the declaration, if present. /// - computed: Property was declared with a computed key /// - r#static: Property was declared with a `static` modifier + /// - definite: Property has a `!` after its key. /// - type_annotation: Type annotation on the property. #[inline] pub fn accessor_property( @@ -7082,6 +7086,7 @@ impl<'a> AstBuilder<'a> { value: Option>, computed: bool, r#static: bool, + definite: bool, type_annotation: T1, ) -> AccessorProperty<'a> where @@ -7095,6 +7100,7 @@ impl<'a> AstBuilder<'a> { value, computed, r#static, + definite, type_annotation: type_annotation.into_in(self.allocator), } } @@ -7111,6 +7117,7 @@ impl<'a> AstBuilder<'a> { /// - value: Initialized value in the declaration, if present. /// - computed: Property was declared with a computed key /// - r#static: Property was declared with a `static` modifier + /// - definite: Property has a `!` after its key. /// - type_annotation: Type annotation on the property. #[inline] pub fn alloc_accessor_property( @@ -7122,6 +7129,7 @@ impl<'a> AstBuilder<'a> { value: Option>, computed: bool, r#static: bool, + definite: bool, type_annotation: T1, ) -> Box<'a, AccessorProperty<'a>> where @@ -7136,6 +7144,7 @@ impl<'a> AstBuilder<'a> { value, computed, r#static, + definite, type_annotation, ), 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 fc5b279277869..8d50ea3135b93 100644 --- a/crates/oxc_ast/src/generated/derive_clone_in.rs +++ b/crates/oxc_ast/src/generated/derive_clone_in.rs @@ -1954,6 +1954,7 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for AccessorProperty<'old_alloc value: self.value.clone_in(allocator), computed: self.computed.clone_in(allocator), r#static: self.r#static.clone_in(allocator), + definite: self.definite.clone_in(allocator), type_annotation: self.type_annotation.clone_in(allocator), } } diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index 58bffaa898afd..4f60e524a6a55 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -469,6 +469,7 @@ impl<'a> IsolatedDeclarations<'a> { None, property.computed, property.r#static, + property.definite, // SAFETY: `ast.copy` is unsound! We need to fix. unsafe { self.ast.copy(&property.type_annotation) }, ); diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index 50477a9849cb1..3cbcae2888c61 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -294,7 +294,8 @@ impl<'a> ParserImpl<'a> { if optional { self.error(diagnostics::optional_accessor_property(optional_span)); } - self.parse_class_accessor_property(span, key, computed, r#static, r#abstract).map(Some) + self.parse_class_accessor_property(span, key, computed, r#static, r#abstract, definite) + .map(Some) } else if self.at(Kind::LParen) || self.at(Kind::LAngle) || r#async || generator { // LAngle for start of type parameters `foo` // ^ @@ -483,6 +484,7 @@ impl<'a> ParserImpl<'a> { } /// + #[allow(clippy::fn_params_excessive_bools)] fn parse_class_accessor_property( &mut self, span: Span, @@ -490,6 +492,7 @@ impl<'a> ParserImpl<'a> { computed: bool, r#static: bool, r#abstract: bool, + definite: bool, ) -> Result> { let type_annotation = if self.ts_enabled() { self.parse_ts_type_annotation()? } else { None }; @@ -510,6 +513,7 @@ impl<'a> ParserImpl<'a> { value, computed, r#static, + definite, type_annotation, )) } diff --git a/crates/oxc_traverse/src/generated/ancestor.rs b/crates/oxc_traverse/src/generated/ancestor.rs index 5f91d1e5ca78d..5d118a2a99cfa 100644 --- a/crates/oxc_traverse/src/generated/ancestor.rs +++ b/crates/oxc_traverse/src/generated/ancestor.rs @@ -7319,6 +7319,7 @@ pub(crate) const OFFSET_ACCESSOR_PROPERTY_KEY: usize = offset_of!(AccessorProper 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_DEFINITE: usize = offset_of!(AccessorProperty, definite); pub(crate) const OFFSET_ACCESSOR_PROPERTY_TYPE_ANNOTATION: usize = offset_of!(AccessorProperty, type_annotation); @@ -7365,6 +7366,11 @@ impl<'a> AccessorPropertyWithoutDecorators<'a> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + #[inline] + pub fn definite(&self) -> &bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } + } + #[inline] pub fn type_annotation(&self) -> &Option>> { unsafe { @@ -7418,6 +7424,11 @@ impl<'a> AccessorPropertyWithoutKey<'a> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + #[inline] + pub fn definite(&self) -> &bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } + } + #[inline] pub fn type_annotation(&self) -> &Option>> { unsafe { @@ -7470,6 +7481,11 @@ impl<'a> AccessorPropertyWithoutValue<'a> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + #[inline] + pub fn definite(&self) -> &bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } + } + #[inline] pub fn type_annotation(&self) -> &Option>> { unsafe { @@ -7529,6 +7545,11 @@ impl<'a> AccessorPropertyWithoutTypeAnnotation<'a> { pub fn r#static(&self) -> &bool { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + + #[inline] + pub fn definite(&self) -> &bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } + } } pub(crate) const OFFSET_IMPORT_EXPRESSION_SPAN: usize = offset_of!(ImportExpression, span);