Skip to content

Commit d8fae1c

Browse files
committed
Update @types/unist
1 parent 2e92449 commit d8fae1c

File tree

3 files changed

+70
-63
lines changed

3 files changed

+70
-63
lines changed

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Position of `child` in `parent`.
1515
* @param {Kind} parent
1616
* Parent node.
17-
* @returns {number | undefined}
17+
* @returns {number | undefined | void}
1818
* Position to move to next (optional).
1919
*/
2020

@@ -60,7 +60,7 @@ export function modifyChildren(modifier) {
6060
* @this {Kind}
6161
* @param {Node} node
6262
* @param {number} index
63-
* @returns {number | undefined}
63+
* @returns {number | undefined | void}
6464
*/
6565
function iteratee(node, index) {
6666
return modifier(node, index, this)

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"index.js"
3434
],
3535
"dependencies": {
36-
"@types/unist": "^2.0.0",
36+
"@types/unist": "^3.0.0",
3737
"array-iterate": "^2.0.0"
3838
},
3939
"devDependencies": {
@@ -81,7 +81,8 @@
8181
"**/*.ts"
8282
],
8383
"rules": {
84-
"@typescript-eslint/consistent-type-definitions": "off"
84+
"@typescript-eslint/consistent-type-definitions": "off",
85+
"import/no-extraneous-dependencies": "off"
8586
}
8687
}
8788
],

test.js

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('unist').Literal<number>} ExampleLiteral
3-
* @typedef {import('unist').Parent<ExampleLiteral>} ExampleParent
2+
* @typedef {import('mdast').Emphasis} Emphasis
3+
* @typedef {import('mdast').PhrasingContent} PhrasingContent
44
*/
55

66
import assert from 'node:assert/strict'
@@ -32,93 +32,98 @@ test('modifyChildren', async function (t) {
3232
})
3333

3434
await t.test('should call `fn` for each child in `parent`', function () {
35+
/** @type {Array<PhrasingContent>} */
3536
const children = [
36-
{type: 'x', value: 0},
37-
{type: 'x', value: 1},
38-
{type: 'x', value: 2},
39-
{type: 'x', value: 3}
37+
{type: 'text', value: '0'},
38+
{type: 'text', value: '1'},
39+
{type: 'text', value: '2'},
40+
{type: 'text', value: '3'}
4041
]
41-
/** @type {ExampleParent} */
42-
const context = {type: 'y', children}
42+
/** @type {Emphasis} */
43+
const context = {type: 'emphasis', children}
4344
let n = -1
4445

4546
modifyChildren(function (child, index, parent) {
4647
n++
4748
assert.strictEqual(child, children[n])
4849
assert.strictEqual(index, n)
4950
assert.strictEqual(parent, context)
50-
return undefined
5151
})(context)
5252
})
5353

5454
await t.test('should work when new children are added', function () {
55+
/** @type {Array<PhrasingContent>} */
5556
const children = [
56-
{type: 'x', value: 0},
57-
{type: 'x', value: 1},
58-
{type: 'x', value: 2},
59-
{type: 'x', value: 3},
60-
{type: 'x', value: 4},
61-
{type: 'x', value: 5},
62-
{type: 'x', value: 6}
57+
{type: 'text', value: '0'},
58+
{type: 'text', value: '1'},
59+
{type: 'text', value: '2'},
60+
{type: 'text', value: '3'},
61+
{type: 'text', value: '4'},
62+
{type: 'text', value: '5'},
63+
{type: 'text', value: '6'}
6364
]
64-
/** @type {ExampleParent} */
65+
/** @type {Emphasis} */
6566
const parent = {
66-
type: 'y',
67+
type: 'emphasis',
6768
children: [
68-
{type: 'x', value: 0},
69-
{type: 'x', value: 1},
70-
{type: 'x', value: 2},
71-
{type: 'x', value: 3}
69+
{type: 'text', value: '0'},
70+
{type: 'text', value: '1'},
71+
{type: 'text', value: '2'},
72+
{type: 'text', value: '3'}
7273
]
7374
}
7475
let n = -1
7576

7677
modifyChildren(
7778
/**
78-
* @param {ExampleLiteral} child
79-
* @param {ExampleParent} parent
79+
* @param {PhrasingContent} child
80+
* @param {Emphasis} parent
8081
*/
8182
function (child, index, parent) {
8283
n++
8384

8485
if (index < 3) {
85-
parent.children.push({type: 'x', value: parent.children.length})
86+
parent.children.push({
87+
type: 'text',
88+
value: String(parent.children.length)
89+
})
8690
}
8791

8892
assert.deepEqual(child, children[n])
8993
assert.deepEqual(index, n)
90-
return undefined
9194
}
9295
)(parent)
9396
})
9497

