@@ -9214,13 +9214,15 @@ fn gen_jsx_children<'a>(opts: GenJsxChildrenOptions<'a>, context: &mut Context<'
92149214 if children. is_empty ( ) {
92159215 items. push_signal ( Signal :: PossibleNewLine ) ;
92169216 } else {
9217+ // `gen_jsx_text` trims boundary whitespace so multi-line JSX text doesn't keep source indentation.
9218+ // Restore meaningful same-line edge spaces here when the first or last rendered child is JSX text.
92179219 let children_len = children. len ( ) ;
92189220 let mut previous_child: Option < Node < ' a > > = None ;
92199221 let mut before_last_child: Option < Node < ' a > > = None ;
92209222 for ( index, ( child, generated_child) ) in children. into_iter ( ) . enumerate ( ) {
92219223 if index > 0 && should_use_space ( * previous_child. as_ref ( ) . unwrap ( ) , child, context) {
92229224 items. extend ( jsx_space_separator ( * previous_child. as_ref ( ) . unwrap ( ) , child, context) ) ;
9223- } else if index == 0 && jsx_child_has_leading_space ( child, context) {
9225+ } else if index == 0 && has_jsx_leading_space ( child, context) {
92249226 items. push_signal ( Signal :: SpaceOrNewLine ) ;
92259227 } else {
92269228 items. push_signal ( Signal :: PossibleNewLine ) ;
@@ -9233,7 +9235,7 @@ fn gen_jsx_children<'a>(opts: GenJsxChildrenOptions<'a>, context: &mut Context<'
92339235 }
92349236 previous_child = Some ( child) ;
92359237 }
9236- if jsx_child_has_trailing_space ( * previous_child. as_ref ( ) . unwrap ( ) , before_last_child, context) {
9238+ if has_jsx_trailing_space ( * previous_child. as_ref ( ) . unwrap ( ) , before_last_child, context) {
92379239 items. push_signal ( Signal :: SpaceOrNewLine ) ;
92389240 } else {
92399241 items. push_signal ( Signal :: PossibleNewLine ) ;
@@ -9242,24 +9244,23 @@ fn gen_jsx_children<'a>(opts: GenJsxChildrenOptions<'a>, context: &mut Context<'
92429244 items
92439245 }
92449246
9245- fn jsx_child_has_leading_space < ' a > ( child : Node < ' a > , context : & mut Context < ' a > ) -> bool {
9246- if let Node :: JSXText ( text) = child {
9247- let raw = text. text_fast ( context. program ) ;
9248- let leading_whitespace = & raw [ ..raw. len ( ) - raw. trim_start ( ) . len ( ) ] ;
9249- !leading_whitespace. is_empty ( ) && !leading_whitespace. contains ( '\n' )
9247+ fn has_jsx_leading_space < ' a > ( current_node : Node < ' a > , context : & Context < ' a > ) -> bool {
9248+ if let Node :: JSXText ( text) = current_node {
9249+ let text = text. text_fast ( context. program ) ;
9250+ text. starts_with ( ' ' ) && utils:: has_no_new_lines_in_leading_whitespace ( text)
92509251 } else {
92519252 false
92529253 }
92539254 }
92549255
9255- fn jsx_child_has_trailing_space < ' a > ( child : Node < ' a > , previous_child : Option < Node < ' a > > , context : & mut Context < ' a > ) -> bool {
9256- if let Node :: JSXText ( text) = child {
9257- if previous_child . map_or ( false , |prev| is_ignore_jsx_expr_container ( prev, context) ) {
9256+ fn has_jsx_trailing_space < ' a > ( current_node : Node < ' a > , previous_node : Option < Node < ' a > > , context : & Context < ' a > ) -> bool {
9257+ if let Node :: JSXText ( text) = current_node {
9258+ if previous_node . map_or ( false , |prev| is_ignore_jsx_expr_container ( prev, context) ) {
92589259 return false ;
92599260 }
9260- let raw = text . text_fast ( context . program ) ;
9261- let trailing_whitespace = & raw [ raw . trim_end ( ) . len ( ) .. ] ;
9262- !trailing_whitespace . is_empty ( ) && !trailing_whitespace . contains ( '\n' )
9261+
9262+ let text = text . text_fast ( context . program ) ;
9263+ text . ends_with ( ' ' ) && utils :: has_no_new_lines_in_trailing_whitespace ( text )
92639264 } else {
92649265 false
92659266 }
0 commit comments