@@ -7,7 +7,7 @@ use oxc_syntax::identifier::{ZWNBSP, is_line_terminator};
77
88use crate :: {
99 Buffer , Format , FormatResult , FormatTrailingCommas , TrailingSeparator , format_args,
10- formatter:: { prelude:: * , separated :: FormatSeparatedIter , trivia:: FormatTrailingComments } ,
10+ formatter:: { prelude:: * , trivia:: FormatTrailingComments } ,
1111 generated:: ast_nodes:: { AstNode , AstNodes } ,
1212 utils:: {
1313 call_expression:: is_test_call_expression,
@@ -25,7 +25,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, Program<'a>> {
2525 fn write ( & self , f : & mut Formatter < ' _ , ' a > ) -> FormatResult < ( ) > {
2626 let format_trailing_comments = format_once ( |f| {
2727 let comments = f. context ( ) . comments ( ) . comments_before ( self . span . end ) ;
28- FormatTrailingComments :: Comments ( comments) . fmt ( f )
28+ write ! ( f , FormatTrailingComments :: Comments ( comments) )
2929 } ) ;
3030
3131 write ! (
@@ -112,19 +112,8 @@ impl<'a> Format<'a> for AstNode<'a, Vec<'a, Directive<'a>>> {
112112 // }
113113 //```
114114 // so we should keep an extra empty line after JsDirectiveList
115- let source_text = f. context ( ) . source_text ( ) ;
116- let mut count = 0 ;
117- let mut source_text_chars = source_text. slice_from ( last_directive. span . end ) . chars ( ) ;
118- for char in source_text_chars. by_ref ( ) {
119- if is_line_terminator ( char) {
120- count += 1 ;
121- } else if !char. is_whitespace ( ) {
122- break ;
123- }
124- }
125115
126- // Need an extra empty line if it has the following line and still has non-characters after whitespace.
127- let need_extra_empty_line = source_text_chars. next ( ) . is_some ( ) && count > 1 ;
116+ let need_extra_empty_line = f. source_text ( ) . lines_after ( last_directive. span . end ) > 1 ;
128117 write ! ( f, if need_extra_empty_line { empty_line( ) } else { hard_line_break( ) } )
129118 }
130119}
0 commit comments