@@ -89,7 +89,7 @@ export function buildCommentTree(
8989 }
9090
9191 while ( path . length > 1 ) {
92- const front = + path . shift ( ) ! ;
92+ const front : CommentKey = path . shift ( ) ! satisfies string as any ;
9393 loc [ front ] = loc [ front ] ?? {
9494 sort : 0 ,
9595 imediateChildren : 0 ,
@@ -100,15 +100,6 @@ export function buildCommentTree(
100100
101101 const front : keyof typeof loc = path . shift ( ) ! as any ;
102102
103- // const parentPageCursor =
104- // "comment" in loc && loc.comment ? loc.comment.pageCursor : undefined;
105- // if (
106- // parentPageCursor !== undefined &&
107- // parentPageCursor !== view.pageCursor
108- // ) {
109- // (loc as CommentTree).pruned = true;
110- // }
111-
112103 loc [ front ] = {
113104 ...loc [ front ] ,
114105 sort : i ,
@@ -131,21 +122,19 @@ function pruneCommentTree(tree: CommentTreeTopLevel): CommentTreeTopLevel {
131122 return ;
132123 }
133124
134- for ( const key in node ) {
135- if ( ! isDataKey ( key ) ) {
136- const child = node [ key ] ;
137- const childPageCursor = child ?. comment ?. pageCursor ;
138- if ( ! _ . isNil ( childPageCursor ) && childPageCursor !== pageCursor ) {
139- node . pruned = true ;
140- delete node [ key ] ;
141- } else if ( child ) {
142- pruneNode ( child ) ;
143- }
125+ for ( const key of getCommentChildrenKeys ( node ) ) {
126+ const child = node [ key ] ;
127+ const childPageCursor = child ?. comment ?. pageCursor ;
128+ if ( ! _ . isNil ( childPageCursor ) && childPageCursor !== pageCursor ) {
129+ node . pruned = true ;
130+ delete node [ key ] ;
131+ } else if ( child ) {
132+ pruneNode ( child ) ;
144133 }
145134 }
146135 }
147136
148- for ( const key in tree ) {
137+ for ( const key of getCommentChildrenKeys ( tree ) ) {
149138 const node = tree [ key ] ;
150139 if ( node ) {
151140 pruneNode ( node ) ;
@@ -169,10 +158,10 @@ function countImediateChildre(node: CommentTree | CommentTreeTopLevel) {
169158 }
170159}
171160
172- function getCommentChildrenKeys ( node : CommentTree | CommentTreeTopLevel ) {
173- return _ . keys (
174- _ . omit ( node , DATA_KEYS ) ,
175- ) satisfies string [ ] as never as CommentKey [ ] ;
161+ function getCommentChildrenKeys (
162+ node : CommentTree | CommentTreeTopLevel ,
163+ ) : CommentKey [ ] {
164+ return _ . keys ( _ . omit ( node , DATA_KEYS ) ) satisfies string [ ] as never ;
176165}
177166
178167export function getCommentChildren (
0 commit comments