@@ -53,22 +53,21 @@ export function getNodeMetadata(
5353 }
5454 } ;
5555 }
56+ const { cst : parent } = ast ;
57+ const children = parent . children ( ) . map ( ( { node } ) => node ) ;
5658
57- const children = ast . cst . children ( ) . map ( ( child ) => {
58- return child . node ;
59- } ) ;
60-
61- const initialOffset = offsets . get ( ast . cst . id ) || 0 ;
59+ const initialOffset = offsets . get ( parent . id ) || 0 ;
6260 let offset = initialOffset ;
6361
6462 const comments = children . reduce ( ( commentsArray : Comment [ ] , child ) => {
63+ const { id, kind, textLength } = child ;
6564 if ( child . isNonterminalNode ( ) ) {
66- offsets . set ( child . id , offset ) ;
65+ offsets . set ( id , offset ) ;
6766 } else {
6867 if ( isComment ( child ) ) {
69- offsets . set ( child . id , offset ) ;
68+ offsets . set ( id , offset ) ;
7069 }
71- switch ( child . kind ) {
70+ switch ( kind ) {
7271 // Since the fetching the comments and calculating offsets are both done
7372 // as we iterate over the children and the comment also depends on the
7473 // offset, it's hard to separate these responsibilities into different
@@ -91,12 +90,12 @@ export function getNodeMetadata(
9190 // functions, etc...
9291 // Since a user can add comments to this section of the code as well,
9392 // we need to track the offsets.
94- offsets . set ( child . id , offset ) ;
93+ offsets . set ( id , offset ) ;
9594 break ;
9695 }
9796 }
9897
99- offset += child . textLength . utf16 ;
98+ offset += textLength . utf16 ;
10099 return commentsArray ;
101100 } , [ ] ) ;
102101
@@ -108,7 +107,7 @@ export function getNodeMetadata(
108107 : getLeadingOffset ( children . reverse ( ) ) ;
109108 const loc = {
110109 start : initialOffset + leadingOffset ,
111- end : initialOffset + ast . cst . textLength . utf16 - trailingOffset ,
110+ end : initialOffset + parent . textLength . utf16 - trailingOffset ,
112111 leadingOffset,
113112 trailingOffset
114113 } ;
0 commit comments