Skip to content

Commit cd509ed

Browse files
fiskersindresorhus
andauthored
Update index-to-position to v1.1 (#52)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 6a7bae7 commit cd509ed

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,13 @@ const getErrorLocation = (string, message) => {
7777
return;
7878
}
7979

80-
let {index, line, column} = match.groups;
80+
const {index, line, column} = match.groups;
8181

8282
if (line && column) {
8383
return {line: Number(line), column: Number(column)};
8484
}
8585

86-
index = Number(index);
87-
88-
// The error location can be out of bounds.
89-
if (index === string.length) {
90-
const {line, column} = indexToPosition(string, string.length - 1, {oneBased: true});
91-
return {line, column: column + 1};
92-
}
93-
94-
return indexToPosition(string, index, {oneBased: true});
86+
return indexToPosition(string, Number(index), {oneBased: true});
9587
};
9688

9789
const addCodePointToUnexpectedToken = message => message.replace(

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
],
4040
"dependencies": {
4141
"@babel/code-frame": "^7.26.2",
42-
"index-to-position": "^1.0.0",
43-
"type-fest": "^4.37.0"
42+
"index-to-position": "^1.1.0",
43+
"type-fest": "^4.39.1"
4444
},
4545
"devDependencies": {
4646
"ava": "^6.2.0",

0 commit comments

Comments
 (0)