File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -108,3 +108,22 @@ Array
108108 ββ item 2` ,
109109 ) ;
110110} ) ;
111+
112+ test ( 'last child is angle, when end of list is "null"' , ( ) => {
113+ // prettier-ignore
114+ const str = 'Array' + printTree ( '' , [
115+ ( tab ) => '[0]:' + printTree ( tab + ' ' , [
116+ ( tab ) => 'item 1' ,
117+ null ,
118+ ] ) ,
119+ null ,
120+ null ,
121+ ] ) ;
122+
123+ expect ( '\n' + str ) . toBe (
124+ `
125+ Array
126+ ββ [0]:
127+ ββ item 1` ,
128+ ) ;
129+ } ) ;
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import type {PrintChild} from './types';
22
33export const printTree = ( tab = '' , children : ( PrintChild | null ) [ ] ) : string => {
44 let str = '' ;
5- const length = children . length ;
6- const last = length - 1 ;
7- for ( let i = 0 ; i < length ; i ++ ) {
5+ let last = children . length - 1 ;
6+ for ( ; last >= 0 ; last -- ) if ( children [ last ] ) break ;
7+ for ( let i = 0 ; i <= last ; i ++ ) {
88 const fn = children [ i ] ;
99 if ( ! fn ) continue ;
1010 const isLast = i === last ;
You canβt perform that action at this time.
0 commit comments