This repository was archived by the owner on Mar 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -302,24 +302,33 @@ Errors.getPosition = function(element, offset) {
302
302
303
303
var pos = loc . start ;
304
304
305
+ if ( offset === 0 ) {
306
+ return pos ;
307
+ }
308
+
305
309
var newlineCount = element . getNewlineCount ( ) ;
306
310
if ( newlineCount > 0 ) {
307
311
var code = element . getSourceCode ( ) ;
308
312
LINE_SEPARATOR . lastIndex = 0 ;
309
313
var lineOffset = 0 ;
310
314
var match ;
315
+ var previousOffset = 0 ;
316
+ var firstLineColumnOffset = pos . column ;
311
317
while ( ( match = LINE_SEPARATOR . exec ( code ) ) !== null ) {
312
318
var currentOffset = match . index ;
313
319
if ( offset <= currentOffset ) {
314
320
return {
315
321
line : pos . line + lineOffset ,
316
- column : currentOffset - offset
322
+ column : firstLineColumnOffset + offset - previousOffset
317
323
} ;
318
324
}
325
+ previousOffset = currentOffset + match [ 0 ] . length ;
326
+ firstLineColumnOffset = 0 ;
327
+ lineOffset ++ ;
319
328
}
320
329
return {
321
330
line : pos . line + newlineCount ,
322
- column : code . length - offset
331
+ column : offset - previousOffset
323
332
} ;
324
333
} else {
325
334
pos = {
You can’t perform that action at this time.
0 commit comments