|
2 | 2 | * @typedef Options Configuration.
|
3 | 3 | * @property {Test} [ignore] `unist-util-is` test used to assert parents
|
4 | 4 | *
|
5 |
| - * @typedef {import('mdast').Text} Text |
6 |
| - * @typedef {import('mdast').Parent} Parent |
7 | 5 | * @typedef {import('mdast').Root} Root
|
| 6 | + * @typedef {import('mdast').Content} Content |
8 | 7 | * @typedef {import('mdast').PhrasingContent} PhrasingContent
|
9 |
| - * @typedef {Parent['children'][number]|Root} Node |
| 8 | + * @typedef {import('mdast').Text} Text |
| 9 | + * @typedef {Content|Root} Node |
| 10 | + * @typedef {Extract<Node, import('mdast').Parent>} Parent |
10 | 11 | *
|
11 | 12 | * @typedef {import('unist-util-visit-parents').Test} Test
|
12 | 13 | * @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult
|
@@ -95,14 +96,11 @@ export const findAndReplace =
|
95 | 96 | /** @type {import('unist-util-visit-parents').Visitor<Text>} */
|
96 | 97 | function visitor(node, parents) {
|
97 | 98 | let index = -1
|
98 |
| - /** @type {Parent} */ |
99 |
| - let parent |
100 | 99 | /** @type {Parent|undefined} */
|
101 | 100 | let grandparent
|
102 | 101 |
|
103 | 102 | while (++index < parents.length) {
|
104 |
| - // @ts-expect-error mdast vs. unist parent. |
105 |
| - parent = parents[index] |
| 103 | + const parent = /** @type {Parent} */ (parents[index]) |
106 | 104 |
|
107 | 105 | if (
|
108 | 106 | ignored(
|
@@ -132,6 +130,7 @@ export const findAndReplace =
|
132 | 130 | const find = pairs[pairIndex][0]
|
133 | 131 | const replace = pairs[pairIndex][1]
|
134 | 132 | let start = 0
|
| 133 | + // @ts-expect-error: TS is wrong, some of these children can be text. |
135 | 134 | let index = parent.children.indexOf(node)
|
136 | 135 | /** @type {Array.<PhrasingContent>} */
|
137 | 136 | let nodes = []
|
|
0 commit comments