@@ -9,56 +9,56 @@ import {convert} from 'unist-util-is'
9
9
/**
10
10
* Find nodes in `parent` after a `child` or after an index, that pass `test`.
11
11
*
12
- * @param parent
12
+ * @template {Node} Kind
13
+ * Node type.
14
+ *
15
+ * @overload
16
+ * @param {Parent } parent
17
+ * @param {Node | number } index
18
+ * @param {import('unist-util-is').PredicateTest<Kind> } test
19
+ * @returns {Array<Kind> }
20
+ *
21
+ * @overload
22
+ * @param {Parent } parent
23
+ * @param {Node | number } index
24
+ * @param {Test } [test]
25
+ * @returns {Array<Node> }
26
+ *
27
+ * @param {Parent } parent
13
28
* Parent node.
14
- * @param index
29
+ * @param { Node | number } index
15
30
* Child of `parent` or it’s index.
16
- * @param test
31
+ * @param { Test } [ test]
17
32
* `unist-util-is`-compatible test.
18
- * @returns
33
+ * @returns { Array<Node> }
19
34
* Children of `parent` that pass `test`.
20
35
*/
21
- export const findAllAfter =
22
- /**
23
- * @type {(
24
- * (<T extends Node>(node: Parent, index: Node | number, test: import('unist-util-is').PredicateTest<T>) => Array<T>) &
25
- * ((node: Parent, index: Node | number, test?: Test) => Array<Node>)
26
- * )}
27
- */
28
- (
29
- /**
30
- * @param {Parent } parent
31
- * @param {Node | number } index
32
- * @param {Test } [test]
33
- * @returns {Array<Node> }
34
- */
35
- function ( parent , index , test ) {
36
- const is = convert ( test )
37
- /** @type {Array<Node> } */
38
- const results = [ ]
39
-
40
- if ( ! parent || ! parent . type || ! parent . children ) {
41
- throw new Error ( 'Expected parent node' )
42
- }
36
+ export function findAllAfter ( parent , index , test ) {
37
+ const is = convert ( test )
38
+ /** @type {Array<Node> } */
39
+ const results = [ ]
43
40
44
- if ( typeof index === 'number' ) {
45
- if ( index < 0 || index === Number . POSITIVE_INFINITY ) {
46
- throw new Error ( 'Expected positive finite number as index' )
47
- }
48
- } else {
49
- index = parent . children . indexOf ( index )
41
+ if ( ! parent || ! parent . type || ! parent . children ) {
42
+ throw new Error ( 'Expected parent node' )
43
+ }
50
44
51
- if ( index < 0 ) {
52
- throw new Error ( 'Expected child node or index' )
53
- }
54
- }
45
+ if ( typeof index === 'number' ) {
46
+ if ( index < 0 || index === Number . POSITIVE_INFINITY ) {
47
+ throw new Error ( 'Expected positive finite number as index' )
48
+ }
49
+ } else {
50
+ index = parent . children . indexOf ( index )
55
51
56
- while ( ++ index < parent . children . length ) {
57
- if ( is ( parent . children [ index ] , index , parent ) ) {
58
- results . push ( parent . children [ index ] )
59
- }
60
- }
52
+ if ( index < 0 ) {
53
+ throw new Error ( 'Expected child node or index' )
54
+ }
55
+ }
61
56
62
- return results
57
+ while ( ++ index < parent . children . length ) {
58
+ if ( is ( parent . children [ index ] , index , parent ) ) {
59
+ results . push ( parent . children [ index ] )
63
60
}
64
- )
61
+ }
62
+
63
+ return results
64
+ }
0 commit comments