Skip to content

Commit 9a3fff8

Browse files
committed
Update @types/hast, @types/xast, utilities
1 parent f451c17 commit 9a3fff8

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

lib/index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
/**
22
* @typedef {import('property-information').Schema} Schema
33
* @typedef {import('hast').Root} HastRoot
4-
* @typedef {import('hast').DocType} HastDoctype
4+
* @typedef {import('hast').Doctype} HastDoctype
55
* @typedef {import('hast').Element} HastElement
66
* @typedef {import('hast').Comment} HastComment
77
* @typedef {import('hast').Text} HastText
8-
* @typedef {import('hast').Content} HastContent
8+
* @typedef {import('hast').Nodes} HastNodes
99
* @typedef {import('xast').Root} XastRoot
1010
* @typedef {import('xast').Element} XastElement
1111
* @typedef {import('xast').Text} XastText
1212
* @typedef {import('xast').Comment} XastComment
1313
* @typedef {import('xast').Doctype} XastDoctype
1414
* @typedef {import('xast').Attributes} XastAttributes
15-
* @typedef {import('xast').RootChildMap} XastRootChildMap
16-
* @typedef {import('xast').ElementChildMap} XastElementChildMap
15+
* @typedef {import('xast').RootContent} XastRootContent
16+
* @typedef {import('xast').Nodes} XastNodes
17+
* @typedef {import('xast').ElementContent} XastElementContent
1718
*/
1819

1920
/**
20-
* @typedef {XastRootChildMap[keyof XastRootChildMap]} XastContent
21-
* @typedef {XastRoot | XastContent} XastNode
22-
* @typedef {HastRoot | HastContent} HastNode
23-
*
2421
* @typedef {'html' | 'svg'} Space
2522
* Namespace.
2623
*
@@ -53,7 +50,7 @@ import {zwitch} from 'zwitch'
5350

5451
const own = {}.hasOwnProperty
5552

56-
/** @type {(node: HastNode, state: State) => XastNode} */
53+
/** @type {(node: HastNodes, state: State) => XastNodes} */
5754
const one = zwitch('type', {
5855
handlers: {root, element, text, comment, doctype},
5956
invalid,
@@ -63,11 +60,11 @@ const one = zwitch('type', {
6360
/**
6461
* Turn a hast tree into a xast tree.
6562
*
66-
* @param {HastNode} tree
63+
* @param {HastNodes} tree
6764
* hast tree to transform.
6865
* @param {Space | Options | null | undefined} [options]
6966
* Configuration.
70-
* @returns {XastNode}
67+
* @returns {XastNodes}
7168
* xast tree.
7269
*/
7370
export function toXast(tree, options) {
@@ -116,7 +113,7 @@ function unknown(value) {
116113
* xast node.
117114
*/
118115
function root(node, state) {
119-
/** @type {Array<XastContent>} */
116+
/** @type {Array<XastRootContent>} */
120117
const children = []
121118
let index = -1
122119

@@ -262,7 +259,7 @@ function element(node, state) {
262259
}
263260
}
264261

265-
/** @type {Array<XastElementChildMap[keyof XastElementChildMap]>} */
262+
/** @type {Array<XastElementContent>} */
266263
const children = []
267264
let index = -1
268265

@@ -293,8 +290,8 @@ function element(node, state) {
293290
}
294291

295292
/**
296-
* @param {HastNode} origin
297-
* @param {XastNode} node
293+
* @param {HastNodes} origin
294+
* @param {XastNodes} node
298295
* @returns {void}
299296
*/
300297
function patch(origin, node) {

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@
3535
"index.js"
3636
],
3737
"dependencies": {
38-
"@types/hast": "^2.0.0",
39-
"@types/unist": "^2.0.0",
40-
"@types/xast": "^1.0.0",
38+
"@types/hast": "^3.0.0",
39+
"@types/unist": "^3.0.0",
40+
"@types/xast": "^2.0.0",
4141
"comma-separated-tokens": "^2.0.0",
4242
"property-information": "^6.0.0",
4343
"space-separated-tokens": "^2.0.0",
44-
"unist-util-position": "^4.0.0",
44+
"unist-util-position": "^5.0.0",
4545
"web-namespaces": "^2.0.0",
4646
"zwitch": "^2.0.0"
4747
},
4848
"devDependencies": {
4949
"@types/node": "^20.0.0",
5050
"c8": "^8.0.0",
51-
"hastscript": "^7.0.0",
51+
"hastscript": "^8.0.0",
5252
"prettier": "^3.0.0",
5353
"remark-cli": "^11.0.0",
5454
"remark-preset-wooorm": "^9.0.0",
5555
"type-coverage": "^2.0.0",
5656
"typescript": "^5.0.0",
57-
"unist-builder": "^3.0.0",
58-
"xastscript": "^3.0.0",
57+
"unist-builder": "^4.0.0",
58+
"xastscript": "^4.0.0",
5959
"xo": "^0.55.0"
6060
},
6161
"scripts": {

test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ test('toXast', async (t) => {
6666
type: 'text',
6767
value: 'foo',
6868
position: {
69-
start: {line: 1, column: 1, offset: null},
70-
end: {line: 1, column: 4, offset: null}
69+
start: {line: 1, column: 1, offset: undefined},
70+
end: {line: 1, column: 4, offset: undefined}
7171
}
7272
},
7373
'should support positional information'
@@ -114,7 +114,6 @@ test('toXast', async (t) => {
114114

115115
await t.test('doctype', () => {
116116
assert.deepEqual(
117-
// @ts-expect-error hast@next.
118117
toXast(u('doctype')),
119118
u('doctype', {name: 'html', public: undefined, system: undefined}),
120119
'should support a doctype node'
@@ -164,7 +163,10 @@ test('toXast', async (t) => {
164163

165164
await t.test('attributes', () => {
166165
assert.deepEqual(
167-
toXast(u('element', {tagName: 'br'}, [])),
166+
toXast(
167+
// @ts-expect-error: intentionally missing.
168+
u('element', {tagName: 'br'}, [])
169+
),
168170
x('br', {xmlns: ns.html}),
169171
'should not fail for elements without properties'
170172
)

0 commit comments

Comments
 (0)