Skip to content

Commit 23a91fc

Browse files
committed
Update @types/hast, utilities
1 parent 7a76496 commit 23a91fc

15 files changed

+70
-94
lines changed

lib/handle/comment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @typedef {import('../types.js').Comment} Comment
3-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Parents} Parents
44
* @typedef {import('../types.js').State} State
55
*/
66

@@ -13,7 +13,7 @@ import {stringifyEntities} from 'stringify-entities'
1313
* Node to handle.
1414
* @param {number | undefined} _1
1515
* Index of `node` in `parent.
16-
* @param {Parent | undefined} _2
16+
* @param {Parents | undefined} _2
1717
* Parent of `node`.
1818
* @param {State} state
1919
* Info passed around about the current state.

lib/handle/doctype.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @typedef {import('../types.js').DocType} DocType
3-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Parents} Parents
44
* @typedef {import('../types.js').State} State
55
*/
66

@@ -11,7 +11,7 @@
1111
* Node to handle.
1212
* @param {number | undefined} _2
1313
* Index of `node` in `parent.
14-
* @param {Parent | undefined} _3
14+
* @param {Parents | undefined} _3
1515
* Parent of `node`.
1616
* @param {State} state
1717
* Info passed around about the current state.

lib/handle/element.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @typedef {import('../types.js').State} State
3-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Parents} Parents
44
* @typedef {import('../types.js').Element} Element
55
* @typedef {import('../types.js').Properties} Properties
66
* @typedef {import('../types.js').PropertyValue} PropertyValue
@@ -53,7 +53,7 @@ const constants = {
5353
* Node to handle.
5454
* @param {number | undefined} index
5555
* Index of `node` in `parent.
56-
* @param {Parent | undefined} parent
56+
* @param {Parents | undefined} parent
5757
* Parent of `node`.
5858
* @param {State} state
5959
* Info passed around about the current state.
@@ -89,6 +89,8 @@ export function element(node, index, parent, state) {
8989
// categorisation.
9090
// This enables for example `menuitem`s, which are void in W3C HTML but not
9191
// void in WHATWG HTML, to be stringified properly.
92+
// Note: `menuitem` has since been removed from the HTML spec, and so is no
93+
// longer void.
9294
if (content) selfClosing = false
9395

9496
if (attrs || !omit || !opening(node, index, parent)) {

lib/handle/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('../types.js').State} State
3-
* @typedef {import('../types.js').Node} Node
4-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Nodes} Nodes
4+
* @typedef {import('../types.js').Parents} Parents
55
*/
66

77
import {zwitch} from 'zwitch'
@@ -13,7 +13,7 @@ import {root} from './root.js'
1313
import {text} from './text.js'
1414

1515
/**
16-
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
16+
* @type {(node: Nodes, index: number | undefined, parent: Parents | undefined, state: State) => string}
1717
*/
1818
export const handle = zwitch('type', {
1919
invalid,

lib/handle/raw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @typedef {import('../types.js').State} State
3-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Parents} Parents
44
* @typedef {import('../types.js').Raw} Raw
55
*/
66

@@ -13,7 +13,7 @@ import {text} from './text.js'
1313
* Node to handle.
1414
* @param {number | undefined} index
1515
* Index of `node` in `parent.
16-
* @param {Parent | undefined} parent
16+
* @param {Parents | undefined} parent
1717
* Parent of `node`.
1818
* @param {State} state
1919
* Info passed around about the current state.

lib/handle/root.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @typedef {import('../types.js').Root} Root
3-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Parents} Parents
44
* @typedef {import('../types.js').State} State
55
*/
66

@@ -11,7 +11,7 @@
1111
* Node to handle.
1212
* @param {number | undefined} _1
1313
* Index of `node` in `parent.
14-
* @param {Parent | undefined} _2
14+
* @param {Parents | undefined} _2
1515
* Parent of `node`.
1616
* @param {State} state
1717
* Info passed around about the current state.

lib/handle/text.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @typedef {import('../types.js').State} State
3-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Parents} Parents
44
* @typedef {import('../types.js').Raw} Raw
55
* @typedef {import('../types.js').Text} Text
66
*/
@@ -14,7 +14,7 @@ import {stringifyEntities} from 'stringify-entities'
1414
* Node to handle.
1515
* @param {number | undefined} _
1616
* Index of `node` in `parent.
17-
* @param {Parent | undefined} parent
17+
* @param {Parents | undefined} parent
1818
* Parent of `node`.
1919
* @param {State} state
2020
* Info passed around about the current state.

