@@ -96,7 +96,19 @@ fn gen_node_with_inner_gen<'a>(node: Node<'a>, context: &mut Context<'a>, inner_
96
96
// generate the node
97
97
if has_ignore_comment {
98
98
items. push_force_current_line_indentation ( ) ;
99
- items. extend ( inner_gen ( ir_helpers:: gen_from_raw_string ( node. text_fast ( context. program ) ) , context) ) ;
99
+ let node_text = if node_kind == NodeKind :: JSXText {
100
+ // keep the leading text, but leave the trailing text to be formatted if on a separate line
101
+ let node_text = node. text_fast ( context. program ) ;
102
+ let end_trim = node_text. trim_end ( ) ;
103
+ if node_text[ end_trim. len ( ) ..] . contains ( '\n' ) {
104
+ end_trim
105
+ } else {
106
+ node_text
107
+ }
108
+ } else {
109
+ node. text_fast ( context. program )
110
+ } ;
111
+ items. extend ( inner_gen ( ir_helpers:: gen_from_raw_string ( node_text) , context) ) ;
100
112
101
113
// mark any previous comments as handled
102
114
for comment in context. comments . trailing_comments_with_previous ( node_end) {
@@ -432,6 +444,20 @@ fn get_has_ignore_comment<'a>(leading_comments: &CommentsIterator<'a>, node: Nod
432
444
}
433
445
}
434
446
447
+ fn is_ignore_jsx_expr_container ( node : Node , context : & Context ) -> bool {
448
+ if let Node :: JSXExprContainer ( expr_container) = node {
449
+ if let JSXExpr :: JSXEmptyExpr ( empty_expr) = expr_container. expr {
450
+ for comment in get_jsx_empty_expr_comments ( empty_expr, context) {
451
+ if ir_helpers:: text_has_dprint_ignore ( & comment. text , & context. config . ignore_node_comment_text ) {
452
+ return true ;
453
+ }
454
+ }
455
+ }
456
+ }
457
+
458
+ false
459
+ }
460
+
435
461
/* class */
436
462
437
463
fn gen_class_method < ' a > ( node : & ' a ClassMethod < ' a > , context : & mut Context < ' a > ) -> PrintItems {
@@ -6830,7 +6856,7 @@ fn get_trailing_comments_same_line<'a>(node: &SourceRange, trailing_comments: Co
6830
6856
trailing_comments_on_same_line
6831
6857
}
6832
6858
6833
- fn get_jsx_empty_expr_comments < ' a > ( node : & JSXEmptyExpr , context : & mut Context < ' a > ) -> CommentsIterator < ' a > {
6859
+ fn get_jsx_empty_expr_comments < ' a > ( node : & JSXEmptyExpr , context : & Context < ' a > ) -> CommentsIterator < ' a > {
6834
6860
node. end ( ) . leading_comments_fast ( context. program )
6835
6861
}
6836
6862
@@ -7210,12 +7236,16 @@ where
7210
7236
let mut items = PrintItems :: new ( ) ;
7211
7237
let children_len = opts. items . len ( ) ;
7212
7238
7213
- for ( i, ( node, optional_print_items) ) in opts. items . into_iter ( ) . enumerate ( ) {
7239
+ let mut member_items = opts. items . into_iter ( ) . enumerate ( ) . peekable ( ) ;
7240
+
7241
+ while let Some ( ( i, ( node, optional_print_items) ) ) = member_items. next ( ) {
7214
7242
// class declarations may have empty statements
7215
7243
let is_empty_stmt = node. is :: < EmptyStmt > ( ) ;
7216
7244
if !is_empty_stmt {
7217
7245
if let Some ( last_node) = last_node {
7218
- if should_use_new_line ( & opts. should_use_new_line , last_node, node, context) {
7246
+ if is_ignore_jsx_expr_container ( last_node, context) && node. kind ( ) == NodeKind :: JSXText {
7247
+ // ignore
7248
+ } else if should_use_new_line ( & opts. should_use_new_line , last_node, node, context) {
7219
7249
items. push_signal ( Signal :: NewLine ) ;
7220
7250
7221
7251
if ( opts. should_use_blank_line ) ( last_node, node, context) {
@@ -7232,11 +7262,12 @@ where
7232
7262
}
7233
7263
}
7234
7264
7265
+ let next_node = member_items. peek ( ) . map ( |( _, ( n, _) ) | n) ;
7235
7266
let end_ln = LineNumber :: new ( "endMember" ) ;
7236
7267
context. end_statement_or_member_lns . push ( end_ln) ;
7237
7268
items. extend ( if let Some ( print_items) = optional_print_items {
7238
7269
print_items
7239
- } else if opts. separator . is_none ( ) {
7270
+ } else if opts. separator . is_none ( ) || is_ignore_jsx_expr_container ( node , context ) && next_node . map ( |n| n . kind ( ) == NodeKind :: JSXText ) . unwrap_or ( false ) {
7240
7271
gen_node ( node, context)
7241
7272
} else {
7242
7273
let generated_separator = get_generated_separator ( & opts. separator , i == children_len - 1 , & condition_resolvers:: true_resolver ( ) ) ;
@@ -9021,7 +9052,9 @@ fn gen_jsx_children<'a>(opts: GenJsxChildrenOptions<'a>, context: &mut Context<'
9021
9052
}
9022
9053
9023
9054
fn jsx_space_separator < ' a > ( previous_node : Node < ' a > , current_node : Node < ' a > , context : & Context < ' a > ) -> PrintItems {
9024
- return if node_should_force_newline_if_multi_line ( previous_node) || node_should_force_newline_if_multi_line ( current_node) {
9055
+ return if is_ignore_jsx_expr_container ( previous_node, context) && current_node. kind ( ) == NodeKind :: JSXText {
9056
+ PrintItems :: new ( )
9057
+ } else if node_should_force_newline_if_multi_line ( previous_node) || node_should_force_newline_if_multi_line ( current_node) {
9025
9058
jsx_force_space_with_newline_if_either_node_multi_line ( previous_node, current_node, context)
9026
9059
} else {
9027
9060
jsx_space_or_newline_or_expr_space ( previous_node, current_node, context)
0 commit comments