Skip to content

Commit 3b9f4cd

Browse files
committed
Fix types to support instances of Node again
1 parent fd941e9 commit 3b9f4cd

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
22
* @typedef {import('unist').Point} Point
3+
* @typedef {import('unist').Node} Node
34
* @typedef {import('unist').Position} Position
4-
* @typedef {Record<string, unknown> & {type: string, position?: Position|undefined}} NodeLike
5+
* @typedef {object & {type: string, position?: Position|undefined}} NodeLike
56
*/
67

78
/**
89
* Stringify one point, a position (start and end points), or a node’s
910
* positional information.
1011
*
11-
* @param {NodeLike|Position|Point|null} [value]
12+
* @param {Node|NodeLike|Position|Point|null} [value]
1213
* @returns {string}
1314
*/
1415
export function stringifyPosition(value) {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@types/unist": "^2.0.0"
3838
},
3939
"devDependencies": {
40+
"@types/mdast": "^3.0.0",
4041
"@types/tape": "^4.0.0",
4142
"c8": "^7.0.0",
4243
"prettier": "^2.0.0",

test.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,22 @@ test('stringifyPosition', function (t) {
7777
}
7878
}),
7979
'2:5-2:6',
80-
'should return a range for `node` with valid `position`'
80+
'should return a range for `node` with valid `position` (types: literal object)'
81+
)
82+
83+
t.equal(
84+
stringifyPosition(
85+
/** @type {import('mdast').Root} */ ({
86+
type: 'root',
87+
children: [],
88+
position: {
89+
start: {line: 1, column: 1},
90+
end: {line: 2, column: 1}
91+
}
92+
})
93+
),
94+
'1:1-2:1',
95+
'should return a range for `node` with valid `position` (types: explicit instance of node)'
8196
)
8297

8398
t.equal(
@@ -102,9 +117,10 @@ test('stringifyPosition', function (t) {
102117
)
103118

104119
t.equal(
105-
// @ts-expect-error runtime.
106120
stringifyPosition({
121+
// @ts-expect-error runtime.
107122
start: {line: null, column: null},
123+
// @ts-expect-error runtime.
108124
end: {line: null, column: null}
109125
}),
110126
'1:1-1:1',

0 commit comments

Comments
 (0)