Skip to content

Commit 7020fea

Browse files
committed
Fix types
1 parent 55fe3ee commit 7020fea

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

index.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@
22
* @typedef {import('unist').Point} Point
33
* @typedef {import('unist').Node} Node
44
* @typedef {import('unist').Position} Position
5-
* @typedef {object & {type: string, position?: Position|undefined}} NodeLike
5+
*/
6+
7+
/**
8+
* @typedef NodeLike
9+
* @property {string} type
10+
* @property {PositionLike | null | undefined} [position]
11+
*
12+
* @typedef PositionLike
13+
* @property {PointLike | null | undefined} [start]
14+
* @property {PointLike | null | undefined} [end]
15+
*
16+
* @typedef PointLike
17+
* @property {number | null | undefined} [line]
18+
* @property {number | null | undefined} [column]
19+
* @property {number | null | undefined} [offset]
620
*/
721

822
/**
923
* Stringify one point, a position (start and end points), or a node’s
1024
* positional information.
1125
*
12-
* @param {Node|NodeLike|Position|Point|null} [value]
26+
* @param {Node | NodeLike | Position | PositionLike | Point | PointLike | null | undefined} [value]
1327
* @returns {string}
1428
*/
1529
export function stringifyPosition(value) {
@@ -38,23 +52,23 @@ export function stringifyPosition(value) {
3852
}
3953

4054
/**
41-
* @param {Point|undefined} point
55+
* @param {Point | PointLike | null | undefined} point
4256
* @returns {string}
4357
*/
4458
function point(point) {
4559
return index(point && point.line) + ':' + index(point && point.column)
4660
}
4761

4862
/**
49-
* @param {Position|undefined} pos
63+
* @param {Position | PositionLike | null | undefined} pos
5064
* @returns {string}
5165
*/
5266
function position(pos) {
5367
return point(pos && pos.start) + '-' + point(pos && pos.end)
5468
}
5569

5670
/**
57-
* @param {number|undefined} value
71+
* @param {number | null | undefined} value
5872
* @returns {number}
5973
*/
6074
function index(value) {

test.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ test('stringifyPosition', function (t) {
2424
'',
2525
'should return empty `string` with `number`'
2626
)
27-
t.equal(
28-
// @ts-expect-error runtime.
29-
stringifyPosition({}),
30-
'',
31-
'should return empty `string` with `{}`'
32-
)
27+
t.equal(stringifyPosition({}), '', 'should return empty `string` with `{}`')
3328

3429
t.equal(
3530
stringifyPosition({type: 'text'}),
@@ -47,7 +42,6 @@ test('stringifyPosition', function (t) {
4742
t.equal(
4843
stringifyPosition({
4944
type: 'text',
50-
// @ts-expect-error runtime.
5145
position: {start: {}, end: {}}
5246
}),
5347
'1:1-1:1',
@@ -58,9 +52,7 @@ test('stringifyPosition', function (t) {
5852
stringifyPosition({
5953
type: 'text',
6054
position: {
61-
// @ts-expect-error runtime.
6255
start: {line: null, column: null},
63-
// @ts-expect-error runtime.
6456
end: {line: null, column: null}
6557
}
6658
}),
@@ -96,7 +88,6 @@ test('stringifyPosition', function (t) {
9688
)
9789

9890
t.equal(
99-
// @ts-expect-error runtime.
10091
stringifyPosition({start: null, end: null}),
10192
'1:1-1:1',
10293
'should return a range for a `position` without `point`s'
@@ -110,17 +101,14 @@ test('stringifyPosition', function (t) {
110101
)
111102

112103
t.equal(
113-
// @ts-expect-error runtime.
114104
stringifyPosition({start: {}, end: {}}),
115105
'1:1-1:1',
116106
'should return range for `position` with invalid `point`s #1'
117107
)
118108

119109
t.equal(
120110
stringifyPosition({
121-
// @ts-expect-error runtime.
122111
start: {line: null, column: null},
123-
// @ts-expect-error runtime.
124112
end: {line: null, column: null}
125113
}),
126114
'1:1-1:1',
@@ -137,7 +125,6 @@ test('stringifyPosition', function (t) {
137125
)
138126

139127
t.equal(
140-
// @ts-expect-error runtime.
141128
stringifyPosition({line: null, column: null}),
142129
'1:1',
143130
'should return a point for a `point` without indices'
@@ -151,14 +138,12 @@ test('stringifyPosition', function (t) {
151138
)
152139

153140
t.equal(
154-
// @ts-expect-error runtime.
155141
stringifyPosition({line: 4}),
156142
'4:1',
157143
'should return a point for a partially valid `point` #1'
158144
)
159145

160146
t.equal(
161-
// @ts-expect-error runtime.
162147
stringifyPosition({column: 12}),
163148
'1:12',
164149
'should return a point for a partially valid `point` #1'

0 commit comments

Comments
 (0)