File tree 3 files changed +22
-4
lines changed
3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* @typedef {import('unist').Point } Point
3
+ * @typedef {import('unist').Node } Node
3
4
* @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
5
6
*/
6
7
7
8
/**
8
9
* Stringify one point, a position (start and end points), or a node’s
9
10
* positional information.
10
11
*
11
- * @param {NodeLike|Position|Point|null } [value]
12
+ * @param {Node| NodeLike|Position|Point|null } [value]
12
13
* @returns {string }
13
14
*/
14
15
export function stringifyPosition ( value ) {
Original file line number Diff line number Diff line change 37
37
"@types/unist" : " ^2.0.0"
38
38
},
39
39
"devDependencies" : {
40
+ "@types/mdast" : " ^3.0.0" ,
40
41
"@types/tape" : " ^4.0.0" ,
41
42
"c8" : " ^7.0.0" ,
42
43
"prettier" : " ^2.0.0" ,
Original file line number Diff line number Diff line change @@ -77,7 +77,22 @@ test('stringifyPosition', function (t) {
77
77
}
78
78
} ) ,
79
79
'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)'
81
96
)
82
97
83
98
t . equal (
@@ -102,9 +117,10 @@ test('stringifyPosition', function (t) {
102
117
)
103
118
104
119
t . equal (
105
- // @ts -expect-error runtime.
106
120
stringifyPosition ( {
121
+ // @ts -expect-error runtime.
107
122
start : { line : null , column : null } ,
123
+ // @ts -expect-error runtime.
108
124
end : { line : null , column : null }
109
125
} ) ,
110
126
'1:1-1:1' ,
You can’t perform that action at this time.
0 commit comments