use crate::prelude::*;
use biome_formatter::{format_args, write};
use biome_js_syntax::JsDefaultClause;
use biome_js_syntax::{AnyJsStatement, JsDefaultClauseFields};
use biome_rowan::AstNodeList;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatJsDefaultClause;
impl FormatNodeRule<JsDefaultClause> for FormatJsDefaultClause {
fn fmt_fields(&self, node: &JsDefaultClause, f: &mut JsFormatter) -> FormatResult<()> {
let JsDefaultClauseFields {
default_token,
colon_token,
consequent,
} = node.as_fields();
let first_child_is_block_stmt = matches!(
consequent.iter().next(),
Some(AnyJsStatement::JsBlockStatement(_))
);
write!(f, [default_token.format(), colon_token.format()])?;
if f.comments().has_dangling_comments(node.syntax()) {
write!(f, [space(), format_dangling_comments(node.syntax())])?;
}
if consequent.is_empty() {
write!(f, [hard_line_break()])
} else if first_child_is_block_stmt {
write!(f, [space(), consequent.format()])
} else {
write!(
f,
[indent(&format_args!(
hard_line_break(),
consequent.format()
))]
)
}
}
fn fmt_dangling_comments(&self, _: &JsDefaultClause, _: &mut JsFormatter) -> FormatResult<()> {
Ok(())
}
}