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 4, 2023
1 parent 6aa9163 commit 352dbb2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
20 changes: 9 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/**
* @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} HastContent
* @typedef {import('hast').Nodes} HastNodes
*/

/**
* @typedef {HastContent | HastRoot} HastNode
*
* @callback AfterTransform
* Callback called when each node is transformed.
* @param {Node} domNode
* DOM node that was handled.
* @param {HastNode} hastNode
* @param {HastNodes} hastNode
* Corresponding hast node.
* @returns {void}
* Nothing.
Expand All @@ -35,7 +34,7 @@ import {h, s} from 'hastscript'
* DOM tree to transform.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {HastNode}
* @returns {HastNodes}
* Equivalent hast node.
*/
export function fromDom(tree, options) {
Expand All @@ -48,7 +47,7 @@ export function fromDom(tree, options) {
* DOM node to transform.
* @param {Options} options
* Configuration.
* @returns {HastNode | undefined}
* @returns {HastNodes | undefined}
* Equivalent hast node.
*
* Note that certain legacy DOM nodes (i.e., Attr nodes (2), CDATA, processing instructions)
Expand All @@ -65,7 +64,7 @@ function transform(node, options) {
* DOM node to transform.
* @param {Options} options
* Configuration.
* @returns {HastNode | undefined}
* @returns {HastNodes | undefined}
* Equivalent hast node.
*/
function one(node, options) {
Expand Down Expand Up @@ -133,7 +132,6 @@ function root(node, options) {
* Equivalent hast node.
*/
function doctype() {
// @ts-expect-error hast types out of date.
return {type: 'doctype'}
}

Expand Down Expand Up @@ -199,12 +197,12 @@ function element(node, options) {
* DOM node to transform.
* @param {Options} options
* Configuration.
* @returns {Array<HastContent>}
* @returns {Array<HastRootContent>}
* Equivalent hast nodes.
*/
function all(node, options) {
const nodes = node.childNodes
/** @type {Array<HastContent>} */
/** @type {Array<HastRootContent>} */
const children = []
let index = -1

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
"index.js"
],
"dependencies": {
"hastscript": "^7.0.0",
"@types/hast": "^3.0.0",
"hastscript": "^8.0.0",
"web-namespaces": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@types/jsdom": "^21.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"jsdom": "^22.0.0",
"prettier": "^3.0.0",
Expand Down
8 changes: 4 additions & 4 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('../lib/index.js').HastNodes} HastNodes
*/

/* eslint-env browser */
Expand Down Expand Up @@ -161,12 +161,12 @@ test('fromDom', () => {

assert.deepEqual(
(() => {
/** @type {Array<[Node, HastNode|undefined]>} */
/** @type {Array<[Node, HastNodes|undefined]>} */
const calls = []
fromDom(heading, {
/**
* @param {Node} node
* @param {HastNode|undefined} transformed
* @param {HastNodes|undefined} transformed
*/
afterTransform(node, transformed) {
calls.push([node, transformed])
Expand Down Expand Up @@ -203,7 +203,7 @@ test('fixtures', async () => {
const fixtureUrl = new URL(folder + '/index.html', base)
const input = String(await fs.readFile(fixtureUrl))
const actual = fromDom(doc(input))
/** @type {HastNode} */
/** @type {HastNodes} */
let expected

try {
Expand Down

0 comments on commit 352dbb2

Please sign in to comment.