lib/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @typedef {import('./types.js').Node} Node
3-
* @typedef {import('./types.js').Parent} Parent
4-
* @typedef {import('./types.js').Content} Content
2+
* @typedef {import('./types.js').Nodes} Nodes
3+
* @typedef {import('./types.js').Parents} Parents
4+
* @typedef {import('./types.js').RootContent} RootContent
55
* @typedef {import('./types.js').Options} Options
66
* @typedef {import('./types.js').State} State
77
*/
@@ -13,7 +13,7 @@ import {handle} from './handle/index.js'
1313
/**
1414
* Serialize hast as HTML.
1515
*
16-
* @param {Node | Array<Content>} tree
16+
* @param {Nodes | Array<RootContent>} tree
1717
* Tree to serialize.
1818
* @param {Options | null | undefined} [options]
1919
* Configuration.
@@ -71,11 +71,11 @@ export function toHtml(tree, options) {
7171
*
7272
* @this {State}
7373
* Info passed around about the current state.
74-
* @param {Node} node
74+
* @param {Nodes} node
7575
* Node to handle.
7676
* @param {number | undefined} index
7777
* Index of `node` in `parent.
78-
* @param {Parent | undefined} parent
78+
* @param {Parents | undefined} parent
7979
* Parent of `node`.
8080
* @returns {string}
8181
* Serialized node.
@@ -89,7 +89,7 @@ function one(node, index, parent) {
8989
*
9090
* @this {State}
9191
* Info passed around about the current state.
92-
* @param {Parent | undefined} parent
92+
* @param {Parents | undefined} parent
9393
* Parent whose children to serialize.
9494
* @returns {string}
9595
*/

lib/omission/closing.js

+16-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @typedef {import('../types.js').Element} Element
3-
* @typedef {import('../types.js').Parent} Parent
3+
* @typedef {import('../types.js').Parents} Parents
44
*/
55

