1
1
/**
2
+ * @typedef {import('unified').Settings } Settings
2
3
* @typedef {import('hast').Root } Root
3
4
*/
4
5
@@ -78,7 +79,6 @@ test('rehype', async function (t) {
78
79
async function ( ) {
79
80
assert . deepEqual (
80
81
unified ( )
81
- // @ts -expect-error: to do: type `settings`.
82
82
. data ( 'settings' , { fragment : true } )
83
83
. use ( rehypeParse , { fragment : false } )
84
84
. use ( rehypeStringify )
@@ -94,7 +94,6 @@ test('rehype', async function (t) {
94
94
async function ( ) {
95
95
assert . deepEqual (
96
96
unified ( )
97
- // @ts -expect-error: to do: type `settings`.
98
97
. data ( 'settings' , { quote : '"' } )
99
98
. use ( rehypeParse , { fragment : true } )
100
99
. use ( rehypeStringify , { quote : "'" } )
@@ -187,8 +186,10 @@ test('rehype', async function (t) {
187
186
'should throw when `tree` is not a valid node' ,
188
187
async function ( ) {
189
188
assert . throws ( function ( ) {
190
- // @ts -expect-error: unknown node.
191
- unified ( ) . use ( rehypeStringify ) . stringify ( { type : 'unicorn' } )
189
+ unified ( )
190
+ . use ( rehypeStringify )
191
+ // @ts -expect-error: check how an unknown node is handled.
192
+ . stringify ( { type : 'unicorn' } )
192
193
} , / u n i c o r n / )
193
194
}
194
195
)
@@ -308,7 +309,6 @@ test('rehype', async function (t) {
308
309
async function ( ) {
309
310
assert . deepEqual (
310
311
rehype ( )
311
- // @ts -expect-error: to do: type `settings`.
312
312
. data ( 'settings' , { emitParseErrors : true } )
313
313
. processSync ( '<!doctypehtml>' )
314
314
. messages . map ( String ) ,
@@ -323,7 +323,6 @@ test('rehype', async function (t) {
323
323
assert . deepEqual (
324
324
rehype ( )
325
325
. data ( 'settings' , {
326
- // @ts -expect-error: to do: type `settings`.
327
326
emitParseErrors : true ,
328
327
missingWhitespaceBeforeDoctypeName : false
329
328
} )
@@ -340,7 +339,6 @@ test('rehype', async function (t) {
340
339
assert . deepEqual (
341
340
rehype ( )
342
341
. data ( 'settings' , {
343
- // @ts -expect-error: to do: type `settings`.
344
342
emitParseErrors : true ,
345
343
missingWhitespaceBeforeDoctypeName : true
346
344
} )
@@ -357,7 +355,6 @@ test('rehype', async function (t) {
357
355
assert . deepEqual (
358
356
rehype ( )
359
357
. data ( 'settings' , {
360
- // @ts -expect-error: to do: type `settings`.
361
358
emitParseErrors : true ,
362
359
missingWhitespaceBeforeDoctypeName : 2
363
360
} )
@@ -373,7 +370,6 @@ test('rehype', async function (t) {
373
370
assert . deepEqual (
374
371
rehype ( )
375
372
. data ( 'settings' , {
376
- // @ts -expect-error: to do: type `settings`.
377
373
emitParseErrors : true ,
378
374
missingWhitespaceBeforeDoctypeName : 1
379
375
} )
@@ -403,15 +399,15 @@ test('fixtures', async function (t) {
403
399
const expectedTreeUrl = new URL ( 'index.json' , base )
404
400
const expectedOutputUrl = new URL ( 'result.html' , base )
405
401
406
- // To do: types of `Settings`.
407
- /** @type {{fragment?: boolean, reprocess?: boolean} } */
408
- let settings = { }
402
+ /** @type {Settings & {reprocess?: boolean | null | undefined} } */
403
+ let config = { }
409
404
410
405
try {
411
- settings = JSON . parse ( String ( await fs . readFile ( configUrl ) ) )
406
+ config = JSON . parse ( String ( await fs . readFile ( configUrl ) ) )
412
407
} catch { }
413
408
414
- // @ts -expect-error: To do: types of `Settings`.
409
+ const { reprocess, ...settings } = config
410
+
415
411
const processor = rehype ( ) . data ( 'settings' , settings )
416
412
const input = new VFile ( {
417
413
basename : 'index.html' ,
@@ -449,9 +445,8 @@ test('fixtures', async function (t) {
449
445
assert . deepEqual ( actualTree , expectedTree )
450
446
assert . equal ( actualOutput , expectedOutput )
451
447
452
- if ( settings . reprocess !== false ) {
448
+ if ( reprocess !== false ) {
453
449
const reprocessedTree = rehype ( )
454
- // @ts -expect-error: to do: type `settings`.
455
450
. data ( 'settings' , settings )
456
451
. parse ( actualOutput )
457
452
removePosition ( actualTree )
0 commit comments