From 7ce240c1d64d36e4222f9be6bce5a3c0d70f4f53 Mon Sep 17 00:00:00 2001 From: Yuji Sugiura Date: Tue, 15 Apr 2025 12:15:03 +0900 Subject: [PATCH] feat(ast): Add `override` field in `AccessorProperty` --- crates/oxc_ast/src/ast/js.rs | 5 ++++- .../oxc_ast/src/generated/assert_layouts.rs | 6 +++-- crates/oxc_ast/src/generated/ast_builder.rs | 9 ++++++++ .../oxc_ast/src/generated/derive_clone_in.rs | 2 ++ .../src/generated/derive_content_eq.rs | 1 + crates/oxc_ast/src/generated/derive_dummy.rs | 1 + crates/oxc_ast/src/generated/derive_estree.rs | 2 +- crates/oxc_codegen/src/gen.rs | 5 +++++ crates/oxc_isolated_declarations/src/class.rs | 1 + crates/oxc_parser/src/js/class.rs | 3 +++ crates/oxc_traverse/src/generated/ancestor.rs | 22 +++++++++++++++++++ napi/parser/deserialize-ts.js | 4 ++-- npm/oxc-types/types.d.ts | 2 +- .../coverage/snapshots/estree_typescript.snap | 3 +-- 14 files changed, 57 insertions(+), 9 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index ebced35d3ee10..193b4f6debd42 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -2300,7 +2300,7 @@ pub enum AccessorPropertyType { #[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)] #[rustfmt::skip] #[estree( - add_fields(declare = TsFalse, optional = TsFalse, r#override = TsFalse, readonly = TsFalse), + add_fields(declare = TsFalse, optional = TsFalse, readonly = TsFalse), field_order( r#type, span, key, value, computed, r#static, decorators, definite, type_annotation, accessibility, optional, r#override, readonly, declare) @@ -2321,6 +2321,9 @@ pub struct AccessorProperty<'a> { pub computed: bool, /// Property was declared with a `static` modifier pub r#static: bool, + /// Property was declared with a `override` modifier + #[ts] + pub r#override: bool, /// Property has a `!` after its key. #[ts] pub definite: bool, diff --git a/crates/oxc_ast/src/generated/assert_layouts.rs b/crates/oxc_ast/src/generated/assert_layouts.rs index b5fff75b3c340..06fbd8f952b5d 100644 --- a/crates/oxc_ast/src/generated/assert_layouts.rs +++ b/crates/oxc_ast/src/generated/assert_layouts.rs @@ -656,7 +656,8 @@ const _: () = { assert!(offset_of!(AccessorProperty, value) == 64); assert!(offset_of!(AccessorProperty, computed) == 80); assert!(offset_of!(AccessorProperty, r#static) == 81); - assert!(offset_of!(AccessorProperty, definite) == 82); + assert!(offset_of!(AccessorProperty, r#override) == 82); + assert!(offset_of!(AccessorProperty, definite) == 83); assert!(offset_of!(AccessorProperty, type_annotation) == 88); assert!(offset_of!(AccessorProperty, accessibility) == 96); @@ -2051,7 +2052,8 @@ const _: () = { assert!(offset_of!(AccessorProperty, value) == 36); assert!(offset_of!(AccessorProperty, computed) == 44); assert!(offset_of!(AccessorProperty, r#static) == 45); - assert!(offset_of!(AccessorProperty, definite) == 46); + assert!(offset_of!(AccessorProperty, r#override) == 46); + assert!(offset_of!(AccessorProperty, definite) == 47); assert!(offset_of!(AccessorProperty, type_annotation) == 48); assert!(offset_of!(AccessorProperty, accessibility) == 52); diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 12cb7b3fc31a6..264a2e965b643 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -6693,6 +6693,7 @@ impl<'a> AstBuilder<'a> { /// * `value`: Initialized value in the declaration, if present. /// * `computed`: Property was declared with a computed key /// * `static`: Property was declared with a `static` modifier + /// * `override`: Property was declared with a `override` modifier /// * `definite`: Property has a `!` after its key. /// * `type_annotation`: Type annotation on the property. /// * `accessibility`: Accessibility modifier. @@ -6706,6 +6707,7 @@ impl<'a> AstBuilder<'a> { value: Option>, computed: bool, r#static: bool, + r#override: bool, definite: bool, type_annotation: T1, accessibility: Option, @@ -6721,6 +6723,7 @@ impl<'a> AstBuilder<'a> { value, computed, r#static, + r#override, definite, type_annotation, accessibility, @@ -7250,6 +7253,7 @@ impl<'a> AstBuilder<'a> { /// * `value`: Initialized value in the declaration, if present. /// * `computed`: Property was declared with a computed key /// * `static`: Property was declared with a `static` modifier + /// * `override`: Property was declared with a `override` modifier /// * `definite`: Property has a `!` after its key. /// * `type_annotation`: Type annotation on the property. /// * `accessibility`: Accessibility modifier. @@ -7263,6 +7267,7 @@ impl<'a> AstBuilder<'a> { value: Option>, computed: bool, r#static: bool, + r#override: bool, definite: bool, type_annotation: T1, accessibility: Option, @@ -7278,6 +7283,7 @@ impl<'a> AstBuilder<'a> { value, computed, r#static, + r#override, definite, type_annotation: type_annotation.into_in(self.allocator), accessibility, @@ -7297,6 +7303,7 @@ impl<'a> AstBuilder<'a> { /// * `value`: Initialized value in the declaration, if present. /// * `computed`: Property was declared with a computed key /// * `static`: Property was declared with a `static` modifier + /// * `override`: Property was declared with a `override` modifier /// * `definite`: Property has a `!` after its key. /// * `type_annotation`: Type annotation on the property. /// * `accessibility`: Accessibility modifier. @@ -7310,6 +7317,7 @@ impl<'a> AstBuilder<'a> { value: Option>, computed: bool, r#static: bool, + r#override: bool, definite: bool, type_annotation: T1, accessibility: Option, @@ -7326,6 +7334,7 @@ impl<'a> AstBuilder<'a> { value, computed, r#static, + r#override, definite, type_annotation, accessibility, diff --git a/crates/oxc_ast/src/generated/derive_clone_in.rs b/crates/oxc_ast/src/generated/derive_clone_in.rs index 73184b38f2447..c3b249989f4b1 100644 --- a/crates/oxc_ast/src/generated/derive_clone_in.rs +++ b/crates/oxc_ast/src/generated/derive_clone_in.rs @@ -4072,6 +4072,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for AccessorProperty<'_> { value: CloneIn::clone_in(&self.value, allocator), computed: CloneIn::clone_in(&self.computed, allocator), r#static: CloneIn::clone_in(&self.r#static, allocator), + r#override: CloneIn::clone_in(&self.r#override, allocator), definite: CloneIn::clone_in(&self.definite, allocator), type_annotation: CloneIn::clone_in(&self.type_annotation, allocator), accessibility: CloneIn::clone_in(&self.accessibility, allocator), @@ -4087,6 +4088,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for AccessorProperty<'_> { 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), + r#override: CloneIn::clone_in_with_semantic_ids(&self.r#override, allocator), definite: CloneIn::clone_in_with_semantic_ids(&self.definite, 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 a547be72a139b..9cee357e5fb28 100644 --- a/crates/oxc_ast/src/generated/derive_content_eq.rs +++ b/crates/oxc_ast/src/generated/derive_content_eq.rs @@ -1252,6 +1252,7 @@ impl ContentEq for AccessorProperty<'_> { && ContentEq::content_eq(&self.value, &other.value) && ContentEq::content_eq(&self.computed, &other.computed) && ContentEq::content_eq(&self.r#static, &other.r#static) + && ContentEq::content_eq(&self.r#override, &other.r#override) && ContentEq::content_eq(&self.definite, &other.definite) && 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 f0f550bded168..1dc1d99a756ff 100644 --- a/crates/oxc_ast/src/generated/derive_dummy.rs +++ b/crates/oxc_ast/src/generated/derive_dummy.rs @@ -1345,6 +1345,7 @@ impl<'a> Dummy<'a> for AccessorProperty<'a> { value: Dummy::dummy(allocator), computed: Dummy::dummy(allocator), r#static: Dummy::dummy(allocator), + r#override: Dummy::dummy(allocator), definite: Dummy::dummy(allocator), type_annotation: Dummy::dummy(allocator), accessibility: Dummy::dummy(allocator), diff --git a/crates/oxc_ast/src/generated/derive_estree.rs b/crates/oxc_ast/src/generated/derive_estree.rs index 44b7d09aa9e8e..2dcea11fab9ec 100644 --- a/crates/oxc_ast/src/generated/derive_estree.rs +++ b/crates/oxc_ast/src/generated/derive_estree.rs @@ -1631,7 +1631,7 @@ impl ESTree for AccessorProperty<'_> { state.serialize_ts_field("typeAnnotation", &self.type_annotation); state.serialize_ts_field("accessibility", &self.accessibility); state.serialize_ts_field("optional", &crate::serialize::TsFalse(self)); - state.serialize_ts_field("override", &crate::serialize::TsFalse(self)); + state.serialize_ts_field("override", &self.r#override); state.serialize_ts_field("readonly", &crate::serialize::TsFalse(self)); state.serialize_ts_field("declare", &crate::serialize::TsFalse(self)); state.end(); diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 14bca07471dcb..ab03eae65b628 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2782,6 +2782,11 @@ impl Gen for AccessorProperty<'_> { p.print_str("static"); p.print_soft_space(); } + if self.r#override { + p.print_space_before_identifier(); + p.print_str("override"); + p.print_soft_space(); + } p.print_space_before_identifier(); p.print_str("accessor"); if self.computed { diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index e970731d46955..533e1aff2d52c 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -515,6 +515,7 @@ impl<'a> IsolatedDeclarations<'a> { None, property.computed, property.r#static, + property.r#override, property.definite, type_annotation, property.accessibility, diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index d884e6e0cb05e..7a59ac99ebfc1 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -295,6 +295,7 @@ impl<'a> ParserImpl<'a> { computed, r#static, r#abstract, + r#override, definite, accessibility, ) @@ -498,6 +499,7 @@ impl<'a> ParserImpl<'a> { computed: bool, r#static: bool, r#abstract: bool, + r#override: bool, definite: bool, accessibility: Option, ) -> Result> { @@ -519,6 +521,7 @@ impl<'a> ParserImpl<'a> { value, computed, r#static, + r#override, definite, type_annotation, accessibility, diff --git a/crates/oxc_traverse/src/generated/ancestor.rs b/crates/oxc_traverse/src/generated/ancestor.rs index 31f3954619ce7..d4efb745090de 100644 --- a/crates/oxc_traverse/src/generated/ancestor.rs +++ b/crates/oxc_traverse/src/generated/ancestor.rs @@ -9042,6 +9042,8 @@ 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_OVERRIDE: usize = + offset_of!(AccessorProperty, r#override); 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); @@ -9094,6 +9096,11 @@ impl<'a, 't> AccessorPropertyWithoutDecorators<'a, 't> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + #[inline] + pub fn r#override(self) -> &'t bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_OVERRIDE) as *const bool) } + } + #[inline] pub fn definite(self) -> &'t bool { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } @@ -9170,6 +9177,11 @@ impl<'a, 't> AccessorPropertyWithoutKey<'a, 't> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + #[inline] + pub fn r#override(self) -> &'t bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_OVERRIDE) as *const bool) } + } + #[inline] pub fn definite(self) -> &'t bool { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } @@ -9245,6 +9257,11 @@ impl<'a, 't> AccessorPropertyWithoutValue<'a, 't> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + #[inline] + pub fn r#override(self) -> &'t bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_OVERRIDE) as *const bool) } + } + #[inline] pub fn definite(self) -> &'t bool { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } @@ -9328,6 +9345,11 @@ impl<'a, 't> AccessorPropertyWithoutTypeAnnotation<'a, 't> { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_STATIC) as *const bool) } } + #[inline] + pub fn r#override(self) -> &'t bool { + unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_OVERRIDE) as *const bool) } + } + #[inline] pub fn definite(self) -> &'t bool { unsafe { &*((self.0 as *const u8).add(OFFSET_ACCESSOR_PROPERTY_DEFINITE) as *const bool) } diff --git a/napi/parser/deserialize-ts.js b/napi/parser/deserialize-ts.js index 571aae7ea45d0..ab2ce9d6ed987 100644 --- a/napi/parser/deserialize-ts.js +++ b/napi/parser/deserialize-ts.js @@ -969,11 +969,11 @@ function deserializeAccessorProperty(pos) { computed: deserializeBool(pos + 80), static: deserializeBool(pos + 81), decorators: deserializeVecDecorator(pos + 16), - definite: deserializeBool(pos + 82), + definite: deserializeBool(pos + 83), typeAnnotation: deserializeOptionBoxTSTypeAnnotation(pos + 88), accessibility: deserializeOptionTSAccessibility(pos + 96), optional: false, - override: false, + override: deserializeBool(pos + 82), readonly: false, declare: false, }; diff --git a/npm/oxc-types/types.d.ts b/npm/oxc-types/types.d.ts index 91bbc59daa07b..7a6dd76d1d627 100644 --- a/npm/oxc-types/types.d.ts +++ b/npm/oxc-types/types.d.ts @@ -704,7 +704,7 @@ export interface AccessorProperty extends Span { typeAnnotation?: TSTypeAnnotation | null; accessibility?: TSAccessibility | null; optional?: false; - override?: false; + override?: boolean; readonly?: false; declare?: false; } diff --git a/tasks/coverage/snapshots/estree_typescript.snap b/tasks/coverage/snapshots/estree_typescript.snap index 3fb746d65240d..391a9242053dc 100644 --- a/tasks/coverage/snapshots/estree_typescript.snap +++ b/tasks/coverage/snapshots/estree_typescript.snap @@ -2,7 +2,7 @@ commit: 15392346 estree_typescript Summary: AST Parsed : 10619/10725 (99.01%) -Positive Passed: 8914/10725 (83.11%) +Positive Passed: 8915/10725 (83.12%) Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts A class member cannot have the 'const' keyword. Mismatch: tasks/coverage/typescript/tests/cases/compiler/abstractPropertyInConstructor.ts @@ -1128,7 +1128,6 @@ Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/mixinClasses Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/mixinClassesAnonymous.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationES2022.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/assignParameterPropertyToPropertyDeclarationESNext.ts -Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorAllowedModifiers.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/defineProperty.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/initializationOrdering1.ts Mismatch: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorLocals.ts