Skip to content

Commit 8ec1c56

Browse files
committed
Fix types for changes in @types/unist
1 parent 04f2d0e commit 8ec1c56

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

test.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,90 @@
1+
/**
2+
* @typedef {import('mdast').Root} Root
3+
* @typedef {import('mdast').Text} Text
4+
* @typedef {Root['children'][number]|Root} Node
5+
*/
6+
7+
import assert from 'node:assert'
18
import test from 'tape'
29
import remark from 'remark'
310
import {VFile} from 'vfile'
411
import {source} from './index.js'
512

613
test('unist-util-source', function (t) {
714
var file = new VFile('> + **[Hello](./example)**\n> world.')
15+
/** @type {Node} */
16+
// @ts-expect-error: hush.
817
var node = remark().parse(file)
918

1019
t.equal(source(node, file), '> + **[Hello](./example)**\n> world.', 'root')
1120

21+
assert(node.type === 'root')
1222
node = node.children[0]
23+
assert(node.type === 'blockquote')
1324
t.equal(
1425
source(node, file),
1526
'> + **[Hello](./example)**\n> world.',
1627
'block quote'
1728
)
1829

1930
node = node.children[0]
31+
assert(node.type === 'list')
2032
t.equal(source(node, file), '+ **[Hello](./example)**\n> world.', 'list')
2133

2234
node = node.children[0]
35+
assert(node.type === 'listItem')
2336
t.equal(source(node, file), '+ **[Hello](./example)**\n> world.', 'list item')
2437

2538
node = node.children[0]
39+
assert(node.type === 'paragraph')
2640
t.equal(source(node, file), '**[Hello](./example)**\n> world.', 'paragraph')
2741

2842
node = node.children[0]
43+
assert(node.type === 'strong')
2944
t.equal(source(node, file), '**[Hello](./example)**', 'strong')
3045

3146
node = node.children[0]
47+
assert(node.type === 'link')
3248
t.equal(source(node, file), '[Hello](./example)', 'link')
3349

3450
node = node.children[0]
51+
assert(node.type === 'text')
3552
t.equal(source(node, file), 'Hello', 'text')
3653

37-
t.equal(source({type: node.type, value: node.value}, file), null, 'generated')
54+
t.equal(
55+
source(/** @type {Text} */ ({type: node.type, value: node.value}), file),
56+
null,
57+
'generated'
58+
)
3859

3960
t.equal(source(null, file), null, 'missing')
4061

4162
file = new VFile('a\r\nb')
42-
node = remark().parse(file).children[0]
63+
// @ts-expect-error: hush.
64+
node = remark().parse(file)
65+
assert(node.type === 'root')
66+
node = node.children[0]
67+
assert(node.type === 'paragraph')
4368

4469
t.equal(source(node, file), 'a\r\nb', 'cr + lf')
4570

4671
file = new VFile('a\rb')
47-
node = remark().parse(file).children[0]
72+
// @ts-expect-error: hush.
73+
node = remark().parse(file)
74+
assert(node.type === 'root')
75+
node = node.children[0]
76+
assert(node.type === 'paragraph')
4877

4978
t.equal(source(node, file), 'a\rb', 'cr')
5079

5180
file = new VFile('a\n')
81+
// @ts-expect-error: hush.
5282
node = remark().parse(file)
5383

5484
t.equal(source(node, file), 'a\n', 'eof eol')
5585

5686
file = new VFile('a\n\rb')
87+
// @ts-expect-error: hush.
5788
node = remark().parse(file)
5889

5990
t.equal(source(node, file), 'a\n\rb', 'blank lines')

0 commit comments

Comments
 (0)