Skip to content

Commit 16ffea7

Browse files
committed
Update @types/xast, utilities
1 parent 6d3b2c7 commit 16ffea7

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

lib/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/**
22
* @typedef {import('xast').Literal} Literal
3-
* @typedef {import('xast').Root} Root
4-
* @typedef {import('xast').RootChildMap} RootChildMap
3+
* @typedef {import('xast').Nodes} Nodes
54
*/
65

76
/**
87
* @typedef {Literal & {type: 'raw'}} Raw
9-
* @typedef {Root | RootChildMap[keyof RootChildMap]} Node
8+
* To do: improved `Raw` type?
109
*
1110
* @typedef {'"' | "'"} Quote
1211
* XML quotes for attribute values.
@@ -45,7 +44,7 @@ import {one} from './one.js'
4544
/**
4645
* Serialize a xast tree to XML.
4746
*
48-
* @param {Node | Array<Node>} tree
47+
* @param {Array<Nodes> | Nodes} tree
4948
* xast node(s) to serialize.
5049
* @param {Options | null | undefined} [options]
5150
* Configuration.
@@ -67,7 +66,7 @@ export function toXml(tree, options) {
6766
)
6867
}
6968

70-
/** @type {Node} */
69+
/** @type {Nodes} */
7170
// @ts-expect-error Assume no `root` in `node`.
7271
const node = Array.isArray(tree) ? {type: 'root', children: tree} : tree
7372

lib/one.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
/**
2-
* @typedef {import('unist').Parent} UnistParent
3-
* @typedef {import('xast').Root} Root
4-
* @typedef {import('xast').RootChildMap} RootChildMap
2+
* @typedef {import('xast').Nodes} Nodes
3+
* @typedef {import('xast').Parents} Parents
4+
* @typedef {import('xast').RootContent} RootContent
55
* @typedef {import('./index.js').State} State
66
*/
77

8-
/**
9-
* @typedef {Root | RootChildMap[keyof RootChildMap]} Node
10-
* @typedef {Extract<Node, UnistParent>} Parent
11-
* @typedef {Parent['children'][number]} Child
12-
*/
13-
148
import {element} from './element.js'
159
import {text} from './text.js'
1610
import {comment} from './comment.js'
@@ -35,7 +29,7 @@ const handlers = {
3529
/**
3630
* Serialize a node.
3731
*
38-
* @param {Node} node
32+
* @param {Nodes} node
3933
* xast node.
4034
* @param {State} state
4135
* Info passed around about the current state.
@@ -63,15 +57,15 @@ export function one(node, state) {
6357
/**
6458
* Serialize all children of `parent`.
6559
*
66-
* @param {Parent} parent
60+
* @param {Parents} parent
6761
* xast parent node.
6862
* @param {State} state
6963
* Info passed around about the current state.
7064
* @returns {string}
7165
* Serialized XML.
7266
*/
7367
export function all(parent, state) {
74-
/** @type {Array<Child>} */
68+
/** @type {Array<RootContent>} */
7569
const children = (parent && parent.children) || []
7670
let index = -1
7771
/** @type {Array<string>} */

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"index.js"
3232
],
3333
"dependencies": {
34-
"@types/xast": "^1.0.0",
34+
"@types/xast": "^2.0.0",
3535
"ccount": "^2.0.0",
3636
"stringify-entities": "^4.0.0"
3737
},
@@ -43,8 +43,8 @@
4343
"remark-preset-wooorm": "^9.0.0",
4444
"type-coverage": "^2.0.0",
4545
"typescript": "^5.0.0",
46-
"unist-builder": "^3.0.0",
47-
"xastscript": "^3.0.0",
46+
"unist-builder": "^4.0.0",
47+
"xastscript": "^4.0.0",
4848
"xo": "^0.55.0"
4949
},
5050
"scripts": {

test/attribute.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {toXml} from '../index.js'
66

77
test('`element` attributes', async (t) => {
88
assert.deepEqual(
9-
toXml(u('element', {name: 'y'}, [])),
9+
toXml(
10+
// @ts-expect-error: check how runtime does not fail on missing `attributes`.
11+
u('element', {name: 'y'}, [])
12+
),
1013
'<y></y>',
1114
'should ignore missing attributes'
1215
)

0 commit comments

Comments
 (0)