Skip to content

Commit

Permalink
Update @types/hast, utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 2, 2023
1 parent 6b26484 commit 5822e6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
17 changes: 8 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/**
* @typedef {import('hast').Root} HastRoot
* @typedef {import('hast').DocType} HastDoctype
* @typedef {import('hast').RootContent} HastRootContent
* @typedef {import('hast').Doctype} HastDoctype
* @typedef {import('hast').Element} HastElement
* @typedef {import('hast').Text} HastText
* @typedef {import('hast').Comment} HastComment
* @typedef {import('hast').Content} HastChild
* @typedef {import('hast').Nodes} HastNodes
*/

/**
* @typedef {HastChild | HastRoot} HastNode
*
* @callback AfterTransform
* Callback called when each node is transformed.
* @param {HastNode} hastNode
* @param {HastNodes} hastNode
* hast node that was handled.
* @param {Node} domNode
* Corresponding DOM node.
Expand Down Expand Up @@ -54,7 +53,7 @@ const own = {}.hasOwnProperty
/**
* Transform a hast tree to a DOM tree
*
* @param {HastNode} tree
* @param {HastNodes} tree
* Tree to transform.
* @param {Options | null | undefined} [options]
* Configuration (optional).
Expand All @@ -73,7 +72,7 @@ export function toDom(tree, options) {
}

/**
* @param {HastNode} node
* @param {HastNodes} node
* Node to transform.
* @param {State} state
* Info passed around about the current state.
Expand All @@ -89,7 +88,7 @@ function transform(node, state) {
/**
* Transform any hast node.
*
* @param {HastNode} node
* @param {HastNodes} node
* Node to transform.
* @param {State} state
* Info passed around about the current state.
Expand Down Expand Up @@ -307,7 +306,7 @@ function element(node, state) {
*
* @param {Node} node
* DOM node to append to.
* @param {Array<HastChild>} children
* @param {Array<HastRootContent>} children
* hast children.
* @param {State} state
* Info passed around about the current state.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"index.js"
],
"dependencies": {
"@types/hast": "^3.0.0",
"property-information": "^6.0.0",
"web-namespaces": "^2.0.0"
},
Expand All @@ -42,7 +43,7 @@
"@types/node": "^20.0.0",
"@types/w3c-xmlserializer": "^2.0.0",
"c8": "^8.0.0",
"hastscript": "^7.0.0",
"hastscript": "^8.0.0",
"jsdom": "^22.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
Expand Down
9 changes: 4 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('../lib/index.js').HastNode} HastNode
* @typedef {import('hast').Nodes} Nodes
*/

import assert from 'node:assert/strict'
Expand Down Expand Up @@ -49,7 +49,7 @@ test('toDom', () => {
toDom({
type: 'root',
children: [
{type: 'doctype', name: 'html'},
{type: 'doctype'},
{
type: 'element',
tagName: 'html',
Expand Down Expand Up @@ -170,7 +170,6 @@ test('toDom', () => {
)

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

assert.deepEqual(
(() => {
/** @type {Array<[HastNode, string]>} */
/** @type {Array<[Nodes, string]>} */
const calls = []
toDom(h('html', [h('title', 'Hi')]), {
afterTransform(node, transformed) {
Expand Down Expand Up @@ -396,7 +395,7 @@ test('fixtures', async () => {

const treeUrl = new URL(folder + '/index.json', base)
const fixtureUrl = new URL(folder + '/index.html', base)
/** @type {HastNode} */
/** @type {Nodes} */
const tree = JSON.parse(String(await fs.readFile(treeUrl)))
const dom = toDom(tree)
const actual = serializeNodeToHtmlString(dom)
Expand Down

0 comments on commit 5822e6a

Please sign in to comment.