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
9086export 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 )
0 commit comments