@@ -7,7 +7,7 @@ use oxc_syntax::identifier::{ZWNBSP, is_line_terminator};
7
7
8
8
use crate :: {
9
9
Buffer , Format , FormatResult , FormatTrailingCommas , TrailingSeparator , format_args,
10
- formatter:: { prelude:: * , separated :: FormatSeparatedIter , trivia:: FormatTrailingComments } ,
10
+ formatter:: { prelude:: * , trivia:: FormatTrailingComments } ,
11
11
generated:: ast_nodes:: { AstNode , AstNodes } ,
12
12
utils:: {
13
13
call_expression:: is_test_call_expression,
@@ -25,7 +25,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, Program<'a>> {
25
25
fn write ( & self , f : & mut Formatter < ' _ , ' a > ) -> FormatResult < ( ) > {
26
26
let format_trailing_comments = format_once ( |f| {
27
27
let comments = f. context ( ) . comments ( ) . comments_before ( self . span . end ) ;
28
- FormatTrailingComments :: Comments ( comments) . fmt ( f )
28
+ write ! ( f , FormatTrailingComments :: Comments ( comments) )
29
29
} ) ;
30
30
31
31
write ! (
@@ -112,19 +112,8 @@ impl<'a> Format<'a> for AstNode<'a, Vec<'a, Directive<'a>>> {
112
112
// }
113
113
//```
114
114
// 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
- }
125
115
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 ;
128
117
write ! ( f, if need_extra_empty_line { empty_line( ) } else { hard_line_break( ) } )
129
118
}
130
119
}
0 commit comments