Skip to content

Commit 6ec1a26

Browse files
committed
Refactor code-style
* Add more docs to JSDoc
1 parent 96288c0 commit 6ec1a26

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/**
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
38
*/
49

510
import {visit} from 'unist-util-visit'
@@ -8,21 +13,15 @@ import {visit} from 'unist-util-visit'
813
* Make an mdast tree compact by merging adjacent text nodes and block quotes.
914
*
1015
* @template {Node} Tree
16+
* Node type.
1117
* @param {Tree} tree
18+
* Tree to change.
1219
* @returns {Tree}
20+
* Changed tree.
1321
*/
22+
// To do: next major: don‘t return `tree`.
1423
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) {
2625
if (
2726
parent &&
2827
index &&
@@ -50,5 +49,7 @@ export function compact(tree) {
5049
return index
5150
}
5251
}
53-
}
52+
})
53+
54+
return tree
5455
}

0 commit comments

Comments
 (0)