File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * @typedef {import('mdast').Content|import('mdast').Root } Node
2
+ * @typedef {import('mdast').Root } Root
3
+ * @typedef {import('mdast').Content } Content
4
+ */
5
+
6
+ /**
7
+ * @typedef {Content | Root } Node
3
8
*/
4
9
5
10
import { visit } from 'unist-util-visit'
@@ -8,21 +13,15 @@ import {visit} from 'unist-util-visit'
8
13
* Make an mdast tree compact by merging adjacent text nodes and block quotes.
9
14
*
10
15
* @template {Node} Tree
16
+ * Node type.
11
17
* @param {Tree } tree
18
+ * Tree to change.
12
19
* @returns {Tree }
20
+ * Changed tree.
13
21
*/
22
+ // To do: next major: don‘t return `tree`.
14
23
export function compact ( tree ) {
15
- // @ts -expect-error: hush, TS.
16
- visit ( tree , visitor )
17
-
18
- return tree
19
-
20
- /**
21
- * @param {import('mdast').Content } child
22
- * @param {number } index
23
- * @param {Extract<Node, import('mdast').Parent> } parent
24
- */
25
- function visitor ( child , index , parent ) {
24
+ visit ( tree , function ( child , index , parent ) {
26
25
if (
27
26
parent &&
28
27
index &&
@@ -50,5 +49,7 @@ export function compact(tree) {
50
49
return index
51
50
}
52
51
}
53
- }
52
+ } )
53
+
54
+ return tree
54
55
}
You can’t perform that action at this time.
0 commit comments