@@ -519,83 +519,42 @@ function buildByRefMap(root: AriaNode | undefined, map: Map<string | undefined,
519519
520520function  compareSnapshots ( ariaSnapshot : AriaSnapshot ,  previousSnapshot : AriaSnapshot  |  undefined ) : Map < AriaNode ,  'skip'  |  'same'  |  'changed' >  { 
521521  const  previousByRef  =  buildByRefMap ( previousSnapshot ?. root ) ; 
522-   const  result  =  new  Map < AriaNode ,  'skip'    |   ' same'|  'changed' > ( ) ; 
522+   const  result  =  new  Map < AriaNode ,  'same'  |  'changed' > ( ) ; 
523523
524524  // Returns whether ariaNode is the same as previousNode. 
525525  const  visit  =  ( ariaNode : AriaNode ,  previousNode : AriaNode  |  undefined ) : boolean  =>  { 
526526    let  same : boolean  =  ariaNode . children . length  ===  previousNode ?. children . length  &&  ariaNodesEqual ( ariaNode ,  previousNode ) ; 
527527    if  ( ariaNode . role  ===  'iframe' ) 
528528      same  =  false ; 
529-     let  canBeSkipped  =  same ; 
530529
531530    for  ( let  childIndex  =  0  ;  childIndex  <  ariaNode . children . length ;  childIndex ++ )  { 
532531      const  child  =  ariaNode . children [ childIndex ] ; 
533532      const  previousChild  =  previousNode ?. children [ childIndex ] ; 
534533      if  ( typeof  child  ===  'string' )  { 
535534        same  &&=  child  ===  previousChild ; 
536-         canBeSkipped  &&=  child  ===  previousChild ; 
537535      }  else  { 
538536        let  previous  =  typeof  previousChild  !==  'string'  ? previousChild  : undefined ; 
539537        if  ( child . ref ) 
540538          previous  =  previousByRef . get ( child . ref ) ; 
541539        const  sameChild  =  visit ( child ,  previous ) ; 
542-         // New child, different order of children, or changed child with no ref - 
543-         // we have to include this node to list children in the right order. 
544-         if  ( ! previous  ||  ( ! sameChild  &&  ! child . ref )  ||  ( previous  !==  previousChild ) ) 
545-           canBeSkipped  =  false ; 
546540        same  &&=  ( sameChild  &&  previous  ===  previousChild ) ; 
547541      } 
548542    } 
549543
550-     result . set ( ariaNode ,  same  ? 'same'  : ( canBeSkipped  ?  'skip'  :  ' changed') ) ; 
544+     result . set ( ariaNode ,  same  ? 'same'  : ' changed') ; 
551545    return  same ; 
552546  } ; 
553547
554548  visit ( ariaSnapshot . root ,  previousByRef . get ( previousSnapshot ?. root ?. ref ) ) ; 
555549  return  result ; 
556550} 
557551
558- // Chooses only the changed parts of the snapshot and returns them as new roots. 
559- function  filterSnapshotDiff ( nodes : ( AriaNode  |  string ) [ ] ,  statusMap : Map < AriaNode ,  'skip'  |  'same'  |  'changed' > ) : ( AriaNode  |  string ) [ ]  { 
560-   const  result : ( AriaNode  |  string ) [ ]  =  [ ] ; 
561- 
562-   const  visit  =  ( ariaNode : AriaNode )  =>  { 
563-     const  status  =  statusMap . get ( ariaNode ) ; 
564-     if  ( status  ===  'same' )  { 
565-       // No need to render unchanged root at all. 
566-     }  else  if  ( status  ===  'skip' )  { 
567-       // Only render changed children. 
568-       for  ( const  child  of  ariaNode . children )  { 
569-         if  ( typeof  child  !==  'string' ) 
570-           visit ( child ) ; 
571-       } 
572-     }  else  { 
573-       // Render this node's subtree. 
574-       result . push ( ariaNode ) ; 
575-     } 
576-   } ; 
577- 
578-   for  ( const  node  of  nodes )  { 
579-     if  ( typeof  node  ===  'string' ) 
580-       result . push ( node ) ; 
581-     else 
582-       visit ( node ) ; 
583-   } 
584-   return  result ; 
585- } 
586- 
587552export  function  renderAriaTree ( ariaSnapshot : AriaSnapshot ,  publicOptions : AriaTreeOptions ,  previousSnapshot ?: AriaSnapshot ) : string  { 
588553  const  options  =  toInternalOptions ( publicOptions ) ; 
589554  const  lines : string [ ]  =  [ ] ; 
590555  const  includeText  =  options . renderStringsAsRegex  ? textContributesInfo  : ( )  =>  true ; 
591556  const  renderString  =  options . renderStringsAsRegex  ? convertToBestGuessRegex  : ( str : string )  =>  str ; 
592- 
593-   // Do not render the root fragment, just its children. 
594-   let  nodesToRender  =  ariaSnapshot . root . role  ===  'fragment'  ? ariaSnapshot . root . children  : [ ariaSnapshot . root ] ; 
595- 
596557  const  statusMap  =  compareSnapshots ( ariaSnapshot ,  previousSnapshot ) ; 
597-   if  ( previousSnapshot ) 
598-     nodesToRender  =  filterSnapshotDiff ( nodesToRender ,  statusMap ) ; 
599558
600559  const  visitText  =  ( text : string ,  indent : string )  =>  { 
601560    const  escaped  =  yamlEscapeValueIfNeeded ( renderString ( text ) ) ; 
@@ -645,15 +604,15 @@ export function renderAriaTree(ariaSnapshot: AriaSnapshot, publicOptions: AriaTr
645604  } ; 
646605
647606  const  visit  =  ( ariaNode : AriaNode ,  indent : string ,  renderCursorPointer : boolean )  =>  { 
607+     const  status  =  statusMap . get ( ariaNode ) ; 
608+ 
648609    // Replace the whole subtree with a single reference when possible. 
649-     if  ( statusMap . get ( ariaNode )  ===  'same'  &&  ariaNode . ref )  { 
610+     if  ( status  ===  'same'  &&  ariaNode . ref )  { 
650611      lines . push ( indent  +  `- ref=${ ariaNode . ref }  ) ; 
651612      return ; 
652613    } 
653614
654-     // When producing a diff, add <changed> marker to all diff roots. 
655-     const  isDiffRoot  =  ! ! previousSnapshot  &&  ! indent ; 
656-     const  escapedKey  =  indent  +  '- '  +  ( isDiffRoot  ? '<changed> '  : '' )  +  yamlEscapeKeyIfNeeded ( createKey ( ariaNode ,  renderCursorPointer ) ) ; 
615+     const  escapedKey  =  indent  +  '- '  +  yamlEscapeKeyIfNeeded ( createKey ( ariaNode ,  renderCursorPointer ) ) ; 
657616    const  singleInlinedTextChild  =  getSingleInlinedTextChild ( ariaNode ) ; 
658617
659618    if  ( ! ariaNode . children . length  &&  ! Object . keys ( ariaNode . props ) . length )  { 
@@ -671,18 +630,22 @@ export function renderAriaTree(ariaSnapshot: AriaSnapshot, publicOptions: AriaTr
671630      lines . push ( escapedKey  +  ':' ) ; 
672631      for  ( const  [ name ,  value ]  of  Object . entries ( ariaNode . props ) ) 
673632        lines . push ( indent  +  '  - /'  +  name  +  ': '  +  yamlEscapeValueIfNeeded ( value ) ) ; 
633+     } 
674634
675-       const  childIndent  =  indent  +  '  ' ; 
635+     indent  +=  '  ' ; 
636+     if  ( singleInlinedTextChild  ===  undefined )  { 
676637      const  inCursorPointer  =  ! ! ariaNode . ref  &&  renderCursorPointer  &&  hasPointerCursor ( ariaNode ) ; 
677638      for  ( const  child  of  ariaNode . children )  { 
678639        if  ( typeof  child  ===  'string' ) 
679-           visitText ( includeText ( ariaNode ,  child )  ? child  : '' ,  childIndent ) ; 
640+           visitText ( includeText ( ariaNode ,  child )  ? child  : '' ,  indent ) ; 
680641        else 
681-           visit ( child ,  childIndent ,  renderCursorPointer  &&  ! inCursorPointer ) ; 
642+           visit ( child ,  indent ,  renderCursorPointer  &&  ! inCursorPointer ) ; 
682643      } 
683644    } 
684645  } ; 
685646
647+   // Do not render the root fragment, just its children. 
648+   const  nodesToRender  =  ariaSnapshot . root . role  ===  'fragment'  ? ariaSnapshot . root . children  : [ ariaSnapshot . root ] ; 
686649  for  ( const  nodeToRender  of  nodesToRender )  { 
687650    if  ( typeof  nodeToRender  ===  'string' ) 
688651      visitText ( nodeToRender ,  '' ) ; 
0 commit comments