1515/**
1616 * @typedef EmbeddedHastFields
1717 * hast fields.
18- * @property {string | null | undefined } [hName]
18+ * @property {string | undefined } [hName]
1919 * Generate a specific element with this tag name instead.
20- * @property {HastProperties | null | undefined } [hProperties]
20+ * @property {HastProperties | undefined } [hProperties]
2121 * Generate an element with these properties instead.
22- * @property {Array<HastElementContent> | null | undefined } [hChildren]
22+ * @property {Array<HastElementContent> | undefined } [hChildren]
2323 * Generate an element with this content instead.
2424 *
2525 * To do: type data!
2929 *
3030 * To do: type data!
3131 *
32- * @typedef {MdastNodes & {data?: MdastData | null | undefined} } MdastNodeWithData
32+ * @typedef {MdastNodes & {data?: MdastData | undefined} } MdastNodeWithData
3333 * mdast node with embedded hast data.
3434 *
3535 * To do: type data!
3636 *
37- * @typedef PointLike
38- * Point-like value.
39- * @property {number | null | undefined } [line]
40- * Line.
41- * @property {number | null | undefined } [column]
42- * Column.
43- * @property {number | null | undefined } [offset]
44- * Offset.
45- *
46- * @typedef PositionLike
47- * Position-like value.
48- * @property {PointLike | null | undefined } [start]
49- * Point-like value.
50- * @property {PointLike | null | undefined } [end]
51- * Point-like value.
52- *
5337 * @callback Handler
5438 * Handle a node.
5539 * @param {State } state
5640 * Info passed around.
5741 * @param {any } node
5842 * mdast node to handle.
59- * @param {MdastParents | null | undefined } parent
43+ * @param {MdastParents | undefined } parent
6044 * Parent of `node`.
61- * @returns {Array<HastElementContent> | HastElementContent | null | undefined }
45+ * @returns {Array<HastElementContent> | HastElementContent | undefined }
6246 * hast node.
6347 *
6448 * @typedef State
7761 * Identifiers of order when footnote calls first appear in tree order.
7862 * @property {Handlers } handlers
7963 * Applied handlers.
80- * @property {(node: MdastNodes, parent: MdastParents | null | undefined) => Array<HastElementContent> | HastElementContent | null | undefined } one
64+ * @property {(node: MdastNodes, parent: MdastParents | undefined) => Array<HastElementContent> | HastElementContent | undefined } one
8165 * Transform an mdast node to hast.
8266 * @property {Options } options
8367 * Configuration.
8468 * @property {(from: MdastNodes, node: HastNodes) => void } patch
8569 * Copy a node’s positional info.
86- * @property {<Type extends HastRootContent>(nodes: Array<Type>, loose?: boolean | null | undefined) => Array<HastText | Type> } wrap
70+ * @property {<Type extends HastRootContent>(nodes: Array<Type>, loose?: boolean | undefined) => Array<HastText | Type> } wrap
8771 * Wrap `nodes` with line endings between each node, adds initial/final line endings when `loose`.
8872 *
8973 * @typedef Options
121105
122106import { visit } from 'unist-util-visit'
123107import { position } from 'unist-util-position'
124- import { handlers } from './handlers/index.js'
108+ import { handlers as defaultHandlers } from './handlers/index.js'
125109
126110const own = { } . hasOwnProperty
127111
@@ -143,6 +127,10 @@ export function createState(tree, options) {
143127 const footnoteById = new Map ( )
144128 /** @type {Map<string, number> } */
145129 const footnoteCounts = new Map ( )
130+ /** @type {Handlers } */
131+ // @ts -expect-error: the root handler returns a root.
132+ // Hard to type.
133+ const handlers = { ...defaultHandlers , ...settings . handlers }
146134
147135 /** @type {State } */
148136 const state = {
@@ -152,13 +140,10 @@ export function createState(tree, options) {
152140 footnoteById,
153141 footnoteCounts,
154142 footnoteOrder : [ ] ,
155- // @ts -expect-error: fix `null` handling?
156- handlers : { ...handlers , ...settings . handlers } ,
157- // @ts -expect-error: fix `null` handling.
143+ handlers,
158144 one : oneBound ,
159145 options : settings ,
160146 patch,
161- // @ts -expect-error: fix `null` handling.
162147 wrap
163148 }
164149
@@ -185,7 +170,7 @@ export function createState(tree, options) {
185170 * mdast node.
186171 * @param {MdastParents | undefined } [parent]
187172 * Parent of `node`.
188- * @returns {Array<HastElementContent> | HastElementContent | null | undefined }
173+ * @returns {Array<HastElementContent> | HastElementContent | undefined }
189174 * Resulting hast node.
190175 */
191176 function oneBound ( node , parent ) {
@@ -298,7 +283,7 @@ function applyData(from, to) {
298283 * mdast node.
299284 * @param {MdastParents | undefined } [parent]
300285 * Parent of `node`.
301- * @returns {Array<HastElementContent> | HastElementContent | null | undefined }
286+ * @returns {Array<HastElementContent> | HastElementContent | undefined }
302287 * Resulting hast node.
303288 */
304289// To do: next major: do not expose, keep bound.
0 commit comments