5
5
* @typedef {import('hast').Text } Text
6
6
* @typedef {import('hast').Parent } Parent
7
7
* @typedef {import('hast').Root } Root
8
- * @typedef {import('hast').Element['children'][number] } Content
9
- * @typedef {Parent['children'][number]|Root } Node
8
+ * @typedef {import('hast').Element } Element
9
+ * @typedef {import('hast').Content } Content
10
+ * @typedef {Root|Content } Node
10
11
*
11
12
* @typedef {import('hast-util-is-element').Test } Test
12
13
* @typedef {import('unist-util-visit-parents').VisitorResult } VisitorResult
@@ -76,10 +77,10 @@ export function findAndReplace(tree, find, replace, options) {
76
77
77
78
return tree
78
79
79
- /** @type {import('unist-util-visit-parents').Visitor<Text > } */
80
+ /** @type {import('unist-util-visit-parents/complex-types ').BuildVisitor<Node, 'text' > } */
80
81
function visitor ( node , parents ) {
81
82
let index = - 1
82
- /** @type {Parent |undefined } */
83
+ /** @type {Root|Element |undefined } */
83
84
let grandparent
84
85
85
86
while ( ++ index < parents . length ) {
@@ -88,15 +89,14 @@ export function findAndReplace(tree, find, replace, options) {
88
89
if (
89
90
ignored (
90
91
parent ,
91
- // @ts -expect-error hast vs. unist parent .
92
+ // @ts -expect-error: TS doesn’t understand but it’s perfect .
92
93
grandparent ? grandparent . children . indexOf ( parent ) : undefined ,
93
94
grandparent
94
95
)
95
96
) {
96
97
return
97
98
}
98
99
99
- // @ts -expect-error hast vs. unist parent.
100
100
grandparent = parent
101
101
}
102
102
0 commit comments