1
1
/**
2
- * @typedef {import('mdast').Parent } MdastParent
3
- * @typedef {import('mdast').Content } Content
2
+ * @typedef {import('mdast').Parents } Parents
3
+ * @typedef {import('mdast').Nodes } Nodes
4
4
* @typedef {import('mdast').Root } Root
5
5
*/
6
6
7
7
/**
8
- * @typedef {Root | Content } Node
9
- * @typedef {Extract<Node, MdastParent> } Parent
10
- *
11
8
* @typedef Info
12
9
* Extra info.
13
- * @property {Parent } parent
10
+ * @property {Parents } parent
14
11
* Parent of the section.
15
12
* @property {number } start
16
13
* Index of `start` in `parent`.
19
16
*
20
17
* @callback Handler
21
18
* Callback called when a section is found.
22
- * @param {Node } start
19
+ * @param {Nodes } start
23
20
* Start of section.
24
- * @param {Array<Node > } between
21
+ * @param {Array<Nodes > } between
25
22
* Nodes between `start` and `end`.
26
- * @param {Node } end
23
+ * @param {Nodes } end
27
24
* End of section.
28
25
* @param {Info } info
29
26
* Extra info.
30
- * @returns {Array<Node | null | undefined> | null | undefined | void }
27
+ * @returns {Array<Nodes | null | undefined> | null | undefined | void }
31
28
* Results.
32
29
*
33
30
* If nothing is returned, nothing will be changed.
@@ -42,7 +39,7 @@ import {visit} from 'unist-util-visit'
42
39
* Search `tree` for a start and end comments matching `name` and change their
43
40
* “section” with `handler`.
44
41
*
45
- * @param {Node } node
42
+ * @param {Nodes } node
46
43
* Tree to search.
47
44
* @param {string } name
48
45
* Comment name to look for.
@@ -54,9 +51,9 @@ import {visit} from 'unist-util-visit'
54
51
export function zone ( node , name , handler ) {
55
52
/** @type {number | undefined } */
56
53
let level
57
- /** @type {Node | undefined } */
54
+ /** @type {Nodes | undefined } */
58
55
let marker
59
- /** @type {Parent | undefined } */
56
+ /** @type {Parents | undefined } */
60
57
let scope
61
58
62
59
visit ( node , ( node , index , parent ) => {
@@ -65,7 +62,7 @@ export function zone(node, name, handler) {
65
62
info && info . name === name ? info . attributes . match ( / ( s t a r t | e n d ) \b / ) : null
66
63
const type = match ? match [ 0 ] : undefined
67
64
68
- if ( parent && index !== null && type ) {
65
+ if ( parent && index !== undefined && type ) {
69
66
if ( ! scope && type === 'start' ) {
70
67
level = 0
71
68
marker = node
@@ -93,7 +90,7 @@ export function zone(node, name, handler) {
93
90
if ( nodes ) {
94
91
// Ensure no empty nodes are inserted.
95
92
// This could be the case if `end` is in `nodes` but no `end` node exists.
96
- /** @type {Array<Node > } */
93
+ /** @type {Array<Nodes > } */
97
94
const result = [ ]
98
95
let offset = - 1
99
96
0 commit comments