1
1
/**
2
- * @typedef {import('hast').Root } Root
3
- * @typedef {import('hast').Content } Content
2
+ * @typedef {import('hast').Nodes } Nodes
3
+ * @typedef {import('hast').RootContent } RootContent
4
4
*/
5
5
6
6
/**
7
- * @typedef {Root | Content } Node
8
- *
9
7
* @typedef Options
10
8
* Configuration.
11
9
* @property {string | null | undefined } [comment='more']
16
14
* are assumed to be somewhat reasonably placed.
17
15
* This option prevents searching giant documents for some comment
18
16
* that probably won’t be found at the end.
19
- * @property {Array<Content > | null | undefined } [ignore=[]]
17
+ * @property {Array<RootContent > | null | undefined } [ignore=[]]
20
18
* Nodes to exclude from the resulting tree.
21
19
* These are not counted towards `size`.
22
20
*/
@@ -26,7 +24,7 @@ import {truncate} from 'hast-util-truncate'
26
24
/**
27
25
* Truncate `tree` to a certain comment.
28
26
*
29
- * @template {Node } Tree
27
+ * @template {Nodes } Tree
30
28
* Type of tree.
31
29
* @param {Tree } tree
32
30
* Tree to truncate.
@@ -51,9 +49,9 @@ export function excerpt(tree, options) {
51
49
/**
52
50
* Truncate `node`.
53
51
*
54
- * @param {Node } node
52
+ * @param {Nodes } node
55
53
* Node to truncate.
56
- * @returns {Node | undefined }
54
+ * @returns {Nodes | undefined }
57
55
* Copy of `node` or `undefined` when done.
58
56
*/
59
57
function preorder ( node ) {
@@ -75,18 +73,17 @@ export function excerpt(tree, options) {
75
73
return
76
74
}
77
75
78
- /** @type {Node } */
76
+ /** @type {Nodes } */
79
77
const replacement = { ...node }
80
78
81
79
if ( 'children' in node ) {
82
- /** @type {Array<Content > } */
80
+ /** @type {Array<RootContent > } */
83
81
const children = [ ]
84
82
let index = - 1
85
83
86
84
while ( ++ index < node . children . length && ! found ) {
87
85
const child = node . children [ index ]
88
- const result = preorder ( child )
89
- // @ts -expect-error: assume content model matches.
86
+ const result = /** @type {RootContent | undefined } */ ( preorder ( child ) )
90
87
if ( result ) children . push ( result )
91
88
}
92
89
0 commit comments