9598
await t.test('should skip forwards', function () {
99+
/** @type {Array<PhrasingContent>} */
96100
const children = [
97-
{type: 'x', value: 0},
98-
{type: 'x', value: 1},
99-
{type: 'x', value: 2},
100-
{type: 'x', value: 3}
101+
{type: 'text', value: '0'},
102+
{type: 'text', value: '1'},
103+
{type: 'text', value: '2'},
104+
{type: 'text', value: '3'}
101105
]
106+
/** @type {Emphasis} */
102107
const context = {
103-
type: 'y',
108+
type: 'emphasis',
104109
children: [
105-
{type: 'x', value: 0},
106-
{type: 'x', value: 1},
107-
{type: 'x', value: 3}
110+
{type: 'text', value: '0'},
111+
{type: 'text', value: '1'},
112+
{type: 'text', value: '3'}
108113
]
109114
}
110115
let n = -1
111116

112117
modifyChildren(
113118
/**
114-
* @param {ExampleLiteral} child
115-
* @param {ExampleParent} parent
119+
* @param {PhrasingContent} child
120+
* @param {Emphasis} parent
116121
*/
117122
function (child, index, parent) {
118123
assert.deepEqual(child, children[++n])
119124

120-
if (child.value === 1) {
121-
parent.children.splice(index + 1, 0, {type: 'x', value: 2})
125+
if ('value' in child && child.value === '1') {
126+
parent.children.splice(index + 1, 0, {type: 'text', value: '2'})
122127
return index + 1
123128
}
124129
}
@@ -129,48 +134,49 @@ test('modifyChildren', async function (t) {
129134

130135
await t.test('should skip backwards', function () {
131136
const calls = [
132-
{type: 'x', value: 0},
133-
{type: 'x', value: 1},
134-
{type: 'x', value: -1},
135-
{type: 'x', value: 0},
136-
{type: 'x', value: 1},
137-
{type: 'x', value: 2},
138-
{type: 'x', value: 3}
137+
{type: 'text', value: '0'},
138+
{type: 'text', value: '1'},
139+
{type: 'text', value: '-1'},
140+
{type: 'text', value: '0'},
141+
{type: 'text', value: '1'},
142+
{type: 'text', value: '2'},
143+
{type: 'text', value: '3'}
139144
]
145+
/** @type {Emphasis} */
140146
const context = {
141-
type: 'y',
147+
type: 'emphasis',
142148
children: [
143-
{type: 'x', value: 0},
144-
{type: 'x', value: 1},
145-
{type: 'x', value: 2},
146-
{type: 'x', value: 3}
149+
{type: 'text', value: '0'},
150+
{type: 'text', value: '1'},
151+
{type: 'text', value: '2'},
152+
{type: 'text', value: '3'}
147153
]
148154
}
149155
let n = -1
150156
let inserted = false
151157

152158
modifyChildren(
153159
/**
154-
* @param {ExampleLiteral} child
155-
* @param {ExampleParent} parent
160+
* @param {PhrasingContent} child
161+
* @param {Emphasis} parent
156162
*/
157163
function (child, _, parent) {
158164
assert.deepEqual(child, calls[++n])
159165

160-
if (!inserted && child.value === 1) {
166+
if (!inserted && 'value' in child && child.value === '1') {
161167
inserted = true
162-
parent.children.unshift({type: 'x', value: -1})
168+
parent.children.unshift({type: 'text', value: '-1'})
163169
return -1
164170
}
165171
}
166172
)(context)
167173

168174
assert.deepEqual(context.children, [
169-
{type: 'x', value: -1},
170-
{type: 'x', value: 0},
171-
{type: 'x', value: 1},
172-
{type: 'x', value: 2},
173-
{type: 'x', value: 3}
175+
{type: 'text', value: '-1'},
176+
{type: 'text', value: '0'},
177+
{type: 'text', value: '1'},
178+
{type: 'text', value: '2'},
179+
{type: 'text', value: '3'}
174180
])
175181
})
176182
})

0 commit comments

Comments
 (0)