From 3efbbb2e1f738c1d75c7fcda8e95c46a8dec03f0 Mon Sep 17 00:00:00 2001 From: Boshen Date: Wed, 28 Feb 2024 17:33:11 +0800 Subject: [PATCH] feat(ast): add "abstract" type to `MethodDefinition` and `PropertyDefinition` (#2536) closes #2532 ``` pub enum PropertyDefinitionType { PropertyDefinition, TSAbstractPropertyDefinition, } pub enum MethodDefinitionType { MethodDefinition, TSAbstractMethodDefinition, } ``` --- crates/oxc_ast/src/ast/js.rs | 58 +++++++++---------- crates/oxc_ast/src/ast/ts.rs | 24 -------- crates/oxc_ast/src/ast_builder.rs | 3 + crates/oxc_ast/src/span.rs | 2 - .../private_bound_identifiers.rs | 6 -- .../syntax_directed_operations/prop_name.rs | 2 - crates/oxc_ast/src/visit.rs | 6 -- crates/oxc_ast/src/visit_mut.rs | 6 -- crates/oxc_codegen/src/gen.rs | 14 +++-- crates/oxc_codegen/src/gen_ts.rs | 21 ------- .../src/rules/unicorn/no_static_only_class.rs | 10 ---- crates/oxc_parser/src/js/class.rs | 30 +++++----- crates/oxc_prettier/src/format/class.rs | 21 ------- crates/oxc_prettier/src/format/mod.rs | 14 ----- .../src/es2022/class_static_block.rs | 4 +- tasks/coverage/prettier_babel.snap | 6 +- tasks/coverage/prettier_typescript.snap | 5 +- 17 files changed, 57 insertions(+), 175 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 9cfd174c1..cde41b466 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1948,8 +1948,6 @@ pub enum ClassElement<'a> { MethodDefinition(Box<'a, MethodDefinition<'a>>), PropertyDefinition(Box<'a, PropertyDefinition<'a>>), AccessorProperty(Box<'a, AccessorProperty<'a>>), - TSAbstractMethodDefinition(Box<'a, TSAbstractMethodDefinition<'a>>), - TSAbstractPropertyDefinition(Box<'a, TSAbstractPropertyDefinition<'a>>), TSIndexSignature(Box<'a, TSIndexSignature<'a>>), } @@ -1960,8 +1958,6 @@ impl<'a> ClassElement<'a> { Self::MethodDefinition(def) => def.r#static, Self::PropertyDefinition(def) => def.r#static, Self::AccessorProperty(def) => def.r#static, - Self::TSAbstractMethodDefinition(def) => def.method_definition.r#static, - Self::TSAbstractPropertyDefinition(def) => def.property_definition.r#static, } } @@ -1971,8 +1967,6 @@ impl<'a> ClassElement<'a> { Self::MethodDefinition(def) => def.computed, Self::PropertyDefinition(def) => def.computed, Self::AccessorProperty(def) => def.computed, - Self::TSAbstractMethodDefinition(def) => def.method_definition.computed, - Self::TSAbstractPropertyDefinition(def) => def.property_definition.computed, } } @@ -1981,8 +1975,6 @@ impl<'a> ClassElement<'a> { Self::StaticBlock(_) | Self::TSIndexSignature(_) | Self::AccessorProperty(_) => None, Self::MethodDefinition(def) => def.accessibility, Self::PropertyDefinition(def) => def.accessibility, - Self::TSAbstractMethodDefinition(def) => def.method_definition.accessibility, - Self::TSAbstractPropertyDefinition(def) => def.property_definition.accessibility, } } @@ -1993,8 +1985,6 @@ impl<'a> ClassElement<'a> { | Self::PropertyDefinition(_) | Self::AccessorProperty(_) => None, Self::MethodDefinition(def) => Some(def.kind), - Self::TSAbstractMethodDefinition(def) => Some(def.method_definition.kind), - Self::TSAbstractPropertyDefinition(_def) => None, } } @@ -2004,8 +1994,6 @@ impl<'a> ClassElement<'a> { Self::MethodDefinition(def) => Some(&def.key), Self::PropertyDefinition(def) => Some(&def.key), Self::AccessorProperty(def) => Some(&def.key), - Self::TSAbstractMethodDefinition(def) => Some(&def.method_definition.key), - Self::TSAbstractPropertyDefinition(def) => Some(&def.property_definition.key), } } @@ -2015,18 +2003,11 @@ impl<'a> ClassElement<'a> { Self::MethodDefinition(def) => def.key.static_name(), Self::PropertyDefinition(def) => def.key.static_name(), Self::AccessorProperty(def) => def.key.static_name(), - Self::TSAbstractMethodDefinition(_def) => None, - Self::TSAbstractPropertyDefinition(_def) => None, } } pub fn is_property(&self) -> bool { - matches!( - self, - Self::PropertyDefinition(_) - | Self::AccessorProperty(_) - | Self::TSAbstractPropertyDefinition(_) - ) + matches!(self, Self::PropertyDefinition(_) | Self::AccessorProperty(_)) } pub fn is_ts_empty_body_function(&self) -> bool { @@ -2034,20 +2015,18 @@ impl<'a> ClassElement<'a> { Self::PropertyDefinition(_) | Self::StaticBlock(_) | Self::AccessorProperty(_) - | Self::TSAbstractPropertyDefinition(_) | Self::TSIndexSignature(_) => false, Self::MethodDefinition(method) => method.value.body.is_none(), - Self::TSAbstractMethodDefinition(_) => true, } } pub fn is_typescript_syntax(&self) -> bool { match self { - Self::TSIndexSignature(_) - | Self::TSAbstractMethodDefinition(_) - | Self::TSAbstractPropertyDefinition(_) => true, + Self::TSIndexSignature(_) => true, Self::MethodDefinition(method) => method.value.is_typescript_syntax(), - Self::PropertyDefinition(property) => property.declare, + Self::PropertyDefinition(property) => { + property.r#type == PropertyDefinitionType::TSAbstractPropertyDefinition + } _ => false, } } @@ -2057,18 +2036,16 @@ impl<'a> ClassElement<'a> { Self::MethodDefinition(method) => !method.decorators.is_empty(), Self::PropertyDefinition(property) => !property.decorators.is_empty(), Self::AccessorProperty(property) => !property.decorators.is_empty(), - Self::StaticBlock(_) - | Self::TSIndexSignature(_) - | Self::TSAbstractMethodDefinition(_) - | Self::TSAbstractPropertyDefinition(_) => false, + Self::StaticBlock(_) | Self::TSIndexSignature(_) => false, } } } #[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct MethodDefinition<'a> { + pub r#type: MethodDefinitionType, #[cfg_attr(feature = "serde", serde(flatten))] pub span: Span, pub key: PropertyKey<'a>, @@ -2082,10 +2059,19 @@ pub struct MethodDefinition<'a> { pub decorators: Vec<'a, Decorator<'a>>, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] +pub enum MethodDefinitionType { + MethodDefinition, + TSAbstractMethodDefinition, +} + #[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] +#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] pub struct PropertyDefinition<'a> { + pub r#type: PropertyDefinitionType, #[cfg_attr(feature = "serde", serde(flatten))] pub span: Span, pub key: PropertyKey<'a>, @@ -2102,6 +2088,14 @@ pub struct PropertyDefinition<'a> { pub decorators: Vec<'a, Decorator<'a>>, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +#[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] +pub enum PropertyDefinitionType { + PropertyDefinition, + TSAbstractPropertyDefinition, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "lowercase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index 0ac3a8414..c25414ba4 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -11,16 +11,6 @@ use serde::Serialize; #[allow(clippy::wildcard_imports)] use crate::ast::*; -#[cfg_attr( - all(feature = "serde", feature = "wasm"), - wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section) -)] -#[allow(dead_code)] -const TS_APPEND_CONTENT: &'static str = r#" -export interface TSAbstractPropertyDefinition extends Omit {} -export interface TSAbstractMethodDefinition extends Omit {} -"#; - #[derive(Debug, Hash)] #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] @@ -504,20 +494,6 @@ pub struct TSTypeAliasDeclaration<'a> { pub modifiers: Modifiers<'a>, } -#[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] -pub struct TSAbstractMethodDefinition<'a> { - #[cfg_attr(feature = "serde", serde(flatten))] - pub method_definition: MethodDefinition<'a>, -} - -#[derive(Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "camelCase"))] -pub struct TSAbstractPropertyDefinition<'a> { - #[cfg_attr(feature = "serde", serde(flatten))] - pub property_definition: PropertyDefinition<'a>, -} - #[derive(Debug, Hash, Clone, PartialEq, Eq, Copy)] #[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "lowercase"))] #[cfg_attr(all(feature = "serde", feature = "wasm"), derive(tsify::Tsify))] diff --git a/crates/oxc_ast/src/ast_builder.rs b/crates/oxc_ast/src/ast_builder.rs index 7ae07e814..648ca6c5a 100644 --- a/crates/oxc_ast/src/ast_builder.rs +++ b/crates/oxc_ast/src/ast_builder.rs @@ -895,6 +895,7 @@ impl<'a> AstBuilder<'a> { pub fn class_property( &self, + r#type: PropertyDefinitionType, span: Span, key: PropertyKey<'a>, value: Option>, @@ -903,6 +904,7 @@ impl<'a> AstBuilder<'a> { decorators: Vec<'a, Decorator<'a>>, ) -> ClassElement<'a> { ClassElement::PropertyDefinition(self.alloc(PropertyDefinition { + r#type, span, key, value, @@ -921,6 +923,7 @@ impl<'a> AstBuilder<'a> { pub fn class_constructor(&self, span: Span, value: Box<'a, Function<'a>>) -> ClassElement<'a> { ClassElement::MethodDefinition(self.alloc(MethodDefinition { + r#type: MethodDefinitionType::MethodDefinition, span, key: self.property_key_expression(self.identifier_reference_expression( IdentifierReference::new(SPAN, "constructor".into()), diff --git a/crates/oxc_ast/src/span.rs b/crates/oxc_ast/src/span.rs index fe8a8a5cb..8ca48f9b8 100644 --- a/crates/oxc_ast/src/span.rs +++ b/crates/oxc_ast/src/span.rs @@ -117,8 +117,6 @@ impl<'a> GetSpan for ClassElement<'a> { Self::MethodDefinition(def) => def.span, Self::PropertyDefinition(def) => def.span, Self::AccessorProperty(def) => def.span, - Self::TSAbstractMethodDefinition(def) => def.method_definition.span, - Self::TSAbstractPropertyDefinition(def) => def.property_definition.span, Self::TSIndexSignature(sig) => sig.span, } } diff --git a/crates/oxc_ast/src/syntax_directed_operations/private_bound_identifiers.rs b/crates/oxc_ast/src/syntax_directed_operations/private_bound_identifiers.rs index 8e53dd2b2..4c1a1ee02 100644 --- a/crates/oxc_ast/src/syntax_directed_operations/private_bound_identifiers.rs +++ b/crates/oxc_ast/src/syntax_directed_operations/private_bound_identifiers.rs @@ -12,12 +12,6 @@ impl<'a> PrivateBoundIdentifiers for ClassElement<'a> { ClassElement::MethodDefinition(def) => def.private_bound_identifiers(), ClassElement::PropertyDefinition(def) => def.private_bound_identifiers(), ClassElement::AccessorProperty(def) => def.private_bound_identifiers(), - ClassElement::TSAbstractMethodDefinition(def) => { - def.method_definition.private_bound_identifiers() - } - ClassElement::TSAbstractPropertyDefinition(def) => { - def.property_definition.private_bound_identifiers() - } } } } diff --git a/crates/oxc_ast/src/syntax_directed_operations/prop_name.rs b/crates/oxc_ast/src/syntax_directed_operations/prop_name.rs index 4c4ee2ad2..04f00ab94 100644 --- a/crates/oxc_ast/src/syntax_directed_operations/prop_name.rs +++ b/crates/oxc_ast/src/syntax_directed_operations/prop_name.rs @@ -43,9 +43,7 @@ impl<'a> PropName for ClassElement<'a> { fn prop_name(&self) -> Option<(&str, Span)> { match self { ClassElement::MethodDefinition(def) => def.prop_name(), - ClassElement::TSAbstractMethodDefinition(def) => def.method_definition.prop_name(), ClassElement::PropertyDefinition(def) => def.prop_name(), - ClassElement::TSAbstractPropertyDefinition(def) => def.property_definition.prop_name(), _ => None, } } diff --git a/crates/oxc_ast/src/visit.rs b/crates/oxc_ast/src/visit.rs index 7db7e9673..7d878b054 100644 --- a/crates/oxc_ast/src/visit.rs +++ b/crates/oxc_ast/src/visit.rs @@ -482,12 +482,6 @@ pub trait Visit<'a>: Sized { ClassElement::MethodDefinition(def) => self.visit_method_definition(def), ClassElement::PropertyDefinition(def) => self.visit_property_definition(def), ClassElement::AccessorProperty(_def) => { /* TODO */ } - ClassElement::TSAbstractMethodDefinition(def) => { - self.visit_method_definition(&def.method_definition); - } - ClassElement::TSAbstractPropertyDefinition(def) => { - self.visit_property_definition(&def.property_definition); - } ClassElement::TSIndexSignature(_def) => {} } } diff --git a/crates/oxc_ast/src/visit_mut.rs b/crates/oxc_ast/src/visit_mut.rs index 2dfaf94cc..af5555171 100644 --- a/crates/oxc_ast/src/visit_mut.rs +++ b/crates/oxc_ast/src/visit_mut.rs @@ -482,12 +482,6 @@ pub trait VisitMut<'a>: Sized { ClassElement::MethodDefinition(def) => self.visit_method_definition(def), ClassElement::PropertyDefinition(def) => self.visit_property_definition(def), ClassElement::AccessorProperty(_def) => { /* TODO */ } - ClassElement::TSAbstractMethodDefinition(def) => { - self.visit_method_definition(&mut def.method_definition); - } - ClassElement::TSAbstractPropertyDefinition(def) => { - self.visit_property_definition(&mut def.property_definition); - } ClassElement::TSIndexSignature(_def) => {} } } diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index a67e4ec16..0abeed3be 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -1981,8 +1981,6 @@ impl<'a, const MINIFY: bool> Gen for ClassElement<'a> { Self::MethodDefinition(elem) => elem.gen(p, ctx), Self::PropertyDefinition(elem) => elem.gen(p, ctx), Self::AccessorProperty(elem) => elem.gen(p, ctx), - Self::TSAbstractMethodDefinition(elem) => elem.gen(p, ctx), - Self::TSAbstractPropertyDefinition(elem) => elem.gen(p, ctx), Self::TSIndexSignature(elem) => elem.gen(p, ctx), } } @@ -2195,11 +2193,14 @@ impl<'a, const MINIFY: bool> Gen for StaticBlock<'a> { impl<'a, const MINIFY: bool> Gen for MethodDefinition<'a> { fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { - if !p.options.enable_typescript && self.value.is_typescript_syntax() { - return; - } self.decorators.gen(p, ctx); + if p.options.enable_typescript + && self.r#type == MethodDefinitionType::TSAbstractMethodDefinition + { + p.print_str(b"abstract "); + } + if self.r#static { p.print_str(b"static "); } @@ -2248,6 +2249,9 @@ impl<'a, const MINIFY: bool> Gen for PropertyDefinition<'a> { fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { self.decorators.gen(p, ctx); if p.options.enable_typescript { + if self.r#type == PropertyDefinitionType::TSAbstractPropertyDefinition { + p.print_str(b"abstract "); + } if let Some(accessibility) = &self.accessibility { match accessibility { TSAccessibility::Private => { diff --git a/crates/oxc_codegen/src/gen_ts.rs b/crates/oxc_codegen/src/gen_ts.rs index 5d1f8e2e2..ead7bcfaa 100644 --- a/crates/oxc_codegen/src/gen_ts.rs +++ b/crates/oxc_codegen/src/gen_ts.rs @@ -646,27 +646,6 @@ impl<'a, const MINIFY: bool> Gen for TSConstructorType<'a> { } } -impl<'a, const MINIFY: bool> Gen for TSAbstractPropertyDefinition<'a> { - fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { - if !p.options.enable_typescript { - return; - } - - p.print_str(b"abstract "); - self.property_definition.gen(p, ctx); - } -} - -impl<'a, const MINIFY: bool> Gen for TSAbstractMethodDefinition<'a> { - fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { - if !p.options.enable_typescript { - return; - } - p.print_str(b"abstract "); - self.method_definition.gen(p, ctx); - } -} - impl<'a, const MINIFY: bool> Gen for TSImportEqualsDeclaration<'a> { fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { if !p.options.enable_typescript { diff --git a/crates/oxc_linter/src/rules/unicorn/no_static_only_class.rs b/crates/oxc_linter/src/rules/unicorn/no_static_only_class.rs index 7ebe4b191..a54ef8768 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_static_only_class.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_static_only_class.rs @@ -74,16 +74,6 @@ impl Rule for NoStaticOnlyClass { return true; } } - oxc_ast::ast::ClassElement::TSAbstractMethodDefinition(v) => { - if v.method_definition.accessibility.is_some() { - return true; - } - } - oxc_ast::ast::ClassElement::TSAbstractPropertyDefinition(v) => { - if v.property_definition.accessibility.is_some() { - return true; - } - } oxc_ast::ast::ClassElement::AccessorProperty(_) | oxc_ast::ast::ClassElement::StaticBlock(_) | oxc_ast::ast::ClassElement::TSIndexSignature(_) => {} diff --git a/crates/oxc_parser/src/js/class.rs b/crates/oxc_parser/src/js/class.rs index 49599943a..684d7976e 100644 --- a/crates/oxc_parser/src/js/class.rs +++ b/crates/oxc_parser/src/js/class.rs @@ -375,7 +375,13 @@ impl<'a> ParserImpl<'a> { } } + let r#type = if r#abstract { + MethodDefinitionType::TSAbstractMethodDefinition + } else { + MethodDefinitionType::MethodDefinition + }; let method_definition = MethodDefinition { + r#type, span: self.end_span(span), key, value, @@ -387,14 +393,7 @@ impl<'a> ParserImpl<'a> { optional, decorators, }; - - if r#abstract { - Ok(ClassElement::TSAbstractMethodDefinition( - self.ast.alloc(TSAbstractMethodDefinition { method_definition }), - )) - } else { - Ok(ClassElement::MethodDefinition(self.ast.alloc(method_definition))) - } + Ok(ClassElement::MethodDefinition(self.ast.alloc(method_definition))) } /// `FieldDefinition`[?Yield, ?Await] ; @@ -426,7 +425,13 @@ impl<'a> ParserImpl<'a> { }; self.asi()?; + let r#type = if r#abstract { + PropertyDefinitionType::TSAbstractPropertyDefinition + } else { + PropertyDefinitionType::PropertyDefinition + }; let property_definition = PropertyDefinition { + r#type, span: self.end_span(span), key, value, @@ -441,14 +446,7 @@ impl<'a> ParserImpl<'a> { definite, decorators: self.state.consume_decorators(), }; - - if r#abstract { - Ok(ClassElement::TSAbstractPropertyDefinition( - self.ast.alloc(TSAbstractPropertyDefinition { property_definition }), - )) - } else { - Ok(ClassElement::PropertyDefinition(self.ast.alloc(property_definition))) - } + Ok(ClassElement::PropertyDefinition(self.ast.alloc(property_definition))) } /// `ClassStaticBlockStatementList` : diff --git a/crates/oxc_prettier/src/format/class.rs b/crates/oxc_prettier/src/format/class.rs index 7198eea71..3163c006f 100644 --- a/crates/oxc_prettier/src/format/class.rs +++ b/crates/oxc_prettier/src/format/class.rs @@ -219,9 +219,6 @@ fn should_print_semicolon_after_class_property<'a>( match next_node { ClassElement::PropertyDefinition(property_definition) => property_definition.computed, - ClassElement::TSAbstractPropertyDefinition(property_definition) => { - property_definition.0.property_definition.computed - } ClassElement::StaticBlock(_) => false, ClassElement::AccessorProperty(_) | ClassElement::TSIndexSignature(_) => true, ClassElement::MethodDefinition(method_definition) => { @@ -240,24 +237,6 @@ fn should_print_semicolon_after_class_property<'a>( return true; } - false - } - ClassElement::TSAbstractMethodDefinition(ts_abstract_method_definition) => { - let is_async = ts_abstract_method_definition.method_definition.value.r#async; - - if is_async - || ts_abstract_method_definition.method_definition.kind == MethodDefinitionKind::Get - || ts_abstract_method_definition.method_definition.kind == MethodDefinitionKind::Set - { - return false; - } - - let is_generator = ts_abstract_method_definition.method_definition.value.generator; - - if ts_abstract_method_definition.method_definition.computed || is_generator { - return true; - } - false } } diff --git a/crates/oxc_prettier/src/format/mod.rs b/crates/oxc_prettier/src/format/mod.rs index 206d92a0e..1eec9ecc8 100644 --- a/crates/oxc_prettier/src/format/mod.rs +++ b/crates/oxc_prettier/src/format/mod.rs @@ -1966,8 +1966,6 @@ impl<'a> Format<'a> for ClassElement<'a> { ClassElement::MethodDefinition(c) => c.format(p), ClassElement::PropertyDefinition(c) => c.format(p), ClassElement::AccessorProperty(c) => c.format(p), - ClassElement::TSAbstractMethodDefinition(c) => c.format(p), - ClassElement::TSAbstractPropertyDefinition(c) => c.format(p), ClassElement::TSIndexSignature(c) => c.format(p), } } @@ -2222,18 +2220,6 @@ impl<'a> Format<'a> for RegExpFlags { } } -impl<'a> Format<'a> for TSAbstractMethodDefinition<'a> { - fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { - line!() - } -} - -impl<'a> Format<'a> for TSAbstractPropertyDefinition<'a> { - fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { - line!() - } -} - impl<'a> Format<'a> for TSIndexSignature<'a> { fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { line!() diff --git a/crates/oxc_transformer/src/es2022/class_static_block.rs b/crates/oxc_transformer/src/es2022/class_static_block.rs index c7d089c19..e4b0ceaca 100644 --- a/crates/oxc_transformer/src/es2022/class_static_block.rs +++ b/crates/oxc_transformer/src/es2022/class_static_block.rs @@ -102,7 +102,9 @@ impl<'a> ClassStaticBlock<'a> { } }; - *element = self.ast.class_property(SPAN, key, value, false, true, self.ast.new_vec()); + let r#type = PropertyDefinitionType::PropertyDefinition; + *element = + self.ast.class_property(r#type, SPAN, key, value, false, true, self.ast.new_vec()); } } } diff --git a/tasks/coverage/prettier_babel.snap b/tasks/coverage/prettier_babel.snap index 6db3aade9..b01991faf 100644 --- a/tasks/coverage/prettier_babel.snap +++ b/tasks/coverage/prettier_babel.snap @@ -1,6 +1,6 @@ prettier_babel Summary: AST Parsed : 2096/2096 (100.00%) -Positive Passed: 1899/2096 (90.60%) +Positive Passed: 1903/2096 (90.79%) Expect to Parse: "comments/attachComment-false/array-expression-trailing-comma/input.js" Expect to Parse: "comments/basic/array-expression-trailing-comma/input.js" Expect to Parse: "comments/basic/object-accessor-computed/input.js" @@ -29,12 +29,8 @@ Expect to Parse: "esprima/es2015-generator/generator-method-with-yield-delegate/ Expect to Parse: "esprima/es2015-import-declaration/import-module/input.js" Expect to Parse: "esprima/expression-primary-object/migrated_0036/input.js" Expect to Parse: "typescript/cast/as-const/input.ts" -Expect to Parse: "typescript/class/abstract/input.ts" Expect to Parse: "typescript/class/declare/input.ts" Expect to Parse: "typescript/class/index-signature/input.ts" -Expect to Parse: "typescript/class/modifiers-accessors/input.ts" -Expect to Parse: "typescript/class/modifiers-methods-async/input.ts" -Expect to Parse: "typescript/class/modifiers-properties/input.ts" Expect to Parse: "typescript/const/initializer-ambient-context/input.ts" Expect to Parse: "typescript/declare/interface/input.ts" Expect to Parse: "typescript/declare/interface-new-line/input.ts" diff --git a/tasks/coverage/prettier_typescript.snap b/tasks/coverage/prettier_typescript.snap index 532e41af5..7d6f893ab 100644 --- a/tasks/coverage/prettier_typescript.snap +++ b/tasks/coverage/prettier_typescript.snap @@ -1,6 +1,6 @@ prettier_typescript Summary: AST Parsed : 5243/5243 (100.00%) -Positive Passed: 2861/5243 (54.57%) +Positive Passed: 2864/5243 (54.63%) Expect to Parse: "compiler/DeclarationErrorsNoEmitOnError.ts" Expect to Parse: "compiler/abstractInterfaceIdentifierName.ts" Expect to Parse: "compiler/abstractPropertyBasics.ts" @@ -1138,7 +1138,6 @@ Expect to Parse: "compiler/readonlyInDeclarationFile.ts" Expect to Parse: "compiler/reboundBaseClassSymbol.ts" Expect to Parse: "compiler/rectype.ts" Expect to Parse: "compiler/recursiveArrayNotCircular.ts" -Expect to Parse: "compiler/recursiveClassBaseType.ts" Expect to Parse: "compiler/recursiveClassInstantiationsWithDefaultConstructors.ts" Expect to Parse: "compiler/recursiveCloduleReference.ts" Expect to Parse: "compiler/recursiveConditionalCrash1.ts" @@ -1494,7 +1493,6 @@ Expect to Parse: "conformance/classes/mixinAbstractClasses.ts" Expect to Parse: "conformance/classes/mixinAbstractClassesReturnTypeInference.ts" Expect to Parse: "conformance/classes/mixinClassesAnnotated.ts" Expect to Parse: "conformance/classes/mixinClassesAnonymous.ts" -Expect to Parse: "conformance/classes/propertyMemberDeclarations/abstractProperty.ts" Expect to Parse: "conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty5.ts" Expect to Parse: "conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty8.ts" Expect to Parse: "conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty9.ts" @@ -1946,7 +1944,6 @@ Expect to Parse: "conformance/jsx/tsxTypeArgumentsJsxPreserveOutput.tsx" Expect to Parse: "conformance/jsx/tsxTypeErrors.tsx" Expect to Parse: "conformance/jsx/tsxUnionElementType5.tsx" Expect to Parse: "conformance/jsx/tsxUnionTypeComponent1.tsx" -Expect to Parse: "conformance/override/override10.ts" Expect to Parse: "conformance/parser/ecmascript5/ClassDeclarations/parserClassDeclarationIndexSignature1.ts" Expect to Parse: "conformance/parser/ecmascript5/EnumDeclarations/parserEnum1.ts" Expect to Parse: "conformance/parser/ecmascript5/EnumDeclarations/parserEnum2.ts"