66
import {whitespace} from 'hast-util-whitespace'
@@ -19,7 +19,6 @@ export const closing = omission({
1919
rp: rubyElement,
2020
optgroup,
2121
option,
22-
menuitem,
2322
colgroup: headOrColgroupOrCaption,
2423
caption: headOrColgroupOrCaption,
2524
thead,
@@ -37,7 +36,7 @@ export const closing = omission({
3736
* Element.
3837
* @param {number | undefined} index
3938
* Index of element in parent.
40-
* @param {Parent | undefined} parent
39+
* @param {Parents | undefined} parent
4140
* Parent of element.
4241
* @returns {boolean}
4342
* Whether the closing tag can be omitted.
@@ -58,7 +57,7 @@ function headOrColgroupOrCaption(_, index, parent) {
5857
* Element.
5958
* @param {number | undefined} index
6059
* Index of element in parent.
61-
* @param {Parent | undefined} parent
60+
* @param {Parents | undefined} parent
6261
* Parent of element.
6362
* @returns {boolean}
6463
* Whether the closing tag can be omitted.
@@ -75,7 +74,7 @@ function html(_, index, parent) {
7574
* Element.
7675
* @param {number | undefined} index
7776
* Index of element in parent.
78-
* @param {Parent | undefined} parent
77+
* @param {Parents | undefined} parent
7978
* Parent of element.
8079
* @returns {boolean}
8180
* Whether the closing tag can be omitted.
@@ -92,7 +91,7 @@ function body(_, index, parent) {
9291
* Element.
9392
* @param {number | undefined} index
9493
* Index of element in parent.
95-
* @param {Parent | undefined} parent
94+
* @param {Parents | undefined} parent
9695
* Parent of element.
9796
* @returns {boolean}
9897
* Whether the closing tag can be omitted.
@@ -153,7 +152,7 @@ function p(_, index, parent) {
153152
* Element.
154153
* @param {number | undefined} index
155154
* Index of element in parent.
156-
* @param {Parent | undefined} parent
155+
* @param {Parents | undefined} parent
157156
* Parent of element.
158157
* @returns {boolean}
159158
* Whether the closing tag can be omitted.
@@ -170,7 +169,7 @@ function li(_, index, parent) {
170169
* Element.
171170
* @param {number | undefined} index
172171
* Index of element in parent.
173-
* @param {Parent | undefined} parent
172+
* @param {Parents | undefined} parent
174173
* Parent of element.
175174
* @returns {boolean}
176175
* Whether the closing tag can be omitted.
@@ -191,7 +190,7 @@ function dt(_, index, parent) {
191190
* Element.
192191
* @param {number | undefined} index
193192
* Index of element in parent.
194-
* @param {Parent | undefined} parent
193+
* @param {Parents | undefined} parent
195194
* Parent of element.
196195
* @returns {boolean}
197196
* Whether the closing tag can be omitted.
@@ -212,7 +211,7 @@ function dd(_, index, parent) {
212211
* Element.
213212
* @param {number | undefined} index
214213
* Index of element in parent.
215-
* @param {Parent | undefined} parent
214+
* @param {Parents | undefined} parent
216215
* Parent of element.
217216
* @returns {boolean}
218217
* Whether the closing tag can be omitted.
@@ -233,7 +232,7 @@ function rubyElement(_, index, parent) {
233232
* Element.
234233
* @param {number | undefined} index
235234
* Index of element in parent.
236-
* @param {Parent | undefined} parent
235+
* @param {Parents | undefined} parent
237236
* Parent of element.
238237
* @returns {boolean}
239238
* Whether the closing tag can be omitted.
@@ -250,7 +249,7 @@ function optgroup(_, index, parent) {
250249
* Element.
251250
* @param {number | undefined} index
252251
* Index of element in parent.
253-
* @param {Parent | undefined} parent
252+
* @param {Parents | undefined} parent
254253
* Parent of element.
255254
* @returns {boolean}
256255
* Whether the closing tag can be omitted.
@@ -264,37 +263,14 @@ function option(_, index, parent) {
264263
)
265264
}
266265

267-
/**
268-
* Whether to omit `</menuitem>`.
269-
*
270-
* @param {Element} _
271-
* Element.
272-
* @param {number | undefined} index
273-
* Index of element in parent.
274-
* @param {Parent | undefined} parent
275-
* Parent of element.
276-
* @returns {boolean}
277-
* Whether the closing tag can be omitted.
278-
*/
279-
function menuitem(_, index, parent) {
280-
const next = siblingAfter(parent, index)
281-
return (
282-
!next ||
283-
(next.type === 'element' &&
284-
(next.tagName === 'menuitem' ||
285-
next.tagName === 'hr' ||
286-
next.tagName === 'menu'))
287-
)
288-
}
289-
290266
/**
291267
* Whether to omit `</thead>`.
292268
*
293269
* @param {Element} _
294270
* Element.
295271
* @param {number | undefined} index
296272
* Index of element in parent.
297-
* @param {Parent | undefined} parent
273+
* @param {Parents | undefined} parent
298274
* Parent of element.
299275
* @returns {boolean}
300276
* Whether the closing tag can be omitted.
@@ -315,7 +291,7 @@ function thead(_, index, parent) {
315291
* Element.
316292
* @param {number | undefined} index
317293
* Index of element in parent.
318-
* @param {Parent | undefined} parent
294+
* @param {Parents | undefined} parent
319295
* Parent of element.
320296
* @returns {boolean}
321297
* Whether the closing tag can be omitted.
@@ -336,7 +312,7 @@ function tbody(_, index, parent) {
336312
* Element.
337313
* @param {number | undefined} index
338314
* Index of element in parent.
339-
* @param {Parent | undefined} parent
315+
* @param {Parents | undefined} parent
340316
* Parent of element.
341317
* @returns {boolean}
342318
* Whether the closing tag can be omitted.
@@ -352,7 +328,7 @@ function tfoot(_, index, parent) {
352328
* Element.
353329
* @param {number | undefined} index
354330
* Index of element in parent.
355-
* @param {Parent | undefined} parent
331+
* @param {Parents | undefined} parent
356332
* Parent of element.
357333
* @returns {boolean}
358334
* Whether the closing tag can be omitted.
@@ -369,7 +345,7 @@ function tr(_, index, parent) {
369345
* Element.
370346
* @param {number | undefined} index
371347
* Index of element in parent.
372-
* @param {Parent | undefined} parent
348+
* @param {Parents | undefined} parent
373349
* Parent of element.
374350
* @returns {boolean}
375351
* Whether the closing tag can be omitted.

lib/omission/opening.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @typedef {import('../types.js').Element} Element
3-
* @typedef {import('../types.js').Parent} Parent
4-
* @typedef {import('../types.js').Content} Content
3+
* @typedef {import('../types.js').Parents} Parents
4+
* @typedef {import('../types.js').RootContent} RootContent
55
*/
66

77
import {whitespace} from 'hast-util-whitespace'
@@ -94,7 +94,7 @@ function body(node) {
9494
* Element.
9595
* @param {number | undefined} index
9696
* Index of element in parent.
97-
* @param {Parent | undefined} parent
97+
* @param {Parents | undefined} parent
9898
* Parent of element.
9999
* @returns {boolean}
100100
* Whether the opening tag can be omitted.
@@ -124,7 +124,7 @@ function colgroup(node, index, parent) {
124124
* Element.
125125
* @param {number | undefined} index
126126
* Index of element in parent.
127-
* @param {Parent | undefined} parent
127+
* @param {Parents | undefined} parent
128128
* Parent of element.
129129
* @returns {boolean}
130130
* Whether the opening tag can be omitted.

0 commit comments

Comments
 (0)