@@ -1431,51 +1431,67 @@ fn parse_arrow_func_expr<'a>(node: &'a ArrowExpr, context: &mut Context<'a>) ->
1431
1431
} ;
1432
1432
1433
1433
fn parse_inner < ' a > ( node : & ' a ArrowExpr , context : & mut Context < ' a > ) -> PrintItems {
1434
- let mut items = PrintItems :: new ( ) ;
1435
1434
let header_start_info = Info :: new ( "arrowFunctionExpressionHeaderStart" ) ;
1436
- let should_use_parens = get_should_use_parens ( & node, context) ;
1437
-
1438
- items. push_info ( header_start_info) ;
1439
- if node. is_async ( ) {
1440
- items. push_str ( "async " ) ;
1441
- }
1442
- if let Some ( type_params) = node. type_params {
1443
- items. extend ( parse_node ( type_params. into ( ) , context) ) ;
1444
- }
1445
-
1446
- if should_use_parens {
1447
- // need to check if there are parens because parse_parameters_or_arguments depends on the parens existing
1448
- if has_parens ( node, context) {
1449
- items. extend ( parse_parameters_or_arguments (
1450
- ParseParametersOrArgumentsOptions {
1451
- node : node. into ( ) ,
1452
- span : node. get_parameters_span ( context) ,
1453
- nodes : node. params . iter ( ) . map ( |node| node. into ( ) ) . collect ( ) ,
1454
- custom_close_paren : |context| {
1455
- Some ( parse_close_paren_with_type (
1456
- ParseCloseParenWithTypeOptions {
1457
- start_info : header_start_info,
1458
- type_node : node. return_type . map ( |x| x. into ( ) ) ,
1459
- type_node_separator : None ,
1460
- param_count : node. params . len ( ) ,
1461
- } ,
1462
- context,
1463
- ) )
1435
+ let header_items = {
1436
+ let mut items = PrintItems :: new ( ) ;
1437
+ let should_use_parens = get_should_use_parens ( & node, context) ;
1438
+
1439
+ items. push_info ( header_start_info) ;
1440
+ if node. is_async ( ) {
1441
+ items. push_str ( "async " ) ;
1442
+ }
1443
+ if let Some ( type_params) = node. type_params {
1444
+ items. extend ( parse_node ( type_params. into ( ) , context) ) ;
1445
+ }
1446
+
1447
+ if should_use_parens {
1448
+ // need to check if there are parens because parse_parameters_or_arguments depends on the parens existing
1449
+ if has_parens ( node, context) {
1450
+ items. extend ( parse_parameters_or_arguments (
1451
+ ParseParametersOrArgumentsOptions {
1452
+ node : node. into ( ) ,
1453
+ span : node. get_parameters_span ( context) ,
1454
+ nodes : node. params . iter ( ) . map ( |node| node. into ( ) ) . collect ( ) ,
1455
+ custom_close_paren : |context| {
1456
+ Some ( parse_close_paren_with_type (
1457
+ ParseCloseParenWithTypeOptions {
1458
+ start_info : header_start_info,
1459
+ type_node : node. return_type . map ( |x| x. into ( ) ) ,
1460
+ type_node_separator : None ,
1461
+ param_count : node. params . len ( ) ,
1462
+ } ,
1463
+ context,
1464
+ ) )
1465
+ } ,
1466
+ is_parameters : true ,
1464
1467
} ,
1465
- is_parameters : true ,
1466
- } ,
1467
- context,
1468
- ) ) ;
1468
+ context,
1469
+ ) ) ;
1470
+ } else {
1471
+ // todo: this should probably use more of the same logic as in parse_parameters_or_arguments
1472
+ // there will only be one param in this case
1473
+ items. extend ( surround_with_parens ( parse_node ( node. params . first ( ) . unwrap ( ) . into ( ) , context) ) ) ;
1474
+ }
1469
1475
} else {
1470
- // todo: this should probably use more of the same logic as in parse_parameters_or_arguments
1471
- // there will only be one param in this case
1472
- items. extend ( surround_with_parens ( parse_node ( node. params . first ( ) . unwrap ( ) . into ( ) , context) ) ) ;
1476
+ items. extend ( parse_node ( node. params . first ( ) . unwrap ( ) . into ( ) , context) ) ;
1473
1477
}
1474
- } else {
1475
- items. extend ( parse_node ( node. params . first ( ) . unwrap ( ) . into ( ) , context) ) ;
1476
- }
1477
1478
1478
- items. push_str ( " =>" ) ;
1479
+ items. push_str ( " =>" ) ;
1480
+ items
1481
+ } ;
1482
+
1483
+ let is_arrow_in_test_call_expr = node
1484
+ . parent ( )
1485
+ . parent ( )
1486
+ . unwrap ( )
1487
+ . to :: < CallExpr > ( )
1488
+ . map ( |c| node_helpers:: is_test_library_call_expr ( c, context. module ) )
1489
+ . unwrap_or ( false ) ;
1490
+ let mut items = if is_arrow_in_test_call_expr {
1491
+ parser_helpers:: with_no_new_lines ( header_items)
1492
+ } else {
1493
+ header_items
1494
+ } ;
1479
1495
1480
1496
let parsed_body = parse_node ( node. body . into ( ) , context) ;
1481
1497
let parsed_body = if use_new_line_group_for_arrow_body ( node, context) {
@@ -2367,7 +2383,7 @@ fn parse_paren_expr<'a>(node: &'a ParenExpr, context: &mut Context<'a>) -> Print
2367
2383
}
2368
2384
2369
2385
fn should_skip_paren_expr ( node : & ParenExpr , context : & Context ) -> bool {
2370
- if has_surrounding_comments ( & node. expr . into ( ) , context) {
2386
+ if node_helpers :: has_surrounding_comments ( & node. expr . into ( ) , context. module ) {
2371
2387
return false ;
2372
2388
}
2373
2389
@@ -3066,7 +3082,7 @@ fn handle_jsx_surrounding_parens<'a>(inner_items: PrintItems, context: &mut Cont
3066
3082
fn should_jsx_surround_newlines ( node : & Node , context : & Context ) -> bool {
3067
3083
let mut parent = node. parent ( ) . unwrap ( ) ;
3068
3084
while let Some ( paren_expr) = parent. to :: < ParenExpr > ( ) {
3069
- if has_surrounding_comments ( & paren_expr. expr . into ( ) , context) {
3085
+ if node_helpers :: has_surrounding_comments ( & paren_expr. expr . into ( ) , context. module ) {
3070
3086
return false ;
3071
3087
}
3072
3088
parent = parent. parent ( ) . unwrap ( ) ;
@@ -3085,13 +3101,13 @@ fn is_jsx_paren_expr_handled_node(node: &Node, context: &Context) -> bool {
3085
3101
return false ;
3086
3102
}
3087
3103
3088
- if has_surrounding_comments ( node, context) {
3104
+ if node_helpers :: has_surrounding_comments ( node, context. module ) {
3089
3105
return false ;
3090
3106
}
3091
3107
3092
3108
let mut parent = node. parent ( ) . unwrap ( ) ;
3093
3109
while parent. is :: < ParenExpr > ( ) {
3094
- if has_surrounding_comments ( & parent, context) {
3110
+ if node_helpers :: has_surrounding_comments ( & parent, context. module ) {
3095
3111
return false ;
3096
3112
}
3097
3113
parent = parent. parent ( ) . unwrap ( ) ;
@@ -3104,10 +3120,6 @@ fn is_jsx_paren_expr_handled_node(node: &Node, context: &Context) -> bool {
3104
3120
)
3105
3121
}
3106
3122
3107
- fn has_surrounding_comments ( node : & Node , context : & Context ) -> bool {
3108
- !node. leading_comments_fast ( context. module ) . is_empty ( ) || !node. trailing_comments_fast ( context. module ) . is_empty ( )
3109
- }
3110
-
3111
3123
fn parse_jsx_element < ' a > ( node : & ' a JSXElement , context : & mut Context < ' a > ) -> PrintItems {
3112
3124
let items = if let Some ( closing) = node. closing {
3113
3125
let result = parse_jsx_with_opening_and_closing (
0 commit comments