Skip to content

Commit 2f8b46c

Browse files
authored
Add support for nullish values in points
Closes GH-4. Reviewed-by: Christian Murphy <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
1 parent b8dc42f commit 2f8b46c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
export function fromPoint(point) {
1717
return {
18-
character: point.column - 1,
19-
line: point.line - 1
18+
character: point.column ? point.column - 1 : 0,
19+
line: point.line ? point.line - 1 : 0
2020
}
2121
}
2222

test/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ test('fromPoint', async () => {
1717
{line: 42, character: 99},
1818
'should convert unist points to LSP positions'
1919
)
20+
21+
assert.deepEqual(
22+
fromPoint({line: 0, column: 0}),
23+
{line: 0, character: 0},
24+
'should convert unist points with zero values'
25+
)
26+
27+
assert.deepEqual(
28+
// @ts-expect-error We test invalid user input here.
29+
fromPoint({line: null, column: null}),
30+
{line: 0, character: 0},
31+
'should convert unist points with null values'
32+
)
2033
})
2134

2235
test('toPoint', async () => {

0 commit comments

Comments
 (0)