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
22 changes: 20 additions & 2 deletions crates/oxc_formatter/src/formatter/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,26 @@ impl<'a> Comments<'a> {
);

let Some(following_node) = following_node else {
let enclosing_span = enclosing_node.span();
return self.comments_before(enclosing_span.end);
// Find dangling comments at the end of the enclosing node
let comments = self.comments_before(enclosing_node.span().end);

let mut start = preceding_span.end;
for (idx, comment) in comments.iter().enumerate() {
// Comments inside the preceding node, which should be printed without checking
if start > comment.span.start {
continue;
}

if !source_text.all_bytes_match(start, comment.span.start, |b| {
b.is_ascii_whitespace() || matches!(b, b')' | b',' | b';')
}) {
return &comments[..idx];
}

start = comment.span.end;
}

return comments;
};

let following_span = following_node.span();
Expand Down
4 changes: 1 addition & 3 deletions tasks/coverage/snapshots/formatter_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 261630d6

formatter_typescript Summary:
AST Parsed : 8816/8816 (100.00%)
Positive Passed: 8805/8816 (99.88%)
Positive Passed: 8806/8816 (99.89%)
Mismatch: tasks/coverage/typescript/tests/cases/compiler/amdLikeInputDeclarationEmit.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/arrayFromAsync.ts
Expand All @@ -13,8 +13,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/genericTypeAsser
Unexpected token
Mismatch: tasks/coverage/typescript/tests/cases/compiler/propertyAccessExpressionInnerComments.ts

Mismatch: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationClasses.ts

Mismatch: tasks/coverage/typescript/tests/cases/compiler/tryStatementInternalComments.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts
Expand Down
Loading