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
14 changes: 11 additions & 3 deletions crates/oxc_formatter/src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,15 +900,23 @@ impl<'a> FormatWrite<'a> for AstNode<'a, WithStatement<'a>> {

impl<'a> FormatWrite<'a> for AstNode<'a, LabeledStatement<'a>> {
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
let comments = f.context().comments().comments_before(self.body.span().start);
let comments = f.context().comments().line_comments_before(self.body.span().start);
FormatLeadingComments::Comments(comments).fmt(f)?;

let label = self.label();
let body = self.body();
write!(f, [label, ":"])?;
if matches!(body.as_ref(), Statement::EmptyStatement(_)) {
// If the body is an empty statement, force semicolon insertion
write!(f, ";")
let empty_comments = f.context().comments().comments_before(self.span.end);
write!(
f,
[
FormatTrailingComments::Comments(empty_comments),
maybe_space(!empty_comments.is_empty()),
// If the body is an empty statement, force semicolon insertion
";"
]
)
} else {
write!(f, [space(), body])
}
Expand Down
3 changes: 1 addition & 2 deletions tasks/prettier_conformance/snapshots/prettier.js.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
js compatibility: 699/749 (93.32%)
js compatibility: 700/749 (93.46%)

# Failed

Expand Down Expand Up @@ -30,7 +30,6 @@ js compatibility: 699/749 (93.32%)
| js/if/expr_and_same_line_comments.js | 💥 | 97.73% |
| js/if/if_comments.js | 💥 | 76.00% |
| js/if/trailing_comment.js | 💥 | 91.43% |
| js/label/empty_label.js | 💥 | 66.67% |
| js/last-argument-expansion/dangling-comment-in-arrow-function.js | 💥 | 22.22% |
| js/object-multiline/multiline.js | 💥✨ | 22.22% |
| js/quote-props/classes.js | 💥💥✨✨ | 47.06% |
Expand Down
Loading