File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
crates/oxc_formatter/src/formatter Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -338,8 +338,26 @@ impl<'a> Comments<'a> {
338
338
) ;
339
339
340
340
let Some ( following_node) = following_node else {
341
- let enclosing_span = enclosing_node. span ( ) ;
342
- return self . comments_before ( enclosing_span. end ) ;
341
+ // Find dangling comments at the end of the enclosing node
342
+ let comments = self . comments_before ( enclosing_node. span ( ) . end ) ;
343
+
344
+ let mut start = preceding_span. end ;
345
+ for ( idx, comment) in comments. iter ( ) . enumerate ( ) {
346
+ // Comments inside the preceding node, which should be printed without checking
347
+ if start > comment. span . start {
348
+ continue ;
349
+ }
350
+
351
+ if !source_text. all_bytes_match ( start, comment. span . start , |b| {
352
+ b. is_ascii_whitespace ( ) || matches ! ( b, b')' | b',' | b';' )
353
+ } ) {
354
+ return & comments[ ..idx] ;
355
+ }
356
+
357
+ start = comment. span . end ;
358
+ }
359
+
360
+ return comments;
343
361
} ;
344
362
345
363
let following_span = following_node. span ( ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ commit: 261630d6
2
2
3
3
formatter_typescript Summary :
4
4
AST Parsed : 8816 / 8816 (100.00 % )
5
- Positive Passed : 8805 / 8816 (99.88 % )
5
+ Positive Passed : 8806 / 8816 (99.89 % )
6
6
Mismatch : tasks / coverage / typescript / tests / cases / compiler / amdLikeInputDeclarationEmit .ts
7
7
8
8
Expect to Parse : tasks / coverage / typescript / tests / cases / compiler / arrayFromAsync .ts
@@ -13,8 +13,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/genericTypeAsser
13
13
Unexpected token
14
14
Mismatch : tasks / coverage / typescript / tests / cases / compiler / propertyAccessExpressionInnerComments .ts
15
15
16
- Mismatch : tasks / coverage / typescript / tests / cases / compiler / sourceMapValidationClasses .ts
17
-
18
16
Mismatch : tasks / coverage / typescript / tests / cases / compiler / tryStatementInternalComments .ts
19
17
20
18
Expect to Parse : tasks / coverage / typescript / tests / cases / conformance / classes / propertyMemberDeclarations / staticPropertyNameConflicts .ts
You can’t perform that action at this time.
0 commit comments