Skip to content

Commit 5bd906b

Browse files
committed
Update @types/mdast
1 parent 55d8221 commit 5bd906b

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

lib/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @typedef {import('mdast').Content} Content
32
* @typedef {import('mdast').Heading} Heading
43
* @typedef {import('mdast').Root} Root
4+
* @typedef {import('mdast').RootContent} RootContent
55
* @typedef {import('unist').Node} UnistNode
66
* @typedef {import('unist').Parent} UnistParent
77
*/
@@ -95,13 +95,13 @@
9595
* Callback called when a section is found.
9696
* @param {Heading} start
9797
* Start of section (a heading node matching `test`).
98-
* @param {Array<Content>} between
98+
* @param {Array<RootContent>} between
9999
* Nodes between `start` and `end`.
100-
* @param {Content | undefined} end
100+
* @param {RootContent | undefined} end
101101
* End of section, if any.
102102
* @param {Info} scope
103103
* Extra info.
104-
* @returns {Array<Content | null | undefined> | null | undefined | void}
104+
* @returns {Array<RootContent | null | undefined> | null | undefined | void}
105105
* Results.
106106
*
107107
* If nothing is returned, nothing will be changed.
@@ -247,7 +247,7 @@ export function headingRange(tree, options, handler) {
247247
if (nodes) {
248248
// Ensure no empty nodes are inserted.
249249
// This could be the case if `end` is in `nodes` but no `end` node exists.
250-
/** @type {Array<Content>} */
250+
/** @type {Array<RootContent>} */
251251
const result = []
252252
let index = -1
253253

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
"index.js"
3434
],
3535
"dependencies": {
36-
"@types/mdast": "^3.0.0",
37-
"@types/unist": "^2.0.0",
36+
"@types/mdast": "^4.0.0",
37+
"@types/unist": "^3.0.0",
3838
"devlop": "^1.1.0",
39-
"mdast-util-to-string": "^3.0.0"
39+
"mdast-util-to-string": "^4.0.0"
4040
},
4141
"devDependencies": {
4242
"@types/node": "^20.0.0",

test.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {fromMarkdown} from 'mdast-util-from-markdown'
1111
import {toMarkdown} from 'mdast-util-to-markdown'
1212
import {headingRange} from 'mdast-util-heading-range'
1313

14+
// To do: remove casts when `from-markdown` is released.
15+
1416
test('headingRange', async function (t) {
1517
await t.test('should expose the public api', async function () {
1618
assert.deepEqual(
@@ -157,13 +159,16 @@ test('headingRange', async function (t) {
157159
await t.test(
158160
'should not remove anything when `null` is given',
159161
async function () {
160-
const tree = fromMarkdown(['Foo', '', '## Foo', '', 'Bar', ''].join('\n'))
162+
const tree = /** @type {Root} */ (
163+
fromMarkdown(['Foo', '', '## Foo', '', 'Bar', ''].join('\n'))
164+
)
161165

162166
headingRange(tree, 'foo', function () {
163167
return null
164168
})
165169

166170
assert.equal(
171+
// @ts-expect-error: remove when `to-markdown` is released.
167172
toMarkdown(tree),
168173
['Foo', '', '## Foo', '', 'Bar', ''].join('\n')
169174
)
@@ -173,35 +178,46 @@ test('headingRange', async function (t) {
173178
await t.test(
174179
'should replace all previous nodes otherwise',
175180
async function () {
176-
const tree = fromMarkdown(['Foo', '', '## Foo', '', 'Bar', ''].join('\n'))
181+
const tree = /** @type {Root} */ (
182+
fromMarkdown(['Foo', '', '## Foo', '', 'Bar', ''].join('\n'))
183+
)
177184

178185
headingRange(tree, 'foo', function () {
179186
return []
180187
})
181188

182-
assert.equal(toMarkdown(tree), ['Foo', ''].join('\n'))
189+
assert.equal(
190+
// @ts-expect-error: remove when `to-markdown` is released.
191+
toMarkdown(tree),
192+
['Foo', ''].join('\n')
193+
)
183194
}
184195
)
185196

186197
await t.test('should insert all returned nodes', async function () {
187-
const tree = fromMarkdown(
188-
['Foo', '', '## Foo', '', 'Bar', '', '## Baz', ''].join('\n')
198+
const tree = /** @type {Root} */ (
199+
fromMarkdown(
200+
['Foo', '', '## Foo', '', 'Bar', '', '## Baz', ''].join('\n')
201+
)
189202
)
190203

191204
headingRange(tree, 'foo', function (start, _, end) {
192205
return [start, {type: 'thematicBreak'}, end]
193206
})
194207

195208
assert.equal(
209+
// @ts-expect-error: remove when `to-markdown` is released.
196210
toMarkdown(tree),
197211
['Foo', '', '## Foo', '', '***', '', '## Baz', ''].join('\n')
198212
)
199213
})
200214

201215
await t.test('should not insert an empty `end`', async function () {
202-
const tree = fromMarkdown(
203-
['# Alpha', '', '## Foo', '', 'one', '', 'two', '', 'three', ''].join(
204-
'\n'
216+
const tree = /** @type {Root} */ (
217+
fromMarkdown(
218+
['# Alpha', '', '## Foo', '', 'one', '', 'two', '', 'three', ''].join(
219+
'\n'
220+
)
205221
)
206222
)
207223

@@ -211,6 +227,7 @@ test('headingRange', async function (t) {
211227
})
212228

213229
assert.equal(
230+
// @ts-expect-error: remove when `to-markdown` is released.
214231
toMarkdown(tree),
215232
['# Alpha', '', '## Foo', '', 'one', '', 'two', '', 'three', ''].join(
216233
'\n'
@@ -335,7 +352,7 @@ test('headingRange', async function (t) {
335352
* Output markdown.
336353
*/
337354
function checkAndRemove(value, options) {
338-
const tree = fromMarkdown(value)
355+
const tree = /** @type {Root} */ (fromMarkdown(value))
339356

340357
headingRange(tree, options, function (start, _, end, scope) {
341358
assert.equal(typeof scope.start, 'number')
@@ -344,5 +361,6 @@ function checkAndRemove(value, options) {
344361
return [start, end]
345362
})
346363

364+
// @ts-expect-error: remove when `to-markdown` is released.
347365
return toMarkdown(tree)
348366
}

0 commit comments

Comments
 (0)