Skip to content

Commit f0ceab5

Browse files
committed
Update @types/hast, utilities
1 parent 341c1ed commit f0ceab5

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

lib/index.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
* @typedef {import('unist').Point} Point
1313
*
1414
* @typedef {import('hast').Root} Root
15-
* @typedef {import('hast').DocType} Doctype
15+
* @typedef {import('hast').Doctype} Doctype
1616
* @typedef {import('hast').Element} Element
1717
* @typedef {import('hast').Text} Text
1818
* @typedef {import('hast').Comment} Comment
19-
* @typedef {import('hast').Content} Content
19+
* @typedef {import('hast').RootContent} RootContent
20+
* @typedef {import('hast').Nodes} Nodes
2021
*
2122
* @typedef {import('mdast-util-to-hast').Raw} Raw
2223
*/
2324

2425
/**
25-
* @typedef {Root | Content} Node
26-
*
27-
* @typedef {{type: 'comment', value: {stitch: Node}}} Stitch
26+
* @typedef {{type: 'comment', value: {stitch: Nodes}}} Stitch
2827
*
2928
* @typedef Options
3029
* Configuration.
@@ -40,7 +39,7 @@
4039
* Info passed around about the current state.
4140
* @property {Parser<DefaultTreeAdapterMap>} parser
4241
* Current parser.
43-
* @property {(node: Node) => void} handle
42+
* @property {(node: Nodes) => void} handle
4443
* Add a hast node to the parser.
4544
* @property {boolean} stitches
4645
* Whether there are stitches.
@@ -75,16 +74,16 @@ const parseOptions = {sourceCodeLocationInfo: true, scriptingEnabled: false}
7574
* Pass a hast tree through an HTML parser, which will fix nesting, and turn
7675
* raw nodes into actual nodes.
7776
*
78-
* @param {Node} tree
77+
* @param {Nodes} tree
7978
* Original hast tree to transform.
8079
* @param {Options | null | undefined} [options]
8180
* Configuration.
82-
* @returns {Node}
81+
* @returns {Nodes}
8382
* Parsed again tree.
8483
*/
8584
export function raw(tree, options) {
8685
const document = documentMode(tree)
87-
/** @type {(node: Node, state: State) => void} */
86+
/** @type {(node: Nodes, state: State) => void} */
8887
const one = zwitch('type', {
8988
handlers: {root, element, text, comment, doctype, raw: handleRaw},
9089
unknown
@@ -137,7 +136,7 @@ export function raw(tree, options) {
137136
/**
138137
* Transform all nodes
139138
*
140-
* @param {Array<Content>} nodes
139+
* @param {Array<RootContent>} nodes
141140
* hast content.
142141
* @param {State} state
143142
* Info passed around about the current state.
@@ -247,7 +246,7 @@ function doctype(node, state) {
247246
/**
248247
* Transform a stitch.
249248
*
250-
* @param {Node} node
249+
* @param {Nodes} node
251250
* unknown node.
252251
* @param {State} state
253252
* Info passed around about the current state.
@@ -258,7 +257,7 @@ function stitch(node, state) {
258257
// Mark that there are stitches, so we need to walk the tree and revert them.
259258
state.stitches = true
260259

261-
/** @type {Node} */
260+
/** @type {Nodes} */
262261
const clone = cloneWithoutChildren(node)
263262

264263
// Recurse, because to somewhat handle `[<x>]</x>` (where `[]` denotes the
@@ -382,7 +381,7 @@ function handleRaw(node, state) {
382381
* Never.
383382
*/
384383
function unknown(node_, state) {
385-
const node = /** @type {Node} */ (node_)
384+
const node = /** @type {Nodes} */ (node_)
386385

387386
if (
388387
state.options.passThrough &&
@@ -406,7 +405,7 @@ function unknown(node_, state) {
406405
*
407406
* @param {State} state
408407
* Info passed around about the current state.
409-
* @param {Point} point
408+
* @param {Point | undefined} point
410409
* Point.
411410
* @returns {void}
412411
* Nothing.
@@ -479,18 +478,13 @@ function resetTokenizer(state, point) {
479478
*
480479
* @param {State} state
481480
* Info passed around about the current state.
482-
* @param {Point} point
481+
* @param {Point | undefined} point
483482
* Point.
484483
* @returns {void}
485484
* Nothing.
486485
*/
487486
function setPoint(state, point) {
488-
if (
489-
point.line &&
490-
point.column &&
491-
point.offset !== null &&
492-
point.offset !== undefined
493-
) {
487+
if (point && point.offset !== undefined) {
494488
/** @type {Location} */
495489
const location = {
496490
startLine: point.line,
@@ -646,7 +640,7 @@ function endTag(node, state) {
646640
/**
647641
* Check if `node` represents a whole document or a fragment.
648642
*
649-
* @param {Node} node
643+
* @param {Nodes} node
650644
* hast node.
651645
* @returns {boolean}
652646
* Whether this represents a whole document or a fragment.
@@ -663,7 +657,7 @@ function documentMode(node) {
663657
/**
664658
* Get a `parse5` location from a node.
665659
*
666-
* @param {Node | Stitch} node
660+
* @param {Nodes | Stitch} node
667661
* hast node.
668662
* @returns {Location}
669663
* `parse5` location.
@@ -673,19 +667,23 @@ function createParse5Location(node) {
673667
const end = pointEnd(node)
674668

675669
return {
676-
startLine: start.line,
677-
startCol: start.column,
678670
// @ts-expect-error: could be `undefined` in hast, which `parse5` types don’t want.
679-
startOffset: start.offset,
680-
endLine: end.line,
681-
endCol: end.column,
671+
startLine: start?.line,
672+
// @ts-expect-error: could be `undefined` in hast, which `parse5` types don’t want.
673+
startCol: start?.column,
674+
// @ts-expect-error: could be `undefined` in hast, which `parse5` types don’t want.
675+
startOffset: start?.offset,
676+
// @ts-expect-error: could be `undefined` in hast, which `parse5` types don’t want.
677+
endLine: end?.line,
678+
// @ts-expect-error: could be `undefined` in hast, which `parse5` types don’t want.
679+
endCol: end?.column,
682680
// @ts-expect-error: could be `undefined` in hast, which `parse5` types don’t want.
683-
endOffset: end.offset
681+
endOffset: end?.offset
684682
}
685683
}
686684

687685
/**
688-
* @template {Node} NodeType
686+
* @template {Nodes} NodeType
689687
* Node type.
690688
* @param {NodeType} node
691689
* Node to clone.

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@
3434
"index.js"
3535
],
3636
"dependencies": {
37-
"@types/hast": "^2.0.0",
37+
"@types/hast": "^3.0.0",
3838
"extend": "^3.0.0",
39-
"hast-util-from-parse5": "^7.0.0",
40-
"hast-util-to-parse5": "^7.0.0",
41-
"html-void-elements": "^2.0.0",
42-
"mdast-util-to-hast": "^12.0.0",
39+
"hast-util-from-parse5": "^8.0.0",
40+
"hast-util-to-parse5": "^8.0.0",
41+
"html-void-elements": "^3.0.0",
42+
"mdast-util-to-hast": "^13.0.0",
4343
"parse5": "^7.0.0",
44-
"unist-util-position": "^4.0.0",
45-
"unist-util-visit": "^4.0.0",
46-
"vfile": "^5.0.0",
44+
"unist-util-position": "^5.0.0",
45+
"unist-util-visit": "^5.0.0",
46+
"vfile": "^6.0.0",
4747
"web-namespaces": "^2.0.0",
4848
"zwitch": "^2.0.0"
4949
},
5050
"devDependencies": {
5151
"@types/node": "^20.0.0",
5252
"c8": "^8.0.0",
5353
"hast-util-to-html": "^8.0.0",
54-
"hastscript": "^7.0.0",
55-
"mdast-util-from-markdown": "^1.0.0",
54+
"hastscript": "^8.0.0",
55+
"mdast-util-from-markdown": "^2.0.0",
5656
"prettier": "^3.0.0",
5757
"remark-cli": "^11.0.0",
5858
"remark-preset-wooorm": "^9.0.0",
5959
"type-coverage": "^2.0.0",
6060
"typescript": "^5.0.0",
61-
"unist-builder": "^3.0.0",
61+
"unist-builder": "^4.0.0",
6262
"xo": "^0.55.0"
6363
},
6464
"scripts": {

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ test('integration', () => {
859859
assert.deepEqual(hast2, expected, 'should equal the fixture tree')
860860

861861
assert.equal(
862+
// @ts-expect-error: to do: remove when `to-html` is released.
862863
toHtml(hast2),
863864
[
864865
'<p><i>Some title</i></p>',

0 commit comments

Comments
 (0)