1
1
/**
2
- * @typedef {import('hast-util-is-element').TestFunctionAnything } TestFunctionAnything
3
- * @typedef {import('hast').Content } Content
2
+ * @typedef {import('hast-util-is-element').TestFunction } TestFunction
3
+ * @typedef {import('hast').Nodes } Nodes
4
+ * @typedef {import('hast').Parents } Parents
4
5
* @typedef {import('hast').Text } Text
5
6
* @typedef {import('hast').Comment } Comment
6
- * @typedef {import('hast').Root } Root
7
7
* @typedef {import('hast').Element } Element
8
8
*/
9
9
10
10
/**
11
- * @typedef {Content | Root } Node
12
- * Any node.
13
- *
14
- * @typedef {Extract<Node, import('unist').Parent> } Parent
15
- * Any parent.
16
- *
17
11
* @typedef {'normal' | 'pre' | 'nowrap' | 'pre-wrap' } Whitespace
18
12
* Valid and useful whitespace values (from CSS).
19
13
*
@@ -59,7 +53,7 @@ const searchTabOrSpaces = /[\t ]+/g
59
53
60
54
const br = convertElement ( 'br' )
61
55
const p = convertElement ( 'p' )
62
- const cell = convertElement ( [ 'th' , 'td' ] )
56
+ const cell = convertElement ( isCell )
63
57
const row = convertElement ( 'tr' )
64
58
65
59
// Note that we don’t need to include void elements here as they don’t have text.
@@ -151,7 +145,7 @@ const blockOrCaption = convertElement([
151
145
* with Chinese, Japanese, or Yi writing systems
152
146
* * replaced elements (such as `audio`) are treated like non-replaced elements
153
147
*
154
- * @param {Node } tree
148
+ * @param {Nodes } tree
155
149
* Tree to turn into text.
156
150
* @param {Options } [options]
157
151
* Configuration (optional).
@@ -255,8 +249,8 @@ export function toText(tree, options = {}) {
255
249
/**
256
250
* <https://html.spec.whatwg.org/#inner-text-collection-steps>
257
251
*
258
- * @param {Node } node
259
- * @param {Parent } parent
252
+ * @param {Nodes } node
253
+ * @param {Parents } parent
260
254
* @param {CollectionInfo } info
261
255
* @returns {Array<string | BreakNumber> }
262
256
*/
@@ -279,7 +273,7 @@ function innerTextCollection(node, parent, info) {
279
273
*
280
274
* @param {Element } node
281
275
* Element node.
282
- * @param {Parent } parent
276
+ * @param {Parents } parent
283
277
* @param {CollectionInfo } info
284
278
* Info on current collection.
285
279
* @returns {Array<string | BreakNumber> }
@@ -330,7 +324,11 @@ function collectElement(node, parent, info) {
330
324
// See: <https://html.spec.whatwg.org/#tables-2>
331
325
// Note: needs further investigation as this does not account for implicit
332
326
// rows.
333
- else if ( row ( node ) && findAfter ( parent , node , row ) ) {
327
+ else if (
328
+ row ( node ) &&
329
+ // @ts -expect-error: something up with types of parents.
330
+ findAfter ( parent , node , row )
331
+ ) {
334
332
suffix = '\n'
335
333
}
336
334
@@ -369,7 +367,11 @@ function collectElement(node, parent, info) {
369
367
// (tab) character to items.
370
368
//
371
369
// See: <https://html.spec.whatwg.org/#tables-2>
372
- if ( cell ( node ) && findAfter ( parent , node , cell ) ) {
370
+ if (
371
+ cell ( node ) &&
372
+ // @ts -expect-error: something up with types of parents.
373
+ findAfter ( parent , node , cell )
374
+ ) {
373
375
items . push ( '\t' )
374
376
}
375
377
@@ -558,7 +560,7 @@ function trimAndCollapseSpacesAndTabs(value, breakBefore, breakAfter) {
558
560
*
559
561
* We don’t support void elements here (so `nobr wbr` -> `normal` is ignored).
560
562
*
561
- * @param {Node } node
563
+ * @param {Nodes } node
562
564
* Node (typically `Element`).
563
565
* @param {CollectionInfo } info
564
566
* Info on current collection.
@@ -599,12 +601,27 @@ function inferWhitespace(node, info) {
599
601
return info . whitespace
600
602
}
601
603
602
- /** @type {TestFunctionAnything } */
604
+ /**
605
+ * @type {TestFunction }
606
+ * @param {Element } node
607
+ * @returns {node is {properties: {hidden: true}} }
608
+ */
603
609
function hidden ( node ) {
604
610
return Boolean ( ( node . properties || { } ) . hidden )
605
611
}
606
612
607
- /** @type {TestFunctionAnything } */
613
+ /**
614
+ * @type {TestFunction }
615
+ * @param {Element } node
616
+ * @returns {node is {tagName: 'td' | 'th'} }
617
+ */
618
+ function isCell ( node ) {
619
+ return node . tagName === 'td' || node . tagName === 'th'
620
+ }
621
+
622
+ /**
623
+ * @type {TestFunction }
624
+ */
608
625
function closedDialog ( node ) {
609
626
return node . tagName === 'dialog' && ! ( node . properties || { } ) . open
610
627
}
0 commit comments