Skip to content

Commit 5822e6a

Browse files
committed
Update @types/hast, utilities
1 parent 6b26484 commit 5822e6a

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

lib/index.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
/**
22
* @typedef {import('hast').Root} HastRoot
3-
* @typedef {import('hast').DocType} HastDoctype
3+
* @typedef {import('hast').RootContent} HastRootContent
4+
* @typedef {import('hast').Doctype} HastDoctype
45
* @typedef {import('hast').Element} HastElement
56
* @typedef {import('hast').Text} HastText
67
* @typedef {import('hast').Comment} HastComment
7-
* @typedef {import('hast').Content} HastChild
8+
* @typedef {import('hast').Nodes} HastNodes
89
*/
910

1011
/**
11-
* @typedef {HastChild | HastRoot} HastNode
12-
*
1312
* @callback AfterTransform
1413
* Callback called when each node is transformed.
15-
* @param {HastNode} hastNode
14+
* @param {HastNodes} hastNode
1615
* hast node that was handled.
1716
* @param {Node} domNode
1817
* Corresponding DOM node.
@@ -54,7 +53,7 @@ const own = {}.hasOwnProperty
5453
/**
5554
* Transform a hast tree to a DOM tree
5655
*
57-
* @param {HastNode} tree
56+
* @param {HastNodes} tree
5857
* Tree to transform.
5958
* @param {Options | null | undefined} [options]
6059
* Configuration (optional).
@@ -73,7 +72,7 @@ export function toDom(tree, options) {
7372
}
7473

7574
/**
76-
* @param {HastNode} node
75+
* @param {HastNodes} node
7776
* Node to transform.
7877
* @param {State} state
7978
* Info passed around about the current state.
@@ -89,7 +88,7 @@ function transform(node, state) {
8988
/**
9089
* Transform any hast node.
9190
*
92-
* @param {HastNode} node
91+
* @param {HastNodes} node
9392
* Node to transform.
9493
* @param {State} state
9594
* Info passed around about the current state.
@@ -307,7 +306,7 @@ function element(node, state) {
307306
*
308307
* @param {Node} node
309308
* DOM node to append to.
310-
* @param {Array<HastChild>} children
309+
* @param {Array<HastRootContent>} children
311310
* hast children.
312311
* @param {State} state
313312
* Info passed around about the current state.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"index.js"
3535
],
3636
"dependencies": {
37+
"@types/hast": "^3.0.0",
3738
"property-information": "^6.0.0",
3839
"web-namespaces": "^2.0.0"
3940
},
@@ -42,7 +43,7 @@
4243
"@types/node": "^20.0.0",
4344
"@types/w3c-xmlserializer": "^2.0.0",
4445
"c8": "^8.0.0",
45-
"hastscript": "^7.0.0",
46+
"hastscript": "^8.0.0",
4647
"jsdom": "^22.0.0",
4748
"prettier": "^3.0.0",
4849
"remark-cli": "^11.0.0",

test/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('../lib/index.js').HastNode} HastNode
2+
* @typedef {import('hast').Nodes} Nodes
33
*/
44

55
import assert from 'node:assert/strict'
@@ -49,7 +49,7 @@ test('toDom', () => {
4949
toDom({
5050
type: 'root',
5151
children: [
52-
{type: 'doctype', name: 'html'},
52+
{type: 'doctype'},
5353
{
5454
type: 'element',
5555
tagName: 'html',
@@ -170,7 +170,6 @@ test('toDom', () => {
170170
)
171171

172172
assert.equal(
173-
// @ts-expect-error hast types out of date.
174173
serializeNodeToHtmlString(toDom({type: 'doctype'})),
175174
'<!DOCTYPE html>',
176175
'creates a doctype node'
@@ -367,7 +366,7 @@ test('toDom', () => {
367366

368367
assert.deepEqual(
369368
(() => {
370-
/** @type {Array<[HastNode, string]>} */
369+
/** @type {Array<[Nodes, string]>} */
371370
const calls = []
372371
toDom(h('html', [h('title', 'Hi')]), {
373372
afterTransform(node, transformed) {
@@ -396,7 +395,7 @@ test('fixtures', async () => {
396395

397396
const treeUrl = new URL(folder + '/index.json', base)
398397
const fixtureUrl = new URL(folder + '/index.html', base)
399-
/** @type {HastNode} */
398+
/** @type {Nodes} */
400399
const tree = JSON.parse(String(await fs.readFile(treeUrl)))
401400
const dom = toDom(tree)
402401
const actual = serializeNodeToHtmlString(dom)

0 commit comments

Comments
 (0)