Skip to content

Commit a541a47

Browse files
committed
Update @types/mdast
1 parent efad1c2 commit a541a47

File tree

5 files changed

+32
-36
lines changed

5 files changed

+32
-36
lines changed

lib/contents.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @typedef {import('mdast').List} List
33
* @typedef {import('mdast').ListItem} ListItem
44
* @typedef {import('mdast').PhrasingContent} PhrasingContent
5-
* @typedef {import('mdast').StaticPhrasingContent} StaticPhrasingContent
65
* @typedef {import('./search.js').SearchEntry} SearchEntry
76
*/
87

@@ -133,10 +132,10 @@ function insert(entry, parent, settings) {
133132

134133
/**
135134
* @param {Array<PhrasingContent>} [nodes]
136-
* @returns {Array<StaticPhrasingContent>}
135+
* @returns {Array<PhrasingContent>}
137136
*/
138137
function all(nodes) {
139-
/** @type {Array<StaticPhrasingContent>} */
138+
/** @type {Array<PhrasingContent>} */
140139
let result = []
141140
let index = -1
142141

@@ -151,18 +150,14 @@ function all(nodes) {
151150

152151
/**
153152
* @param {PhrasingContent} node
154-
* @returns {StaticPhrasingContent | Array<StaticPhrasingContent>}
153+
* @returns {PhrasingContent | Array<PhrasingContent>}
155154
*/
156155
function one(node) {
157156
if (node.type === 'footnoteReference') {
158157
return []
159158
}
160159

161-
if (
162-
node.type === 'link' ||
163-
node.type === 'linkReference' ||
164-
node.type === 'footnote'
165-
) {
160+
if (node.type === 'link' || node.type === 'linkReference') {
166161
return all(node.children)
167162
}
168163

lib/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/**
2-
* @typedef {import('mdast').Root} Root
3-
* @typedef {import('mdast').Content} Content
2+
* @typedef {import('mdast').Nodes} Nodes
43
* @typedef {import('mdast').List} List
54
* @typedef {import('./search.js').SearchOptions} SearchOptions
65
* @typedef {import('./contents.js').ContentsOptions} ContentsOptions
76
*/
87

98
/**
10-
* @typedef {Root | Content} Node
119
* @typedef {SearchOptions & ContentsOptions & ExtraOptions} Options
1210
*
1311
* @typedef ExtraOptions
@@ -48,7 +46,7 @@ import {toExpression} from './to-expression.js'
4846
* Only top-level headings (those not in blockquotes or lists), are used.
4947
* This default behavior can be changed by passing `options.parents`.
5048
*
51-
* @param {Node} tree
49+
* @param {Nodes} tree
5250
* Tree to search and generate from.
5351
* @param {Options | null | undefined} [options]
5452
* Configuration.

lib/search.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/**
2-
* @typedef {import('mdast').Root} Root
3-
* @typedef {import('mdast').Content} Content
2+
* @typedef {import('mdast').Nodes} Nodes
43
* @typedef {import('mdast').Heading} Heading
54
* @typedef {import('mdast').PhrasingContent} PhrasingContent
65
* @typedef {import('unist-util-is').Test} Test
76
*/
87

98
/**
10-
* @typedef {Root | Content} Node
119
* @typedef {Heading['depth']} Rank
1210
*
1311
*/
@@ -62,7 +60,7 @@ const slugs = new Slugger()
6260
/**
6361
* Search a node for a toc.
6462
*
65-
* @param {Node} root
63+
* @param {Nodes} root
6664
* @param {RegExp | undefined} expression
6765
* @param {SearchOptions} settings
6866
* @returns {SearchResult}
@@ -95,15 +93,20 @@ export function search(root, expression, settings) {
9593
}
9694

9795
// Our opening heading.
98-
if (position !== null && expression && !index && expression.test(value)) {
96+
if (
97+
position !== undefined &&
98+
expression &&
99+
!index &&
100+
expression.test(value)
101+
) {
99102
index = position + 1
100103
opening = node
101104
return
102105
}
103106

104107
// Our closing heading.
105108
if (
106-
position !== null &&
109+
position !== undefined &&
107110
opening &&
108111
!endIndex &&
109112
node.depth <= opening.depth

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
],
3737
"dependencies": {
3838
"@types/extend": "^3.0.0",
39-
"@types/mdast": "^3.0.0",
39+
"@types/mdast": "^4.0.0",
4040
"extend": "^3.0.0",
4141
"github-slugger": "^2.0.0",
42-
"mdast-util-to-string": "^3.1.0",
43-
"unist-util-is": "^5.0.0",
44-
"unist-util-visit": "^4.0.0"
42+
"mdast-util-to-string": "^4.0.0",
43+
"unist-util-is": "^6.0.0",
44+
"unist-util-visit": "^5.0.0"
4545
},
4646
"devDependencies": {
4747
"@types/node": "^20.0.0",
@@ -86,7 +86,8 @@
8686
{
8787
"files": "example.js",
8888
"rules": {
89-
"capitalized-comments": "off"
89+
"capitalized-comments": "off",
90+
"import/order": "off"
9091
}
9192
}
9293
]

test/index.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ test('toc', () => {
2828
'should expose the public api'
2929
)
3030

31-
assert.throws(
32-
() => {
33-
// @ts-expect-error runtime.
34-
toc()
35-
},
36-
/Cannot read propert/,
37-
'should fail without node'
38-
)
31+
assert.throws(() => {
32+
// @ts-expect-error runtime.
33+
toc()
34+
}, 'should fail without node')
3935
})
4036

4137
test('Fixtures', async () => {
@@ -60,10 +56,13 @@ test('Fixtures', async () => {
6056

6157
const {useCustomHProperty, ...options} = config
6258

63-
const tree = fromMarkdown(input, {
64-
mdastExtensions: [gfmFromMarkdown()],
65-
extensions: [gfm()]
66-
})
59+
// To do: remove cast when `from-markdown` is released.
60+
const tree = /** @type {Root} */ (
61+
fromMarkdown(input, {
62+
mdastExtensions: [gfmFromMarkdown()],
63+
extensions: [gfm()]
64+
})
65+
)
6766

6867
if (useCustomHProperty) {
6968
visit(tree, 'heading', (heading) => {

0 commit comments

Comments
 (0)