Skip to content

Commit abd9091

Browse files
committedAug 8, 2023
Update @types/hast, utilities
1 parent 5525b0d commit abd9091

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed
 

‎lib/index.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/**
2-
* @typedef {import('hast').Root} Root
3-
* @typedef {import('hast').Content} Content
2+
* @typedef {import('hast').Nodes} Nodes
3+
* @typedef {import('hast').RootContent} RootContent
44
*/
55

66
/**
7-
* @typedef {Root | Content} Node
8-
*
97
* @typedef Options
108
* Configuration.
119
* @property {string | null | undefined} [comment='more']
@@ -16,7 +14,7 @@
1614
* are assumed to be somewhat reasonably placed.
1715
* This option prevents searching giant documents for some comment
1816
* that probably won’t be found at the end.
19-
* @property {Array<Content> | null | undefined} [ignore=[]]
17+
* @property {Array<RootContent> | null | undefined} [ignore=[]]
2018
* Nodes to exclude from the resulting tree.
2119
* These are not counted towards `size`.
2220
*/
@@ -26,7 +24,7 @@ import {truncate} from 'hast-util-truncate'
2624
/**
2725
* Truncate `tree` to a certain comment.
2826
*
29-
* @template {Node} Tree
27+
* @template {Nodes} Tree
3028
* Type of tree.
3129
* @param {Tree} tree
3230
* Tree to truncate.
@@ -51,9 +49,9 @@ export function excerpt(tree, options) {
5149
/**
5250
* Truncate `node`.
5351
*
54-
* @param {Node} node
52+
* @param {Nodes} node
5553
* Node to truncate.
56-
* @returns {Node | undefined}
54+
* @returns {Nodes | undefined}
5755
* Copy of `node` or `undefined` when done.
5856
*/
5957
function preorder(node) {
@@ -75,18 +73,17 @@ export function excerpt(tree, options) {
7573
return
7674
}
7775

78-
/** @type {Node} */
76+
/** @type {Nodes} */
7977
const replacement = {...node}
8078

8179
if ('children' in node) {
82-
/** @type {Array<Content>} */
80+
/** @type {Array<RootContent>} */
8381
const children = []
8482
let index = -1
8583

8684
while (++index < node.children.length && !found) {
8785
const child = node.children[index]
88-
const result = preorder(child)
89-
// @ts-expect-error: assume content model matches.
86+
const result = /** @type {RootContent | undefined} */ (preorder(child))
9087
if (result) children.push(result)
9188
}
9289

‎package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@
3434
"index.js"
3535
],
3636
"dependencies": {
37-
"@types/hast": "^2.0.0",
38-
"hast-util-truncate": "^1.0.0"
37+
"@types/hast": "^3.0.0",
38+
"hast-util-truncate": "^2.0.0"
3939
},
4040
"devDependencies": {
4141
"@types/node": "^20.0.0",
4242
"c8": "^8.0.0",
43-
"hast-util-select": "^5.0.0",
44-
"hastscript": "^7.0.0",
45-
"mdast-util-from-markdown": "^1.0.0",
46-
"mdast-util-mdx": "^2.0.0",
47-
"mdast-util-to-hast": "^12.0.0",
48-
"micromark-extension-mdxjs": "^1.0.0",
43+
"hast-util-select": "^6.0.0",
44+
"hastscript": "^8.0.0",
45+
"mdast-util-from-markdown": "^2.0.0",
46+
"mdast-util-mdx": "^3.0.0",
47+
"mdast-util-to-hast": "^13.0.0",
48+
"micromark-extension-mdxjs": "^2.0.0",
4949
"prettier": "^3.0.0",
5050
"remark-cli": "^11.0.0",
5151
"remark-preset-wooorm": "^9.0.0",
5252
"type-coverage": "^2.0.0",
5353
"typescript": "^5.0.0",
54-
"unist-builder": "^3.0.0",
55-
"unist-util-remove-position": "^4.0.0",
54+
"unist-builder": "^4.0.0",
55+
"unist-util-remove-position": "^5.0.0",
5656
"xo": "^0.55.0"
5757
},
5858
"scripts": {

‎test.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,17 @@ test('excerpt', () => {
105105
'should support `ignore`'
106106
)
107107

108+
const tree2 = fromMarkdown('Some text\n\n{/* more */}\n\nSome more text', {
109+
extensions: [mdxjs()],
110+
mdastExtensions: [mdxFromMarkdown()]
111+
})
112+
removePosition(tree2)
113+
108114
assert.deepEqual(
109115
excerpt(
110-
// @ts-expect-error: hush!
111-
toHast(
112-
removePosition(
113-
fromMarkdown('Some text\n\n{/* more */}\n\nSome more text', {
114-
extensions: [mdxjs()],
115-
mdastExtensions: [mdxFromMarkdown()]
116-
})
117-
),
118-
{passThrough: ['mdxFlowExpression', 'mdxTextExpression', 'mdxjsEsm']}
119-
)
116+
toHast(tree2, {
117+
passThrough: ['mdxFlowExpression', 'mdxTextExpression', 'mdxjsEsm']
118+
})
120119
),
121120
u('root', [h('p', 'Some text'), u('text', '\n')]),
122121
'should integrate w/ `mdast-util-mdx` (support `/* comments */`)'

0 commit comments

Comments
 (0)