Skip to content

Commit 30b467e

Browse files
committed
fix(formatter): preserve trailing comments before the semicolon in class methods without a body (#18446)
Fixes prettier test `typescript/interface2/comments-ts-only/18278.ts`
1 parent 233dda6 commit 30b467e

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

crates/oxc_formatter/src/print/class.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ impl<'a> FormatWrite<'a> for AstNode<'a, MethodDefinition<'a>> {
125125

126126
if let Some(body) = &value.body() {
127127
write!(f, body);
128+
} else {
129+
let comments = f.context().comments().comments_before(self.span.end);
130+
write!(f, FormatTrailingComments::Comments(comments));
128131
}
132+
129133
if self.r#type().is_abstract()
130134
|| matches!(value.r#type, FunctionType::TSEmptyBodyFunctionExpression)
131135
{

tasks/prettier_conformance/snapshots/prettier.ts.snap.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ts compatibility: 586/601 (97.50%)
1+
ts compatibility: 587/601 (97.67%)
22

33
# Failed
44

@@ -11,7 +11,6 @@ ts compatibility: 586/601 (97.50%)
1111
| typescript/class/quoted-property.ts | 💥 | 66.67% |
1212
| typescript/comments/mapped_types.ts | 💥 | 96.77% |
1313
| typescript/comments/method_types.ts | 💥 | 82.05% |
14-
| typescript/interface2/comments-ts-only/18278.ts | 💥 | 95.65% |
1514
| typescript/last-argument-expansion/decorated-function.tsx | 💥 | 29.06% |
1615
| typescript/mapped-type/issue-11098.ts | 💥 | 97.03% |
1716
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |

0 commit comments

Comments
 (0)