Skip to content

Commit 6ca88d0

Browse files
committed
Update @types/mdast
1 parent da23de4 commit 6ca88d0

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

lib/index.js

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
/**
2-
* @typedef {import('mdast').Parent} MdastParent
3-
* @typedef {import('mdast').Root} Root
4-
* @typedef {import('mdast').Content} Content
2+
* @typedef {import('mdast').Nodes} Nodes
3+
* @typedef {import('mdast').Parents} Parents
54
* @typedef {import('mdast').PhrasingContent} PhrasingContent
5+
* @typedef {import('mdast').Root} Root
66
* @typedef {import('mdast').Text} Text
77
* @typedef {import('unist-util-visit-parents').Test} Test
88
* @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult
99
*/
1010

1111
/**
12-
* @typedef {Content | Root} Node
13-
* @typedef {Extract<Node, MdastParent>} Parent
14-
* @typedef {Exclude<Parent, Root>} ContentParent
15-
*
1612
* @typedef RegExpMatchObject
1713
* Info on the match.
1814
* @property {number} index
1915
* The index of the search at which the result was found.
2016
* @property {string} input
2117
* A copy of the search string in the text node.
22-
* @property {[Root, ...Array<ContentParent>, Text]} stack
18+
* @property {[...Array<Parents>, Text]} stack
2319
* All ancestors of the text node, where the last node is the text itself.
2420
*
2521
* @callback ReplaceFunction
@@ -90,18 +86,17 @@ const own = {}.hasOwnProperty
9086
export const findAndReplace =
9187
/**
9288
* @type {(
93-
* (<Tree extends Node>(tree: Tree, find: Find, replace?: Replace | null | undefined, options?: Options | null | undefined) => Tree) &
94-
* (<Tree extends Node>(tree: Tree, schema: FindAndReplaceSchema | FindAndReplaceList, options?: Options | null | undefined) => Tree)
89+
* ((tree: Nodes, find: Find, replace?: Replace | null | undefined, options?: Options | null | undefined) => undefined) &
90+
* ((tree: Nodes, schema: FindAndReplaceSchema | FindAndReplaceList, options?: Options | null | undefined) => undefined)
9591
* )}
9692
**/
9793
(
9894
/**
99-
* @template {Node} Tree
100-
* @param {Tree} tree
95+
* @param {Nodes} tree
10196
* @param {Find | FindAndReplaceSchema | FindAndReplaceList} find
10297
* @param {Replace | Options | null | undefined} [replace]
10398
* @param {Options | null | undefined} [options]
104-
* @returns {Tree}
99+
* @returns {undefined}
105100
*/
106101
function (tree, find, replace, options) {
107102
/** @type {Options | null | undefined} */
@@ -131,13 +126,13 @@ export const findAndReplace =
131126
visitParents(tree, 'text', visitor)
132127
}
133128

134-
// To do next major: don’t return the given tree.
129+
// @ts-expect-error: To do: remove.
135130
return tree
136131

137-
/** @type {import('unist-util-visit-parents/complex-types.js').BuildVisitor<Root, 'text'>} */
132+
/** @type {import('unist-util-visit-parents').BuildVisitor<Root, 'text'>} */
138133
function visitor(node, parents) {
139134
let index = -1
140-
/** @type {Parent | undefined} */
135+
/** @type {Parents | undefined} */
141136
let grandparent
142137

143138
while (++index < parents.length) {
@@ -167,7 +162,7 @@ export const findAndReplace =
167162
*
168163
* @param {Text} node
169164
* Text node.
170-
* @param {Array<Parent>} parents
165+
* @param {Array<Parents>} parents
171166
* Parents.
172167
* @returns {VisitorResult}
173168
* Result.
@@ -193,7 +188,6 @@ export const findAndReplace =
193188
const matchObject = {
194189
index: match.index,
195190
input: match.input,
196-
// @ts-expect-error: stack is fine.
197191
stack: [...parents, node]
198192
}
199193
let value = replace(...match, matchObject)

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
"index.js"
3434
],
3535
"dependencies": {
36-
"@types/mdast": "^3.0.0",
36+
"@types/mdast": "^4.0.0",
3737
"escape-string-regexp": "^5.0.0",
38-
"unist-util-is": "^5.0.0",
39-
"unist-util-visit-parents": "^5.0.0"
38+
"unist-util-is": "^6.0.0",
39+
"unist-util-visit-parents": "^6.0.0"
4040
},
4141
"devDependencies": {
4242
"@types/node": "^20.0.0",
@@ -46,7 +46,7 @@
4646
"remark-preset-wooorm": "^9.0.0",
4747
"type-coverage": "^2.0.0",
4848
"typescript": "^5.0.0",
49-
"unist-builder": "^3.0.0",
49+
"unist-builder": "^4.0.0",
5050
"xo": "^0.54.0"
5151
},
5252
"scripts": {

0 commit comments

Comments
 (0)