Skip to content

Commit 3b247d3

Browse files
committed
Update @types/hast, utilities
1 parent d97b228 commit 3b247d3

File tree

2 files changed

+42
-25
lines changed

2 files changed

+42
-25
lines changed

lib/index.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
/**
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
45
* @typedef {import('hast').Text} Text
56
* @typedef {import('hast').Comment} Comment
6-
* @typedef {import('hast').Root} Root
77
* @typedef {import('hast').Element} Element
88
*/
99

1010
/**
11-
* @typedef {Content | Root} Node
12-
* Any node.
13-
*
14-
* @typedef {Extract<Node, import('unist').Parent>} Parent
15-
* Any parent.
16-
*
1711
* @typedef {'normal' | 'pre' | 'nowrap' | 'pre-wrap'} Whitespace
1812
* Valid and useful whitespace values (from CSS).
1913
*
@@ -59,7 +53,7 @@ const searchTabOrSpaces = /[\t ]+/g
5953

6054
const br = convertElement('br')
6155
const p = convertElement('p')
62-
const cell = convertElement(['th', 'td'])
56+
const cell = convertElement(isCell)
6357
const row = convertElement('tr')
6458

6559
// Note that we don’t need to include void elements here as they don’t have text.
@@ -151,7 +145,7 @@ const blockOrCaption = convertElement([
151145
* with Chinese, Japanese, or Yi writing systems
152146
* * replaced elements (such as `audio`) are treated like non-replaced elements
153147
*
154-
* @param {Node} tree
148+
* @param {Nodes} tree
155149
* Tree to turn into text.
156150
* @param {Options} [options]
157151
* Configuration (optional).
@@ -255,8 +249,8 @@ export function toText(tree, options = {}) {
255249
/**
256250
* <https://html.spec.whatwg.org/#inner-text-collection-steps>
257251
*
258-
* @param {Node} node
259-
* @param {Parent} parent
252+
* @param {Nodes} node
253+
* @param {Parents} parent
260254
* @param {CollectionInfo} info
261255
* @returns {Array<string | BreakNumber>}
262256
*/
@@ -279,7 +273,7 @@ function innerTextCollection(node, parent, info) {
279273
*
280274
* @param {Element} node
281275
* Element node.
282-
* @param {Parent} parent
276+
* @param {Parents} parent
283277
* @param {CollectionInfo} info
284278
* Info on current collection.
285279
* @returns {Array<string | BreakNumber>}
@@ -330,7 +324,11 @@ function collectElement(node, parent, info) {
330324
// See: <https://html.spec.whatwg.org/#tables-2>
331325
// Note: needs further investigation as this does not account for implicit
332326
// 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+
) {
334332
suffix = '\n'
335333
}
336334

@@ -369,7 +367,11 @@ function collectElement(node, parent, info) {
369367
// (tab) character to items.
370368
//
371369
// 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+
) {
373375
items.push('\t')
374376
}
375377

@@ -558,7 +560,7 @@ function trimAndCollapseSpacesAndTabs(value, breakBefore, breakAfter) {
558560
*
559561
* We don’t support void elements here (so `nobr wbr` -> `normal` is ignored).
560562
*
561-
* @param {Node} node
563+
* @param {Nodes} node
562564
* Node (typically `Element`).
563565
* @param {CollectionInfo} info
564566
* Info on current collection.
@@ -599,12 +601,27 @@ function inferWhitespace(node, info) {
599601
return info.whitespace
600602
}
601603

602-
/** @type {TestFunctionAnything} */
604+
/**
605+
* @type {TestFunction}
606+
* @param {Element} node
607+
* @returns {node is {properties: {hidden: true}}}
608+
*/
603609
function hidden(node) {
604610
return Boolean((node.properties || {}).hidden)
605611
}
606612

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+
*/
608625
function closedDialog(node) {
609626
return node.tagName === 'dialog' && !(node.properties || {}).open
610627
}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@
3535
"index.js"
3636
],
3737
"dependencies": {
38-
"@types/hast": "^2.0.0",
39-
"@types/unist": "^2.0.0",
40-
"hast-util-is-element": "^2.0.0",
41-
"unist-util-find-after": "^4.0.0"
38+
"@types/hast": "^3.0.0",
39+
"@types/unist": "^3.0.0",
40+
"hast-util-is-element": "^3.0.0",
41+
"unist-util-find-after": "^5.0.0"
4242
},
4343
"devDependencies": {
4444
"@types/node": "^20.0.0",
4545
"c8": "^8.0.0",
46-
"hastscript": "^7.0.0",
46+
"hastscript": "^8.0.0",
4747
"prettier": "^3.0.0",
4848
"remark-cli": "^11.0.0",
4949
"remark-preset-wooorm": "^9.0.0",
5050
"type-coverage": "^2.0.0",
5151
"typescript": "^5.0.0",
52-
"unist-builder": "^3.0.0",
52+
"unist-builder": "^4.0.0",
5353
"xo": "^0.55.0"
5454
},
5555
"scripts": {

0 commit comments

Comments
 (0)