11/**
2- * @typedef {import('mdast').Parent } MdastParent
3- * @typedef {import('mdast').Content } Content
2+ * @typedef {import('mdast').Parents } Parents
3+ * @typedef {import('mdast').Nodes } Nodes
44 * @typedef {import('mdast').Root } Root
55 */
66
77/**
8- * @typedef {Root | Content } Node
9- * @typedef {Extract<Node, MdastParent> } Parent
10- *
118 * @typedef Info
129 * Extra info.
13- * @property {Parent } parent
10+ * @property {Parents } parent
1411 * Parent of the section.
1512 * @property {number } start
1613 * Index of `start` in `parent`.
1916 *
2017 * @callback Handler
2118 * Callback called when a section is found.
22- * @param {Node } start
19+ * @param {Nodes } start
2320 * Start of section.
24- * @param {Array<Node > } between
21+ * @param {Array<Nodes > } between
2522 * Nodes between `start` and `end`.
26- * @param {Node } end
23+ * @param {Nodes } end
2724 * End of section.
2825 * @param {Info } info
2926 * Extra info.
30- * @returns {Array<Node | null | undefined> | null | undefined | void }
27+ * @returns {Array<Nodes | null | undefined> | null | undefined | void }
3128 * Results.
3229 *
3330 * If nothing is returned, nothing will be changed.
@@ -42,7 +39,7 @@ import {visit} from 'unist-util-visit'
4239 * Search `tree` for a start and end comments matching `name` and change their
4340 * “section” with `handler`.
4441 *
45- * @param {Node } node
42+ * @param {Nodes } node
4643 * Tree to search.
4744 * @param {string } name
4845 * Comment name to look for.
@@ -54,9 +51,9 @@ import {visit} from 'unist-util-visit'
5451export function zone ( node , name , handler ) {
5552 /** @type {number | undefined } */
5653 let level
57- /** @type {Node | undefined } */
54+ /** @type {Nodes | undefined } */
5855 let marker
59- /** @type {Parent | undefined } */
56+ /** @type {Parents | undefined } */
6057 let scope
6158
6259 visit ( node , ( node , index , parent ) => {
@@ -65,7 +62,7 @@ export function zone(node, name, handler) {
6562 info && info . name === name ? info . attributes . match ( / ( s t a r t | e n d ) \b / ) : null
6663 const type = match ? match [ 0 ] : undefined
6764
68- if ( parent && index !== null && type ) {
65+ if ( parent && index !== undefined && type ) {
6966 if ( ! scope && type === 'start' ) {
7067 level = 0
7168 marker = node
@@ -93,7 +90,7 @@ export function zone(node, name, handler) {
9390 if ( nodes ) {
9491 // Ensure no empty nodes are inserted.
9592 // This could be the case if `end` is in `nodes` but no `end` node exists.
96- /** @type {Array<Node > } */
93+ /** @type {Array<Nodes > } */
9794 const result = [ ]
9895 let offset = - 1
9996
0 commit comments