Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions crates/oxc_prettier/src/format/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ use crate::{

pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a> {
let mut parts = p.vec();

for decorator in &class.decorators {
parts.push(ss!("@"));
parts.push(decorator.expression.format(p));
parts.extend(hardline!());
}

if class.r#abstract {
parts.push(ss!("abstract "));
}
Expand All @@ -33,6 +40,25 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a
parts.push(space!());
}

if let Some(implements) = &class.implements {
if implements.len() > 0 {
parts.push(ss!("implements "));

let mut print_comma = false;
for implementation in implements {
if print_comma {
parts.push(ss!(", "));
} else {
print_comma = true;
}

parts.push(implementation.format(p));
}

parts.push(space!());
}
}

parts.push(class.body.format(p));
Doc::Array(parts)
}
Expand Down Expand Up @@ -126,7 +152,7 @@ impl<'a, 'b> ClassMemberish<'a, 'b> {
fn is_readonly(&self) -> bool {
match self {
ClassMemberish::PropertyDefinition(property_definition) => property_definition.readonly,
ClassMemberish::AccessorProperty(_) => false,
ClassMemberish::AccessorProperty(_) => true,
}
}

Expand Down Expand Up @@ -229,10 +255,6 @@ pub(super) fn print_class_property<'a>(
parts.push(ss!("abstract "));
}

if matches!(node, ClassMemberish::AccessorProperty(_)) {
parts.push(ss!("readonly "));
}

parts.push(node.format_key(p));

if node.is_optional() {
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_prettier/src/format/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ pub(super) fn print_function<'a>(
pub(super) fn print_method<'a>(p: &mut Prettier<'a>, method: &MethodDefinition<'a>) -> Doc<'a> {
let mut parts = p.vec();

if let Some(accessibility) = &method.accessibility {
parts.push(ss!(accessibility.as_str()));
parts.push(space!());
}

if matches!(method.r#type, MethodDefinitionType::TSAbstractMethodDefinition) {
parts.push(ss!("abstract "));
}
Expand Down
14 changes: 14 additions & 0 deletions crates/oxc_prettier/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,20 @@ impl<'a> Format<'a> for ClassElement<'a> {
}
}

impl<'a> Format<'a> for TSClassImplements<'a> {
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
let mut parts = p.vec();

parts.push(self.expression.format(p));

if let Some(type_parameters) = &self.type_parameters {
parts.push(type_parameters.format(p));
}

Doc::Array(parts)
}
}

impl<'a> Format<'a> for JSXIdentifier<'a> {
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
line!()
Expand Down
4 changes: 1 addition & 3 deletions tasks/prettier_conformance/prettier.ts.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ts compatibility: 107/526 (20.34%)
ts compatibility: 109/526 (20.72%)

# Failed

Expand Down Expand Up @@ -155,7 +155,6 @@ ts compatibility: 107/526 (20.34%)
### conformance/classes/classDeclarations/classAbstractKeyword
* conformance/classes/classDeclarations/classAbstractKeyword/classAbstractClinterfaceAssignability.ts
* conformance/classes/classDeclarations/classAbstractKeyword/classAbstractConstructorAssignability.ts
* conformance/classes/classDeclarations/classAbstractKeyword/classAbstractCrashedOnce.ts
* conformance/classes/classDeclarations/classAbstractKeyword/classAbstractFactoryFunction.ts
* conformance/classes/classDeclarations/classAbstractKeyword/classAbstractImportInstantiation.ts
* conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInAModule.ts
Expand Down Expand Up @@ -368,7 +367,6 @@ ts compatibility: 107/526 (20.34%)
### decorators-ts
* decorators-ts/accessor-decorator.ts
* decorators-ts/angular.ts
* decorators-ts/class-decorator.ts
* decorators-ts/method-decorator.ts
* decorators-ts/mobx.ts
* decorators-ts/multiple.ts
Expand Down