@@ -374,41 +374,48 @@ fn parse_node_with_inner_parse<'a>(
374374}
375375
376376fn get_has_ignore_comment < ' a > ( leading_comments : & CommentsIterator < ' a > , node : & Node < ' a > , context : & mut Context < ' a > ) -> bool {
377- return if let Some ( last_comment ) = get_last_comment ( leading_comments , node, context ) {
378- parser_helpers :: text_has_dprint_ignore ( & last_comment . text , & context . config . ignore_node_comment_text )
379- } else {
380- false
377+ let comments = match node. parent ( ) {
378+ Some ( Node :: JSXElement ( jsx_element ) ) => get_comments_for_jsx_children ( & jsx_element . children , & node . lo ( ) , context ) ,
379+ Some ( Node :: JSXFragment ( jsx_fragment ) ) => get_comments_for_jsx_children ( & jsx_fragment . children , & node . lo ( ) , context ) ,
380+ _ => leading_comments . clone ( ) ,
381381 } ;
382382
383- #[ inline]
384- fn get_last_comment < ' a > ( leading_comments : & CommentsIterator < ' a > , node : & Node , context : & mut Context < ' a > ) -> Option < & ' a Comment > {
385- return match node. parent ( ) {
386- Some ( Node :: JSXElement ( jsx_element) ) => get_last_comment_for_jsx_children ( & jsx_element. children , & node. lo ( ) , context) ,
387- Some ( Node :: JSXFragment ( jsx_fragment) ) => get_last_comment_for_jsx_children ( & jsx_fragment. children , & node. lo ( ) , context) ,
388- _ => leading_comments. peek_last_comment ( ) ,
383+ for comment in comments. into_iter ( ) {
384+ if parser_helpers:: text_has_dprint_ignore ( & comment. text , & context. config . ignore_node_comment_text ) {
385+ return true ;
386+ }
387+ }
388+
389+ return false ;
390+
391+ fn get_comments_for_jsx_children < ' a > ( children : & [ JSXElementChild ] , node_lo : & BytePos , context : & mut Context < ' a > ) -> CommentsIterator < ' a > {
392+ let mut iterator = CommentsIterator :: empty ( ) ;
393+ let index = if let Some ( index) = children. binary_search_by_key ( node_lo, |child| child. lo ( ) ) . ok ( ) {
394+ index
395+ } else {
396+ return iterator;
389397 } ;
390398
391- fn get_last_comment_for_jsx_children < ' a > ( children : & [ JSXElementChild ] , node_lo : & BytePos , context : & mut Context < ' a > ) -> Option < & ' a Comment > {
392- let index = children. binary_search_by_key ( node_lo, |child| child. lo ( ) ) . ok ( ) ?;
393- for i in ( 0 ..index) . rev ( ) {
394- match children. get ( i) ? {
395- JSXElementChild :: JSXExprContainer ( expr_container) => {
396- return match expr_container. expr {
397- JSXExpr :: JSXEmptyExpr ( empty_expr) => get_jsx_empty_expr_comments ( & empty_expr, context) . last ( ) ,
398- _ => None ,
399- } ;
400- }
401- JSXElementChild :: JSXText ( jsx_text) => {
402- if !jsx_text. text_fast ( context. program ) . trim ( ) . is_empty ( ) {
403- return None ;
399+ for i in ( 0 ..index) . rev ( ) {
400+ match children. get ( i) . unwrap ( ) {
401+ JSXElementChild :: JSXExprContainer ( expr_container) => {
402+ match expr_container. expr {
403+ JSXExpr :: JSXEmptyExpr ( empty_expr) => {
404+ iterator. extend ( get_jsx_empty_expr_comments ( & empty_expr, context) ) ;
404405 }
406+ _ => break ,
407+ } ;
408+ }
409+ JSXElementChild :: JSXText ( jsx_text) => {
410+ if !jsx_text. text_fast ( context. program ) . trim ( ) . is_empty ( ) {
411+ break ;
405412 }
406- _ => return None ,
407413 }
414+ _ => break ,
408415 }
409-
410- None
411416 }
417+
418+ iterator
412419 }
413420}
414421
0 commit comments