Skip to content

Commit ffbb8a8

Browse files
committed
Change to expect, yield undefined
1 parent 9fd2dfa commit ffbb8a8

File tree

5 files changed

+22
-37
lines changed

5 files changed

+22
-37
lines changed

lib/handlers/list-item.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Info passed around.
1818
* @param {ListItem} node
1919
* mdast node.
20-
* @param {Parents | null | undefined} parent
20+
* @param {Parents | undefined} parent
2121
* Parent of `node`.
2222
* @returns {Element}
2323
* hast node.

lib/handlers/table-row.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Info passed around.
1818
* @param {TableRow} node
1919
* mdast node.
20-
* @param {Parents | null | undefined} parent
20+
* @param {Parents | undefined} parent
2121
* Parent of `node`.
2222
* @returns {Element}
2323
* hast node.

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import {createState} from './state.js'
8282
* mdast tree.
8383
* @param {Options | null | undefined} [options]
8484
* Configuration (optional).
85-
* @returns {HastNodes | null | undefined}
85+
* @returns {HastNodes | undefined}
8686
* hast tree.
8787
*/
8888
// To do: next major: always return a single `root`.

lib/state.js

+16-31
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
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!
@@ -29,36 +29,20 @@
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
@@ -77,13 +61,13 @@
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
@@ -121,7 +105,7 @@
121105

122106
import {visit} from 'unist-util-visit'
123107
import {position} from 'unist-util-position'
124-
import {handlers} from './handlers/index.js'
108+
import {handlers as defaultHandlers} from './handlers/index.js'
125109

126110
const 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.

readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Transform mdast to hast.
135135

136136
###### Returns
137137

138-
hast tree ([`HastNode | null | undefined`][hast-node]).
138+
hast tree ([`HastNode | undefined`][hast-node]).
139139

140140
##### Notes
141141

@@ -214,12 +214,12 @@ Handle a node (TypeScript).
214214
— info passed around
215215
* `node` ([`MdastNode`][mdast-node])
216216
— node to handle
217-
* `parent` ([`MdastNode | null | undefined`][mdast-node])
217+
* `parent` ([`MdastNode | undefined`][mdast-node])
218218
— parent of `node`
219219

220220
###### Returns
221221

222-
Result ([`HastNode | Array<HastNode> | null | undefined`][mdast-node]).
222+
Result ([`Array<HastNode> | HastNode | undefined`][hast-node]).
223223

224224
### `Handlers`
225225

0 commit comments

Comments
 (0)