@@ -67,37 +67,67 @@ export {_void, wrap}
67
67
// Construct.
68
68
const mdast = zwitch ( 'type' , {
69
69
// Core interface.
70
+ // @ts -expect-error: fine.
70
71
unknown,
72
+ // @ts -expect-error: fine.
71
73
invalid : unknown ,
72
74
// Per-type handling.
73
75
handlers : {
76
+ // @ts -expect-error: fine.
74
77
root : wrap ( root ) ,
78
+ // @ts -expect-error: fine.
75
79
paragraph : parent ,
80
+ // @ts -expect-error: fine.
76
81
blockquote : parent ,
82
+ // @ts -expect-error: fine.
77
83
tableRow : parent ,
84
+ // @ts -expect-error: fine.
78
85
tableCell : parent ,
86
+ // @ts -expect-error: fine.
79
87
strong : parent ,
88
+ // @ts -expect-error: fine.
80
89
emphasis : parent ,
90
+ // @ts -expect-error: fine.
81
91
delete : parent ,
92
+ // @ts -expect-error: fine.
82
93
listItem : wrap ( listItem ) ,
94
+ // @ts -expect-error: fine.
83
95
footnote : parent ,
96
+ // @ts -expect-error: fine.
84
97
heading : wrap ( heading ) ,
98
+ // @ts -expect-error: fine.
85
99
text : literal ,
100
+ // @ts -expect-error: fine.
86
101
inlineCode : literal ,
102
+ // @ts -expect-error: fine.
87
103
yaml : literal ,
104
+ // @ts -expect-error: fine.
88
105
toml : literal ,
106
+ // @ts -expect-error: fine.
89
107
code : wrap ( code ) ,
108
+ // @ts -expect-error: fine.
90
109
thematicBreak : _void ,
110
+ // @ts -expect-error: fine.
91
111
break : _void ,
112
+ // @ts -expect-error: fine.
92
113
list : wrap ( list ) ,
114
+ // @ts -expect-error: fine.
93
115
footnoteDefinition : wrap ( footnoteDefinition ) ,
116
+ // @ts -expect-error: fine.
94
117
definition : wrap ( definition ) ,
118
+ // @ts -expect-error: fine.
95
119
link : wrap ( link ) ,
120
+ // @ts -expect-error: fine.
96
121
image : wrap ( image ) ,
122
+ // @ts -expect-error: fine.
97
123
linkReference : wrap ( linkReference ) ,
124
+ // @ts -expect-error: fine.
98
125
imageReference : wrap ( imageReference ) ,
126
+ // @ts -expect-error: fine.
99
127
footnoteReference : wrap ( footnoteReference ) ,
128
+ // @ts -expect-error: fine.
100
129
table : wrap ( table ) ,
130
+ // @ts -expect-error: fine.
101
131
html : literal
102
132
}
103
133
} )
@@ -128,9 +158,8 @@ function assertParent(node) {
128
158
*/
129
159
function assertLiteral ( node ) {
130
160
unistLiteral ( node )
131
- nodeAssert . strictEqual (
132
- typeof node . value ,
133
- 'string' ,
161
+ nodeAssert (
162
+ typeof node . value === 'string' ,
134
163
'literal should have a string `value`'
135
164
)
136
165
}
@@ -143,7 +172,7 @@ function assertLiteral(node) {
143
172
function root ( node , ancestor ) {
144
173
parent ( node )
145
174
146
- nodeAssert . strictEqual ( ancestor , undefined , '`root` should not have a parent' )
175
+ nodeAssert ( ancestor === undefined , '`root` should not have a parent' )
147
176
}
148
177
149
178
/**
@@ -155,30 +184,21 @@ function list(node) {
155
184
indexable ( node )
156
185
157
186
if ( node . spread != null ) {
158
- nodeAssert . strictEqual (
159
- typeof node . spread ,
160
- 'boolean' ,
161
- '`spread` must be `boolean`'
162
- )
187
+ nodeAssert ( typeof node . spread === 'boolean' , '`spread` must be `boolean`' )
163
188
}
164
189
165
190
if ( node . ordered != null ) {
166
- nodeAssert . strictEqual (
167
- typeof node . ordered ,
168
- 'boolean' ,
169
- '`ordered` must be `boolean`'
170
- )
191
+ nodeAssert ( typeof node . ordered === 'boolean' , '`ordered` must be `boolean`' )
171
192
}
172
193
173
194
if ( ! node . ordered ) {
174
- nodeAssert . ok ( node . start == null , 'unordered lists must not have `start`' )
195
+ nodeAssert ( node . start == null , 'unordered lists must not have `start`' )
175
196
} else if ( node . start != null ) {
176
- nodeAssert . strictEqual (
177
- typeof node . start ,
178
- 'number' ,
197
+ nodeAssert (
198
+ typeof node . start === 'number' ,
179
199
'ordered lists must have `start`'
180
200
)
181
- nodeAssert . ok ( node . start >= 0 , '`start` must be gte `0`' )
201
+ nodeAssert ( node . start >= 0 , '`start` must be gte `0`' )
182
202
}
183
203
}
184
204
@@ -191,19 +211,11 @@ function listItem(node) {
191
211
indexable ( node )
192
212
193
213
if ( node . spread != null ) {
194
- nodeAssert . strictEqual (
195
- typeof node . spread ,
196
- 'boolean' ,
197
- '`spread` must be `boolean`'
198
- )
214
+ nodeAssert ( typeof node . spread === 'boolean' , '`spread` must be `boolean`' )
199
215
}
200
216
201
217
if ( node . checked != null ) {
202
- nodeAssert . strictEqual (
203
- typeof node . checked ,
204
- 'boolean' ,
205
- '`checked` must be `boolean`'
206
- )
218
+ nodeAssert ( typeof node . checked === 'boolean' , '`checked` must be `boolean`' )
207
219
}
208
220
}
209
221
@@ -215,8 +227,9 @@ function heading(node) {
215
227
parent ( node )
216
228
indexable ( node )
217
229
218
- nodeAssert . ok ( node . depth > 0 , '`depth` should be gte `1`' )
219
- nodeAssert . ok ( node . depth <= 6 , '`depth` should be lte `6`' )
230
+ nodeAssert ( typeof node . depth === 'number' , '`depth` should be a number' )
231
+ nodeAssert ( node . depth > 0 , '`depth` should be gte `1`' )
232
+ nodeAssert ( node . depth <= 6 , '`depth` should be lte `6`' )
220
233
}
221
234
222
235
/**
@@ -228,20 +241,12 @@ function code(node) {
228
241
indexable ( node )
229
242
230
243
if ( node . lang != null ) {
231
- nodeAssert . strictEqual (
232
- typeof node . lang ,
233
- 'string' ,
234
- '`lang` must be `string`'
235
- )
244
+ nodeAssert ( typeof node . lang === 'string' , '`lang` must be `string`' )
236
245
}
237
246
238
247
if ( node . meta != null ) {
239
- nodeAssert . ok ( node . lang != null , 'code with `meta` must also have `lang`' )
240
- nodeAssert . strictEqual (
241
- typeof node . meta ,
242
- 'string' ,
243
- '`meta` must be `string`'
244
- )
248
+ nodeAssert ( node . lang != null , 'code with `meta` must also have `lang`' )
249
+ nodeAssert ( typeof node . meta === 'string' , '`meta` must be `string`' )
245
250
}
246
251
}
247
252
@@ -253,18 +258,13 @@ function footnoteDefinition(node) {
253
258
parent ( node )
254
259
indexable ( node )
255
260
256
- nodeAssert . strictEqual (
257
- typeof node . identifier ,
258
- 'string' ,
261
+ nodeAssert (
262
+ typeof node . identifier === 'string' ,
259
263
'`footnoteDefinition` must have `identifier`'
260
264
)
261
265
262
266
if ( node . label != null ) {
263
- nodeAssert . strictEqual (
264
- typeof node . label ,
265
- 'string' ,
266
- '`label` must be `string`'
267
- )
267
+ nodeAssert ( typeof node . label === 'string' , '`label` must be `string`' )
268
268
}
269
269
}
270
270
@@ -276,28 +276,19 @@ function definition(node) {
276
276
_void ( node )
277
277
indexable ( node )
278
278
279
- nodeAssert . strictEqual (
280
- typeof node . identifier ,
281
- 'string' ,
279
+ nodeAssert (
280
+ typeof node . identifier === 'string' ,
282
281
'`identifier` must be `string`'
283
282
)
284
283
285
284
if ( node . label != null ) {
286
- nodeAssert . strictEqual (
287
- typeof node . label ,
288
- 'string' ,
289
- '`label` must be `string`'
290
- )
285
+ nodeAssert ( typeof node . label === 'string' , '`label` must be `string`' )
291
286
}
292
287
293
- nodeAssert . strictEqual ( typeof node . url , 'string' , '`url` must be `string`' )
288
+ nodeAssert ( typeof node . url === 'string' , '`url` must be `string`' )
294
289
295
290
if ( node . title != null ) {
296
- nodeAssert . strictEqual (
297
- typeof node . title ,
298
- 'string' ,
299
- '`title` must be `string`'
300
- )
291
+ nodeAssert ( typeof node . title === 'string' , '`title` must be `string`' )
301
292
}
302
293
}
303
294
@@ -309,14 +300,10 @@ function link(node) {
309
300
parent ( node )
310
301
indexable ( node )
311
302
312
- nodeAssert . strictEqual ( typeof node . url , 'string' , '`url` must be `string`' )
303
+ nodeAssert ( typeof node . url === 'string' , '`url` must be `string`' )
313
304
314
305
if ( node . title != null ) {
315
- nodeAssert . strictEqual (
316
- typeof node . title ,
317
- 'string' ,
318
- '`title` must be `string`'
319
- )
306
+ nodeAssert ( typeof node . title === 'string' , '`title` must be `string`' )
320
307
}
321
308
}
322
309
@@ -328,18 +315,14 @@ function image(node) {
328
315
_void ( node )
329
316
indexable ( node )
330
317
331
- nodeAssert . strictEqual ( typeof node . url , 'string' , '`url` must be `string`' )
318
+ nodeAssert ( typeof node . url === 'string' , '`url` must be `string`' )
332
319
333
320
if ( node . title != null ) {
334
- nodeAssert . strictEqual (
335
- typeof node . title ,
336
- 'string' ,
337
- '`title` must be `string`'
338
- )
321
+ nodeAssert ( typeof node . title === 'string' , '`title` must be `string`' )
339
322
}
340
323
341
324
if ( node . alt != null ) {
342
- nodeAssert . strictEqual ( typeof node . alt , 'string' , '`alt` must be `string`' )
325
+ nodeAssert ( typeof node . alt === 'string' , '`alt` must be `string`' )
343
326
}
344
327
}
345
328
@@ -351,25 +334,19 @@ function linkReference(node) {
351
334
parent ( node )
352
335
indexable ( node )
353
336
354
- nodeAssert . strictEqual (
355
- typeof node . identifier ,
356
- 'string' ,
337
+ nodeAssert (
338
+ typeof node . identifier === 'string' ,
357
339
'`identifier` must be `string`'
358
340
)
359
341
360
342
if ( node . label != null ) {
361
- nodeAssert . strictEqual (
362
- typeof node . label ,
363
- 'string' ,
364
- '`label` must be `string`'
365
- )
343
+ nodeAssert ( typeof node . label === 'string' , '`label` must be `string`' )
366
344
}
367
345
368
346
if ( node . referenceType != null ) {
369
- nodeAssert . notStrictEqual (
347
+ nodeAssert (
370
348
// @ts -expect-error Check if it’s a string.
371
- [ 'shortcut' , 'collapsed' , 'full' ] . indexOf ( node . referenceType ) ,
372
- - 1 ,
349
+ [ 'shortcut' , 'collapsed' , 'full' ] . includes ( node . referenceType ) ,
373
350
'`referenceType` must be `shortcut`, `collapsed`, or `full`'
374
351
)
375
352
}
@@ -383,29 +360,23 @@ function imageReference(node) {
383
360
_void ( node )
384
361
indexable ( node )
385
362
386
- nodeAssert . strictEqual (
387
- typeof node . identifier ,
388
- 'string' ,
363
+ nodeAssert (
364
+ typeof node . identifier === 'string' ,
389
365
'`identifier` must be `string`'
390
366
)
391
367
392
368
if ( node . label != null ) {
393
- nodeAssert . strictEqual (
394
- typeof node . label ,
395
- 'string' ,
396
- '`label` must be `string`'
397
- )
369
+ nodeAssert ( typeof node . label === 'string' , '`label` must be `string`' )
398
370
}
399
371
400
372
if ( node . alt != null ) {
401
- nodeAssert . strictEqual ( typeof node . alt , 'string' , '`alt` must be `string`' )
373
+ nodeAssert ( typeof node . alt === 'string' , '`alt` must be `string`' )
402
374
}
403
375
404
376
if ( node . referenceType != null ) {
405
- nodeAssert . notStrictEqual (
377
+ nodeAssert (
406
378
// @ts -expect-error Check if it’s a string.
407
- [ 'shortcut' , 'collapsed' , 'full' ] . indexOf ( node . referenceType ) ,
408
- - 1 ,
379
+ [ 'shortcut' , 'collapsed' , 'full' ] . includes ( node . referenceType ) ,
409
380
'`referenceType` must be `shortcut`, `collapsed`, or `full`'
410
381
)
411
382
}
@@ -419,18 +390,13 @@ function footnoteReference(node) {
419
390
_void ( node )
420
391
indexable ( node )
421
392
422
- nodeAssert . strictEqual (
423
- typeof node . identifier ,
424
- 'string' ,
393
+ nodeAssert (
394
+ typeof node . identifier === 'string' ,
425
395
'`identifier` must be `string`'
426
396
)
427
397
428
398
if ( node . label != null ) {
429
- nodeAssert . strictEqual (
430
- typeof node . label ,
431
- 'string' ,
432
- '`label` must be `string`'
433
- )
399
+ nodeAssert ( typeof node . label === 'string' , '`label` must be `string`' )
434
400
}
435
401
}
436
402
@@ -445,18 +411,17 @@ function table(node) {
445
411
indexable ( node )
446
412
447
413
if ( node . align != null ) {
448
- nodeAssert . ok ( Array . isArray ( node . align ) , '`align` must be `array`' )
414
+ nodeAssert ( Array . isArray ( node . align ) , '`align` must be `array`' )
449
415
/** @type {Array.<unknown> } */
450
416
const align = node . align // type-coverage:ignore-line
451
417
452
418
while ( ++ index < align . length ) {
453
419
const value = align [ index ]
454
420
455
421
if ( value != null ) {
456
- nodeAssert . notStrictEqual (
422
+ nodeAssert (
457
423
// @ts -expect-error Check if it’s a string.
458
- [ 'left' , 'right' , 'center' ] . indexOf ( value ) ,
459
- - 1 ,
424
+ [ 'left' , 'right' , 'center' ] . includes ( value ) ,
460
425
"each align in table must be `null, 'left', 'right', 'center'`"
461
426
)
462
427
}
0 commit comments