15
15
/**
16
16
* @typedef EmbeddedHastFields
17
17
* hast fields.
18
- * @property {string | null | undefined } [hName]
18
+ * @property {string | undefined } [hName]
19
19
* Generate a specific element with this tag name instead.
20
- * @property {HastProperties | null | undefined } [hProperties]
20
+ * @property {HastProperties | undefined } [hProperties]
21
21
* Generate an element with these properties instead.
22
- * @property {Array<HastElementContent> | null | undefined } [hChildren]
22
+ * @property {Array<HastElementContent> | undefined } [hChildren]
23
23
* Generate an element with this content instead.
24
24
*
25
25
* To do: type data!
29
29
*
30
30
* To do: type data!
31
31
*
32
- * @typedef {MdastNodes & {data?: MdastData | null | undefined} } MdastNodeWithData
32
+ * @typedef {MdastNodes & {data?: MdastData | undefined} } MdastNodeWithData
33
33
* mdast node with embedded hast data.
34
34
*
35
35
* To do: type data!
36
36
*
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
- *
53
37
* @callback Handler
54
38
* Handle a node.
55
39
* @param {State } state
56
40
* Info passed around.
57
41
* @param {any } node
58
42
* mdast node to handle.
59
- * @param {MdastParents | null | undefined } parent
43
+ * @param {MdastParents | undefined } parent
60
44
* Parent of `node`.
61
- * @returns {Array<HastElementContent> | HastElementContent | null | undefined }
45
+ * @returns {Array<HastElementContent> | HastElementContent | undefined }
62
46
* hast node.
63
47
*
64
48
* @typedef State
77
61
* Identifiers of order when footnote calls first appear in tree order.
78
62
* @property {Handlers } handlers
79
63
* 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
81
65
* Transform an mdast node to hast.
82
66
* @property {Options } options
83
67
* Configuration.
84
68
* @property {(from: MdastNodes, node: HastNodes) => void } patch
85
69
* 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
87
71
* Wrap `nodes` with line endings between each node, adds initial/final line endings when `loose`.
88
72
*
89
73
* @typedef Options
121
105
122
106
import { visit } from 'unist-util-visit'
123
107
import { position } from 'unist-util-position'
124
- import { handlers } from './handlers/index.js'
108
+ import { handlers as defaultHandlers } from './handlers/index.js'
125
109
126
110
const own = { } . hasOwnProperty
127
111
@@ -143,6 +127,10 @@ export function createState(tree, options) {
143
127
const footnoteById = new Map ( )
144
128
/** @type {Map<string, number> } */
145
129
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 }
146
134
147
135
/** @type {State } */
148
136
const state = {
@@ -152,13 +140,10 @@ export function createState(tree, options) {
152
140
footnoteById,
153
141
footnoteCounts,
154
142
footnoteOrder : [ ] ,
155
- // @ts -expect-error: fix `null` handling?
156
- handlers : { ...handlers , ...settings . handlers } ,
157
- // @ts -expect-error: fix `null` handling.
143
+ handlers,
158
144
one : oneBound ,
159
145
options : settings ,
160
146
patch,
161
- // @ts -expect-error: fix `null` handling.
162
147
wrap
163
148
}
164
149
@@ -185,7 +170,7 @@ export function createState(tree, options) {
185
170
* mdast node.
186
171
* @param {MdastParents | undefined } [parent]
187
172
* Parent of `node`.
188
- * @returns {Array<HastElementContent> | HastElementContent | null | undefined }
173
+ * @returns {Array<HastElementContent> | HastElementContent | undefined }
189
174
* Resulting hast node.
190
175
*/
191
176
function oneBound ( node , parent ) {
@@ -298,7 +283,7 @@ function applyData(from, to) {
298
283
* mdast node.
299
284
* @param {MdastParents | undefined } [parent]
300
285
* Parent of `node`.
301
- * @returns {Array<HastElementContent> | HastElementContent | null | undefined }
286
+ * @returns {Array<HastElementContent> | HastElementContent | undefined }
302
287
* Resulting hast node.
303
288
*/
304
289
// To do: next major: do not expose, keep bound.
0 commit comments