diff --git a/lib/index.js b/lib/index.js index ee5d6fb..a1e32c5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,8 +15,8 @@ */ export function fromPoint(point) { return { - character: point.column - 1, - line: point.line - 1 + character: point.column ? point.column - 1 : 0, + line: point.line ? point.line - 1 : 0 } } diff --git a/test/index.js b/test/index.js index d23b316..c4beedb 100644 --- a/test/index.js +++ b/test/index.js @@ -17,6 +17,19 @@ test('fromPoint', async () => { {line: 42, character: 99}, 'should convert unist points to LSP positions' ) + + assert.deepEqual( + fromPoint({line: 0, column: 0}), + {line: 0, character: 0}, + 'should convert unist points with zero values' + ) + + assert.deepEqual( + // @ts-expect-error We test invalid user input here. + fromPoint({line: null, column: null}), + {line: 0, character: 0}, + 'should convert unist points with null values' + ) }) test('toPoint', async () => {