@@ -35,7 +35,7 @@ for (const entry of fs.readdirSync(FIXTURES)) {
3535 end : inputRange . end ,
3636 }
3737 : inputRange ;
38- const pos = parser . positionAt ( range . start ) ;
38+ const pos = positionAt ( range . start ) ;
3939 partsByLine [ pos . line ] . push ( {
4040 label,
4141 range,
@@ -60,6 +60,14 @@ for (const entry of fs.readdirSync(FIXTURES)) {
6060 }
6161 }
6262 } ;
63+ const positionAt = ( offset : number ) : Position => {
64+ if ( offset && lines . includes ( offset + 1 ) ) {
65+ // Normalize lines to their first char.
66+ return parser . positionAt ( offset + 1 ) ;
67+ }
68+
69+ return parser . positionAt ( offset ) ;
70+ } ;
6371 const tagStack : Ranges . TagName [ ] = [ ] ;
6472 const parser = createParser ( {
6573 onError ( range ) {
@@ -187,23 +195,23 @@ for (const entry of fs.readdirSync(FIXTURES)) {
187195 linePrefix +
188196 read ( {
189197 start : 0 ,
190- end : lines [ 1 ] ,
198+ end : lines . length > 1 ? lines [ 1 ] - 1 : src . length ,
191199 } )
192200 } `;
193201 } else {
194202 result += `\n${
195203 linePrefix +
196204 read ( {
197- start : lines [ line ] + 1 ,
198- end : lines [ line + 1 ] ,
205+ start : lines [ line ] ,
206+ end : lines . length > line + 1 ? lines [ line + 1 ] - 1 : src . length ,
199207 } )
200208 } `;
201209 }
202210
203211 if ( len ) {
204212 const padding = " " . repeat ( linePrefix . length - 3 ) ;
205213 parts . sort ( ( a , b ) => {
206- const delta = ( a . pos . character || 1 ) - ( b . pos . character || 1 ) ;
214+ const delta = a . pos . character - b . pos . character ;
207215 return delta === 0 ? b . range . start - a . range . start : delta ;
208216 } ) ;
209217
@@ -212,7 +220,7 @@ for (const entry of fs.readdirSync(FIXTURES)) {
212220
213221 for ( let i = 0 ; i < len ; i ++ ) {
214222 const part = parts [ i ] ;
215- const col = part . pos . character || 1 ;
223+ const col = part . pos . character + 1 ;
216224 const delta = col - lastCol ;
217225
218226 if ( delta > 0 ) {
@@ -234,15 +242,15 @@ for (const entry of fs.readdirSync(FIXTURES)) {
234242 }
235243 }
236244
237- const column = pos . character || 1 ;
245+ const column = pos . character ;
238246
239- if ( prevPart && ( prevPart . pos . character || 1 ) === column ) {
247+ if ( prevPart && prevPart . pos . character === column ) {
240248 label = `├${ label } ` ;
241249 } else {
242250 label = `╰${ label } ` ;
243251 }
244252
245- label = `${ columns . slice ( 0 , column - 1 ) } ${ label } ` ;
253+ label = `${ columns . slice ( 0 , column ) } ${ label } ` ;
246254 result += `\n${ padding + ( prevPart ? `│ ${ label } ` : `╰─ ${ label } ` ) } ` ;
247255 }
248256 }
0 commit comments