Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Sep 25, 2024
1 parent f43fe60 commit 3854c59
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions crates/oxc_prettier/src/format/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use oxc_span::GetSpan;

use super::assignment::AssignmentLikeNode;
use crate::{
array, doc::{Doc, DocBuilder, Group, IfBreak, Line}, format::{assignment, Separator}, group, hardline, if_break, indent, indent_if_break, line, softline, space, ss, Format, Prettier,
array,
doc::{Doc, DocBuilder, Group, IfBreak, Line},
format::{assignment, Separator},
group, hardline, if_break, indent, indent_if_break, line, softline, space, ss, Format,
Prettier,
};

pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a> {
Expand All @@ -15,7 +19,7 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a

// Keep old behaviour of extends in same line
// If there is only on extends and there are not comments
// ToDo: implement comment checks
// ToDo: implement comment checks
// @link https://github.com/prettier/prettier/blob/aa3853b7765645b3f3d8a76e41cf6d70b93c01fd/src/language-js/print/class.js#L62
let group_mode = class.implements.as_ref().map(|v| !v.is_empty()).unwrap_or(false);

Expand All @@ -28,7 +32,7 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a
if let Some(super_type_parameters) = &class.super_type_parameters {
extend_parts.push(super_type_parameters.format(p));
}

extend_parts.push(if_break!(p, " ", ""));

if group_mode {
Expand All @@ -55,7 +59,7 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a
}

parts.push(ss!("class "));

if let Some(id) = &class.id {
parts.push(id.format(p));
}
Expand All @@ -67,7 +71,7 @@ pub(super) fn print_class<'a>(p: &mut Prettier<'a>, class: &Class<'a>) -> Doc<'a
if class.id.is_some() || class.type_parameters.is_some() {
parts.push(space!());
}

if group_mode {
let printend_parts_group = if should_indent_only_heritage_clauses(class) {
array!(p, Doc::Array(group_parts), indent!(p, Doc::Array(heritage_clauses_parts)))
Expand Down Expand Up @@ -387,21 +391,24 @@ fn print_heritage_clauses_implements<'a>(p: &mut Prettier<'a>, class: &Class<'a>
}

if should_indent_only_heritage_clauses(class) {
parts.push(Doc::IfBreak(IfBreak{
parts.push(Doc::IfBreak(IfBreak {
flat_content: p.boxed(ss!("")),
break_contents: p.boxed(line!()),
group_id: None // ToDo - how to attach group id
group_id: None, // ToDo - how to attach group id
}));
} else {
parts.extend(hardline!());
}

parts.push(if_break!(p, "", " "));
parts.push(ss!("implements "));

let implements_docs = implements.iter().map(|v| v.format(p)).collect();

parts.push(indent!(p, group!(p, softline!(), Doc::Array(p.join(Separator::CommaLine, implements_docs)))));
parts.push(indent!(
p,
group!(p, softline!(), Doc::Array(p.join(Separator::CommaLine, implements_docs)))
));
parts.push(space!());

Doc::Group(Group::new(parts))
Expand Down

0 comments on commit 3854c59

Please sign in to comment.