File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,7 +23,24 @@ export function clearOffsets(): void {
2323 offsets . clear ( ) ;
2424}
2525
26- function getLeadingOffset ( children : Edge [ ] ) : number {
26+ function reversedIterator ( children : Edge [ ] ) : Iterable < Edge > {
27+ return {
28+ [ Symbol . iterator ] ( ) : Iterator < Edge > {
29+ let index = children . length ;
30+ return {
31+ next : function ( ) : IteratorResult < Edge , Edge > {
32+ index -- ;
33+ return {
34+ done : index < 0 ,
35+ value : children [ index ]
36+ } ;
37+ }
38+ } ;
39+ }
40+ } ;
41+ }
42+
43+ function getLeadingOffset ( children : Edge [ ] | Iterable < Edge > ) : number {
2744 let offset = 0 ;
2845 for ( const { node } of children ) {
2946 if ( node . isNonterminalNode ( ) || ! isCommentOrWhiteSpace ( node ) ) {
@@ -110,7 +127,10 @@ export class SlangNode {
110127
111128 const [ leadingOffset , trailingOffset ] = enclosePeripheralComments
112129 ? [ 0 , 0 ]
113- : [ getLeadingOffset ( children ) , getLeadingOffset ( children . reverse ( ) ) ] ;
130+ : [
131+ getLeadingOffset ( children ) ,
132+ getLeadingOffset ( reversedIterator ( children ) )
133+ ] ;
114134
115135 this . loc = {
116136 start : initialOffset + leadingOffset ,
You can’t perform that action at this time.
0 commit comments