Skip to content

Commit 04a70a3

Browse files
committed
Update @types/unist
1 parent 8beaeb8 commit 04a70a3

File tree

3 files changed

+21
-43
lines changed

3 files changed

+21
-43
lines changed

index.test-d.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,27 @@
11
import {expectAssignable, expectNotType, expectType} from 'tsd'
22
import type {
33
Blockquote,
4-
Content,
54
Definition,
65
Delete,
76
Emphasis,
8-
Footnote,
97
FootnoteDefinition,
108
Heading,
119
Link,
1210
LinkReference,
1311
List,
1412
ListItem,
13+
Nodes,
1514
Paragraph,
15+
Parents,
1616
PhrasingContent,
1717
Root,
18+
RootContent,
1819
Strong,
19-
Table,
20-
TableCell,
21-
TableRow
20+
TableCell
2221
} from 'mdast'
2322
import type {Node, Parent} from 'unist'
2423
import {CONTINUE, EXIT, SKIP, visitParents} from './index.js'
2524

26-
// To do: use `mdast` when released.
27-
type Nodes = Root | Content
28-
29-
// To do: use `mdast` when released.
30-
type Parents =
31-
| Blockquote
32-
| Delete
33-
| Emphasis
34-
| Footnote
35-
| FootnoteDefinition
36-
| Heading
37-
| Link
38-
| LinkReference
39-
| List
40-
| ListItem
41-
| Paragraph
42-
| Root
43-
| Strong
44-
| Table
45-
| TableCell
46-
| TableRow
47-
4825
/* Setup */
4926
const implicitTree = {
5027
type: 'root',
@@ -147,7 +124,7 @@ visitParents(sampleTree, isHeading2, function (node) {
147124
// ## Combined tests
148125
visitParents(sampleTree, ['heading', {depth: 1}, isHeading], function (node) {
149126
// Unfortunately TS casts things in arrays too vague.
150-
expectType<Root | Content>(node)
127+
expectType<Root | RootContent>(node)
151128
})
152129

153130
// To do: update to `unist-util-is` should make this work?
@@ -156,7 +133,7 @@ visitParents(sampleTree, ['heading', {depth: 1}, isHeading], function (node) {
156133
// ['heading', {depth: 1}, isHeading] as const,
157134
// function (node) {
158135
// // Unfortunately TS casts things in arrays too vague.
159-
// expectType<Root | Content>(node)
136+
// expectType<Root | RootContent>(node)
160137
// }
161138
// )
162139

@@ -212,9 +189,7 @@ visitParents(sampleTree, 'tableCell', function (node) {
212189
visitParents(node, function (node, parents) {
213190
expectType<TableCell | PhrasingContent>(node)
214191
expectType<
215-
Array<
216-
Delete | Emphasis | Footnote | Link | LinkReference | Strong | TableCell
217-
>
192+
Array<Delete | Emphasis | Link | LinkReference | Strong | TableCell>
218193
>(parents)
219194
})
220195
})

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
"index.js"
4444
],
4545
"dependencies": {
46-
"@types/unist": "^2.0.0",
47-
"unist-util-is": "^5.0.0"
46+
"@types/unist": "^3.0.0",
47+
"unist-util-is": "^6.0.0"
4848
},
4949
"devDependencies": {
50-
"@types/hast": "^2.0.0",
51-
"@types/mdast": "^3.0.0",
50+
"@types/hast": "^3.0.0",
51+
"@types/mdast": "^4.0.0",
5252
"@types/node": "^20.0.0",
53-
"@types/xast": "^1.0.0",
53+
"@types/xast": "^2.0.0",
5454
"c8": "^8.0.0",
5555
"mdast-util-from-markdown": "^1.0.0",
5656
"mdast-util-gfm": "^2.0.0",

test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* @typedef {import('hast').Root} HastRoot
3+
* @typedef {import('mdast').Parents} Parents
34
* @typedef {import('mdast').PhrasingContent} PhrasingContent
4-
* @typedef {import('unist').Parent} Parent
5+
* @typedef {import('mdast').Root} Root
56
* @typedef {import('xast').Root} XastRoot
67
*/
78

@@ -13,7 +14,10 @@ import {gfmFromMarkdown} from 'mdast-util-gfm'
1314
import {gfm} from 'micromark-extension-gfm'
1415
import {EXIT, SKIP, CONTINUE, visitParents} from 'unist-util-visit-parents'
1516

16-
const tree = fromMarkdown('Some _emphasis_, **importance**, and `code`.')
17+
// To do: remove cast when `mdast-util-from-markdown` is updated.
18+
const tree = /** @type {Root} */ (
19+
fromMarkdown('Some _emphasis_, **importance**, and `code`.')
20+
)
1721
const paragraph = tree.children[0]
1822
assert(paragraph.type === 'paragraph')
1923
const emphasis = paragraph.children[1]
@@ -55,8 +59,7 @@ const reverseTypes = [
5559
'text'
5660
]
5761

58-
// To do: use `Parents` from `mdast` when released.
59-
/** @type {Array<Array<Parent>>} */
62+
/** @type {Array<Array<Parents>>} */
6063
const ancestors = [
6164
[],
6265
[tree],
@@ -71,8 +74,7 @@ const ancestors = [
7174
[tree, paragraph]
7275
]
7376

74-
// To do: use `Parents` from `mdast` when released.
75-
/** @type {Array<Array<Parent>>} */
77+
/** @type {Array<Array<Parents>>} */
7678
const textAncestors = [
7779
[tree, paragraph],
7880
[tree, paragraph, emphasis],
@@ -578,6 +580,7 @@ test('visitParents', async function (t) {
578580
{
579581
type: 'element',
580582
name: 'xml',
583+
attributes: {},
581584
children: [{type: 'text', value: 'Oh no!'}]
582585
}
583586
]

0 commit comments

Comments
 (0)