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> {
338338 ) ;
339339
340340 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;
343361 } ;
344362
345363 let following_span = following_node. span ( ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ commit: 261630d6
22
33formatter_typescript Summary :
44AST Parsed : 8816 / 8816 (100.00 % )
5- Positive Passed : 8805 / 8816 (99.88 % )
5+ Positive Passed : 8806 / 8816 (99.89 % )
66Mismatch : tasks / coverage / typescript / tests / cases / compiler / amdLikeInputDeclarationEmit .ts
77
88Expect to Parse : tasks / coverage / typescript / tests / cases / compiler / arrayFromAsync .ts
@@ -13,8 +13,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/genericTypeAsser
1313Unexpected token
1414Mismatch : tasks / coverage / typescript / tests / cases / compiler / propertyAccessExpressionInnerComments .ts
1515
16- Mismatch : tasks / coverage / typescript / tests / cases / compiler / sourceMapValidationClasses .ts
17-
1816Mismatch : tasks / coverage / typescript / tests / cases / compiler / tryStatementInternalComments .ts
1917
2018Expect to Parse : tasks / coverage / typescript / tests / cases / conformance / classes / propertyMemberDeclarations / staticPropertyNameConflicts .ts
You can’t perform that action at this time.
0 commit comments