@@ -6174,7 +6174,7 @@ fn parse_header_with_conditional_brace_body<'a>(opts: ParseHeaderWithConditional
6174
6174
let mut items = PrintItems :: new ( ) ;
6175
6175
6176
6176
items. push_info ( start_header_info) ;
6177
- items. extend ( opts. parsed_header ) ;
6177
+ items. extend ( new_line_group ( opts. parsed_header ) ) ;
6178
6178
items. push_info ( end_header_info) ;
6179
6179
let result = parse_conditional_brace_body ( ParseConditionalBraceBodyOptions {
6180
6180
parent : opts. parent ,
@@ -6222,7 +6222,6 @@ fn parse_conditional_brace_body<'a>(opts: ParseConditionalBraceBodyOptions<'a>,
6222
6222
let end_header_info = opts. end_header_info ;
6223
6223
let requires_braces_condition = opts. requires_braces_condition_ref ;
6224
6224
let start_inner_text_info = Info :: new ( "startInnerText" ) ;
6225
- let end_first_line_comments_info = Info :: new ( "endFirstLineComments" ) ;
6226
6225
let start_statements_info = Info :: new ( "startStatements" ) ;
6227
6226
let end_statements_info = Info :: new ( "endStatements" ) ;
6228
6227
let header_trailing_comments = get_header_trailing_comments ( & opts. body_node , context) ;
@@ -6238,17 +6237,10 @@ fn parse_conditional_brace_body<'a>(opts: ParseConditionalBraceBodyOptions<'a>,
6238
6237
let open_brace_token = get_open_brace_token ( & opts. body_node , context) ;
6239
6238
let use_braces = opts. use_braces ;
6240
6239
let is_body_empty_stmt = opts. body_node . kind ( ) == NodeKind :: EmptyStmt ;
6241
- let mut space_condition = if_true (
6240
+ let mut inner_brace_space_condition = if_true (
6242
6241
"spaceCondition" ,
6243
6242
move |condition_context| {
6244
6243
if is_body_empty_stmt { return Some ( false ) ; }
6245
-
6246
- if let Some ( has_first_line_comments) = condition_resolvers:: are_infos_not_equal ( condition_context, & start_inner_text_info, & end_first_line_comments_info) {
6247
- if has_first_line_comments {
6248
- return Some ( true ) ;
6249
- }
6250
- }
6251
-
6252
6244
let start_inner_text_info = condition_context. get_resolved_info ( & start_inner_text_info) ?;
6253
6245
let end_statements_info = condition_context. get_resolved_info ( & end_statements_info) ?;
6254
6246
if start_inner_text_info. line_number < end_statements_info. line_number {
@@ -6258,7 +6250,7 @@ fn parse_conditional_brace_body<'a>(opts: ParseConditionalBraceBodyOptions<'a>,
6258
6250
} ,
6259
6251
Signal :: SpaceOrNewLine . into ( ) ,
6260
6252
) ;
6261
- let space_condition_ref = space_condition . get_reference ( ) ;
6253
+ let inner_brace_space_condition_ref = inner_brace_space_condition . get_reference ( ) ;
6262
6254
let mut newline_condition = if_true (
6263
6255
"newLineCondition" ,
6264
6256
move |condition_context| {
@@ -6338,6 +6330,7 @@ fn parse_conditional_brace_body<'a>(opts: ParseConditionalBraceBodyOptions<'a>,
6338
6330
start_header_info,
6339
6331
} , context) ) ;
6340
6332
items. push_str ( "{" ) ;
6333
+ items. push_condition ( inner_brace_space_condition) ;
6341
6334
Some ( items)
6342
6335
} ,
6343
6336
false_path : None ,
@@ -6348,13 +6341,14 @@ fn parse_conditional_brace_body<'a>(opts: ParseConditionalBraceBodyOptions<'a>,
6348
6341
let mut items = PrintItems :: new ( ) ;
6349
6342
items. push_info ( start_info) ;
6350
6343
items. push_condition ( open_brace_condition) ;
6351
- items. push_condition ( space_condition) ;
6352
6344
items. push_info ( start_inner_text_info) ;
6353
6345
let parsed_comments = parse_comment_collection ( header_trailing_comments. into_iter ( ) , None , None , context) ;
6354
6346
if !parsed_comments. is_empty ( ) {
6355
- items. push_condition ( conditions:: indent_if_start_of_line ( parsed_comments) ) ;
6347
+ items. push_signal ( Signal :: StartForceNoNewLines ) ;
6348
+ items. push_str ( " " ) ;
6349
+ items. extend ( parsed_comments) ;
6350
+ items. push_signal ( Signal :: FinishForceNoNewLines ) ;
6356
6351
}
6357
- items. push_info ( end_first_line_comments_info) ;
6358
6352
items. push_condition ( newline_condition) ;
6359
6353
items. push_info ( start_statements_info) ;
6360
6354
@@ -6371,6 +6365,13 @@ fn parse_conditional_brace_body<'a>(opts: ParseConditionalBraceBodyOptions<'a>,
6371
6365
items. extend ( parser_helpers:: with_indent ( {
6372
6366
let mut items = PrintItems :: new ( ) ;
6373
6367
let body_node_span = opts. body_node . span ( ) ;
6368
+ if !is_body_empty_stmt {
6369
+ items. push_condition ( if_true (
6370
+ "spaceIfAtStart" ,
6371
+ move |context| condition_resolvers:: is_at_same_position ( context, & start_info) ,
6372
+ Signal :: SpaceOrNewLine . into ( ) ,
6373
+ ) ) ;
6374
+ }
6374
6375
items. extend ( parse_node ( opts. body_node , context) ) ;
6375
6376
items. extend ( parse_trailing_comments ( & body_node_span, context) ) ;
6376
6377
items
@@ -6398,7 +6399,7 @@ fn parse_conditional_brace_body<'a>(opts: ParseConditionalBraceBodyOptions<'a>,
6398
6399
if condition_resolvers:: is_at_same_position ( condition_context, & start_inner_text_info) ? {
6399
6400
return Some ( false ) ;
6400
6401
}
6401
- let had_space = condition_context. get_resolved_condition ( & space_condition_ref ) ?;
6402
+ let had_space = condition_context. get_resolved_condition ( & inner_brace_space_condition_ref ) ?;
6402
6403
return Some ( had_space) ;
6403
6404
} ,
6404
6405
" " . into ( ) ,
0 commit comments