Skip to content

Commit 58b4a4e

Browse files
committed
Update @types/mdast
1 parent a3f40d8 commit 58b4a4e

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

Diff for: lib/index.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
/**
2-
* @typedef {import('mdast').Parent} MdastParent
3-
* @typedef {import('mdast').Content} Content
2+
* @typedef {import('mdast').Parents} Parents
3+
* @typedef {import('mdast').Nodes} Nodes
44
* @typedef {import('mdast').Root} Root
55
*/
66

77
/**
8-
* @typedef {Root | Content} Node
9-
* @typedef {Extract<Node, MdastParent>} Parent
10-
*
118
* @typedef Info
129
* Extra info.
13-
* @property {Parent} parent
10+
* @property {Parents} parent
1411
* Parent of the section.
1512
* @property {number} start
1613
* Index of `start` in `parent`.
@@ -19,15 +16,15 @@
1916
*
2017
* @callback Handler
2118
* Callback called when a section is found.
22-
* @param {Node} start
19+
* @param {Nodes} start
2320
* Start of section.
24-
* @param {Array<Node>} between
21+
* @param {Array<Nodes>} between
2522
* Nodes between `start` and `end`.
26-
* @param {Node} end
23+
* @param {Nodes} end
2724
* End of section.
2825
* @param {Info} info
2926
* Extra info.
30-
* @returns {Array<Node | null | undefined> | null | undefined | void}
27+
* @returns {Array<Nodes | null | undefined> | null | undefined | void}
3128
* Results.
3229
*
3330
* If nothing is returned, nothing will be changed.
@@ -42,7 +39,7 @@ import {visit} from 'unist-util-visit'
4239
* Search `tree` for a start and end comments matching `name` and change their
4340
* “section” with `handler`.
4441
*
45-
* @param {Node} node
42+
* @param {Nodes} node
4643
* Tree to search.
4744
* @param {string} name
4845
* Comment name to look for.
@@ -54,9 +51,9 @@ import {visit} from 'unist-util-visit'
5451
export function zone(node, name, handler) {
5552
/** @type {number | undefined} */
5653
let level
57-
/** @type {Node | undefined} */
54+
/** @type {Nodes | undefined} */
5855
let marker
59-
/** @type {Parent | undefined} */
56+
/** @type {Parents | undefined} */
6057
let scope
6158

6259
visit(node, (node, index, parent) => {
@@ -65,7 +62,7 @@ export function zone(node, name, handler) {
6562
info && info.name === name ? info.attributes.match(/(start|end)\b/) : null
6663
const type = match ? match[0] : undefined
6764

68-
if (parent && index !== null && type) {
65+
if (parent && index !== undefined && type) {
6966
if (!scope && type === 'start') {
7067
level = 0
7168
marker = node
@@ -93,7 +90,7 @@ export function zone(node, name, handler) {
9390
if (nodes) {
9491
// Ensure no empty nodes are inserted.
9592
// This could be the case if `end` is in `nodes` but no `end` node exists.
96-
/** @type {Array<Node>} */
93+
/** @type {Array<Nodes>} */
9794
const result = []
9895
let offset = -1
9996

Diff for: package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"index.js"
3737
],
3838
"dependencies": {
39-
"@types/mdast": "^3.0.0",
40-
"@types/unist": "^2.0.0",
39+
"@types/mdast": "^4.0.0",
40+
"@types/unist": "^3.0.0",
4141
"mdast-comment-marker": "^2.0.0",
42-
"unist-util-visit": "^4.0.0"
42+
"unist-util-visit": "^5.0.0"
4343
},
4444
"devDependencies": {
4545
"@types/node": "^20.0.0",

Diff for: test/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ test('zone', async () => {
3636
/** @type {{default: (tree: Root) => void}} */
3737
const mod = await import(new URL(folder + '/index.js', root).href)
3838
const check = mod.default
39-
const tree = fromMarkdown(
40-
await fs.readFile(new URL(folder + '/input.md', root))
39+
// To do: remove cast when `from-markdown` is released.
40+
const tree = /** @type {Root} */ (
41+
fromMarkdown(await fs.readFile(new URL(folder + '/input.md', root)))
4142
)
4243

4344
check(tree)
4445

45-
assert.equal(toMarkdown(tree), expected, folder)
46+
// @ts-expect-error: remove cast when `to-markdown` is released.
47+
const result = toMarkdown(tree)
48+
49+
assert.equal(result, expected, folder)
4650
}
4751
})

0 commit comments

Comments
 (0)