@@ -58,8 +58,9 @@ export function getNodeMetadata(
5858
5959 const initialOffset = offsets . get ( parent . id ) || 0 ;
6060 let offset = initialOffset ;
61+ const comments : Comment [ ] = [ ] ;
6162
62- const comments = children . reduce ( ( commentsArray : Comment [ ] , child ) => {
63+ for ( const child of children ) {
6364 const { id, kind, textLength } = child ;
6465 if ( child . isNonterminalNode ( ) ) {
6566 offsets . set ( id , offset ) ;
@@ -73,16 +74,16 @@ export function getNodeMetadata(
7374 // offset, it's hard to separate these responsibilities into different
7475 // functions without doing the iteration twice.
7576 case TerminalKind . MultiLineComment :
76- commentsArray . push ( new MultiLineComment ( child ) ) ;
77+ comments . push ( new MultiLineComment ( child ) ) ;
7778 break ;
7879 case TerminalKind . MultiLineNatSpecComment :
79- commentsArray . push ( new MultiLineNatSpecComment ( child ) ) ;
80+ comments . push ( new MultiLineNatSpecComment ( child ) ) ;
8081 break ;
8182 case TerminalKind . SingleLineComment :
82- commentsArray . push ( new SingleLineComment ( child ) ) ;
83+ comments . push ( new SingleLineComment ( child ) ) ;
8384 break ;
8485 case TerminalKind . SingleLineNatSpecComment :
85- commentsArray . push ( new SingleLineNatSpecComment ( child ) ) ;
86+ comments . push ( new SingleLineNatSpecComment ( child ) ) ;
8687 break ;
8788 case TerminalKind . Identifier :
8889 case TerminalKind . YulIdentifier :
@@ -96,8 +97,7 @@ export function getNodeMetadata(
9697 }
9798
9899 offset += textLength . utf16 ;
99- return commentsArray ;
100- } , [ ] ) ;
100+ }
101101
102102 const leadingOffset = enclosePeripheralComments
103103 ? 0
@@ -107,7 +107,7 @@ export function getNodeMetadata(
107107 : getLeadingOffset ( children . reverse ( ) ) ;
108108 const loc = {
109109 start : initialOffset + leadingOffset ,
110- end : initialOffset + parent . textLength . utf16 - trailingOffset ,
110+ end : offset - trailingOffset ,
111111 leadingOffset,
112112 trailingOffset
113113 } ;
0 commit comments