Skip to content

Commit 346e332

Browse files
committed
Update dev-dependencies
1 parent 2fc4c23 commit 346e332

File tree

3 files changed

+26
-43
lines changed

3 files changed

+26
-43
lines changed

index.js

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/**
2-
* @typedef {Parent['children'][number]|Root} Node
3-
* @typedef {import('mdast').Parent} Parent
4-
* @typedef {import('mdast').Literal} Literal
2+
* @typedef {import('unist').Node} UnistNode
3+
* @typedef {import('unist').Parent} UnistParent
4+
* @typedef {import('unist').Literal} UnistLiteral
5+
*
56
* @typedef {import('mdast').Root} Root
7+
* @typedef {import('mdast').Content} Content
68
* @typedef {import('mdast').List} List
79
* @typedef {import('mdast').ListItem} ListItem
810
* @typedef {import('mdast').Heading} Heading
@@ -17,6 +19,11 @@
1719
* @typedef {import('mdast').Table} Table
1820
*/
1921

22+
/**
23+
* @typedef {Root | Content} Node
24+
* @typedef {Extract<Node, UnistParent>} Parent
25+
* @typedef {Extract<Node, UnistLiteral>} Literal
26+
*/
2027
import nodeAssert from 'node:assert'
2128
import {zwitch} from 'zwitch'
2229
import {mapz} from 'mapz'
@@ -33,7 +40,7 @@ import {
3340
* If `node` is a parent, all children will be asserted too.
3441
*
3542
* @param {unknown} [node]
36-
* @param {Parent} [parent]
43+
* @param {UnistParent | null | undefined} [parent]
3744
* @returns {asserts node is Node}
3845
*/
3946
export function assert(node, parent) {
@@ -44,7 +51,7 @@ export function assert(node, parent) {
4451
* Assert that `node` is a valid mdast parent.
4552
*
4653
* @param {unknown} [node]
47-
* @param {Parent} [parent]
54+
* @param {UnistParent | null | undefined} [parent]
4855
* @returns {asserts node is Parent}
4956
*/
5057
export function parent(node, parent) {
@@ -55,7 +62,7 @@ export function parent(node, parent) {
5562
* Assert that `node` is a valid mdast literal.
5663
*
5764
* @param {unknown} [node]
58-
* @param {Parent} [parent]
65+
* @param {UnistParent | null | undefined} [parent]
5966
* @returns {asserts node is Literal}
6067
*/
6168
export function literal(node, parent) {
@@ -65,67 +72,37 @@ export function literal(node, parent) {
6572
// Construct.
6673
const mdast = zwitch('type', {
6774
// Core interface.
68-
// @ts-expect-error: fine.
6975
unknown,
70-
// @ts-expect-error: fine.
7176
invalid: unknown,
7277
// Per-type handling.
7378
handlers: {
74-
// @ts-expect-error: fine.
7579
root: wrap(root),
76-
// @ts-expect-error: fine.
7780
paragraph: parent,
78-
// @ts-expect-error: fine.
7981
blockquote: parent,
80-
// @ts-expect-error: fine.
8182
tableRow: parent,
82-
// @ts-expect-error: fine.
8383
tableCell: parent,
84-
// @ts-expect-error: fine.
8584
strong: parent,
86-
// @ts-expect-error: fine.
8785
emphasis: parent,
88-
// @ts-expect-error: fine.
8986
delete: parent,
90-
// @ts-expect-error: fine.
9187
listItem: wrap(listItem),
92-
// @ts-expect-error: fine.
9388
footnote: parent,
94-
// @ts-expect-error: fine.
9589
heading: wrap(heading),
96-
// @ts-expect-error: fine.
9790
text: literal,
98-
// @ts-expect-error: fine.
9991
inlineCode: literal,
100-
// @ts-expect-error: fine.
10192
yaml: literal,
102-
// @ts-expect-error: fine.
10393
toml: literal,
104-
// @ts-expect-error: fine.
10594
code: wrap(code),
106-
// @ts-expect-error: fine.
10795
thematicBreak: _void,
108-
// @ts-expect-error: fine.
10996
break: _void,
110-
// @ts-expect-error: fine.
11197
list: wrap(list),
112-
// @ts-expect-error: fine.
11398
footnoteDefinition: wrap(footnoteDefinition),
114-
// @ts-expect-error: fine.
11599
definition: wrap(definition),
116-
// @ts-expect-error: fine.
117100
link: wrap(link),
118-
// @ts-expect-error: fine.
119101
image: wrap(image),
120-
// @ts-expect-error: fine.
121102
linkReference: wrap(linkReference),
122-
// @ts-expect-error: fine.
123103
imageReference: wrap(imageReference),
124-
// @ts-expect-error: fine.
125104
footnoteReference: wrap(footnoteReference),
126-
// @ts-expect-error: fine.
127105
table: wrap(table),
128-
// @ts-expect-error: fine.
129106
html: literal
130107
}
131108
})
@@ -134,7 +111,7 @@ const all = mapz(mdast, {key: 'children'})
134111

135112
/**
136113
* @param {unknown} node
137-
* @param {Parent} [ancestor]
114+
* @param {UnistParent | null | undefined} [ancestor]
138115
* @returns {asserts node is Node}
139116
*/
140117
function unknown(node, ancestor) {
@@ -157,14 +134,16 @@ function assertParent(node) {
157134
function assertLiteral(node) {
158135
unistLiteral(node)
159136
nodeAssert(
137+
// `value` in unist literals is `any`.
138+
// type-coverage:ignore-next-line
160139
typeof node.value === 'string',
161140
'literal should have a string `value`'
162141
)
163142
}
164143

165144
/**
166145
* @param {unknown} node
167-
* @param {Parent} ancestor
146+
* @param {UnistParent | null | undefined} [ancestor]
168147
* @returns {asserts node is Root}
169148
*/
170149
function root(node, ancestor) {

index.test-d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import {expectType, expectNotType} from 'tsd'
2-
import {Parent} from 'mdast'
3-
import {Node, assert, parent} from './index.js'
2+
import type {Parent as UnistParent} from 'unist'
3+
import type {Root, Content} from 'mdast'
4+
import {assert, parent} from './index.js'
5+
6+
type Node = Root | Content
7+
type Parent = Extract<Node, UnistParent>
48

59
const emptyNode = {type: 'doctype'}
610
const literalNode = {type: 'text', value: 'a'}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
"@types/tape": "^4.0.0",
4242
"c8": "^7.0.0",
4343
"prettier": "^2.0.0",
44-
"remark-cli": "^10.0.0",
44+
"remark-cli": "^11.0.0",
4545
"remark-preset-wooorm": "^9.0.0",
4646
"rimraf": "^3.0.0",
4747
"tape": "^5.0.0",
48-
"tsd": "^0.20.0",
48+
"tsd": "^0.25.0",
4949
"type-coverage": "^2.0.0",
5050
"typescript": "^4.0.0",
51-
"xo": "^0.49.0"
51+
"xo": "^0.53.0"
5252
},
5353
"scripts": {
5454
"prepack": "npm run build && npm run format",

0 commit comments

Comments
 (0)