diff --git a/crates/oxc_formatter/src/write/jsx/opening_element.rs b/crates/oxc_formatter/src/write/jsx/opening_element.rs index 1fee743637132..1c42323a8e826 100644 --- a/crates/oxc_formatter/src/write/jsx/opening_element.rs +++ b/crates/oxc_formatter/src/write/jsx/opening_element.rs @@ -91,7 +91,12 @@ impl<'a> Format<'a> for FormatOpeningElement<'a, '_> { last_attribute_has_comment, } => { let format_inner = format_with(|f| { - write!(f, [format_open, soft_line_indent_or_space(&self.attributes())]); + write!(f, [format_open]); + + let attributes = self.attributes(); + if !attributes.is_empty() { + write!(f, [soft_line_indent_or_space(&attributes)]); + } let comments = f.context().comments().comments_before(self.span.end); FormatTrailingComments::Comments(comments).fmt(f); diff --git a/crates/oxc_formatter/src/write/mod.rs b/crates/oxc_formatter/src/write/mod.rs index f69b9ab0686e7..981d962079451 100644 --- a/crates/oxc_formatter/src/write/mod.rs +++ b/crates/oxc_formatter/src/write/mod.rs @@ -80,6 +80,7 @@ use crate::{ use self::{ array_expression::FormatArrayExpression, arrow_function_expression::is_multiline_template_starting_on_same_line, + block_statement::is_empty_block, call_arguments::is_simple_module_import, class::format_grouped_parameters_with_return_type_for_method, object_like::ObjectLike, @@ -1614,7 +1615,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSModuleBlock<'a>> { let span = self.span(); write!(f, "{"); - if body.is_empty() && directives.is_empty() { + if is_empty_block(&self.body) && directives.is_empty() { write!(f, [format_dangling_comments(span).with_block_indent()]); } else { write!(f, [block_indent(&format_args!(directives, body))]);