@@ -44,12 +44,13 @@ export abstract class SlangNode {
4444 enclosePeripheralComments = false
4545 ) {
4646 if ( ast instanceof SlangTerminalNode ) {
47- const offset = collected . offsets . get ( ast . id ) || 0 ;
47+ const start = collected . offsets . get ( ast . id ) || 0 ;
48+ const end = start + ast . textLength . utf16 ;
4849 this . loc = {
49- start : offset ,
50- end : offset + ast . textLength . utf16 ,
51- leadingOffset : 0 ,
52- trailingOffset : 0
50+ outerStart : start ,
51+ outerEnd : end ,
52+ start ,
53+ end
5354 } ;
5455 return ;
5556 }
@@ -112,10 +113,10 @@ export abstract class SlangNode {
112113 trailingOffset ??= triviaLength ;
113114
114115 this . loc = {
116+ outerStart : initialOffset ,
117+ outerEnd : offset ,
115118 start : initialOffset + leadingOffset ,
116- end : offset - trailingOffset ,
117- leadingOffset,
118- trailingOffset
119+ end : offset - trailingOffset
119120 } ;
120121 }
121122
@@ -124,26 +125,24 @@ export abstract class SlangNode {
124125 ) : void {
125126 const { loc } = this ;
126127 // calculate correct loc object
127- if ( loc . leadingOffset === 0 ) {
128+ if ( loc . outerStart === loc . start ) {
128129 for ( const childNode of childNodes ) {
129130 if ( childNode === undefined ) continue ;
130- const { leadingOffset , start } = childNode . loc ;
131+ const { outerStart , start } = childNode . loc ;
131132
132- if ( start - leadingOffset === loc . start ) {
133- loc . leadingOffset = leadingOffset ;
133+ if ( outerStart === loc . start ) {
134134 loc . start = start ;
135135 break ;
136136 }
137137 }
138138 }
139139
140- if ( loc . trailingOffset === 0 ) {
140+ if ( loc . outerEnd === loc . end ) {
141141 for ( const childNode of reversedIterator ( childNodes ) ) {
142142 if ( childNode === undefined ) continue ;
143- const { trailingOffset , end } = childNode . loc ;
143+ const { outerEnd , end } = childNode . loc ;
144144
145- if ( end + trailingOffset === loc . end ) {
146- loc . trailingOffset = trailingOffset ;
145+ if ( outerEnd === loc . end ) {
147146 loc . end = end ;
148147 break ;
149148 }
0 commit comments