8
8
* @typedef {import('../index.js').Parser } Parser
9
9
* @typedef {import('../index.js').Pluggable } Pluggable
10
10
* @typedef {import('../index.js').PluggableList } PluggableList
11
+ * @typedef {import('../index.js').PluginTuple } PluginTuple
11
12
* @typedef {import('../index.js').Plugin } Plugin
12
13
* @typedef {import('../index.js').Preset } Preset
13
14
* @typedef {import('../index.js').ProcessCallback } ProcessCallback
14
15
* @typedef {import('../index.js').Processor } Processor
15
16
* @typedef {import('../index.js').RunCallback } RunCallback
16
- * @typedef {import('../index.js').Transformer } Transformer
17
17
*/
18
18
19
19
import structuredClone from '@ungap/structured-clone'
@@ -52,7 +52,6 @@ function base() {
52
52
53
53
// Plugins.
54
54
processor . attachers = attachers
55
- // @ts -expect-error: overloads are handled.
56
55
processor . use = use
57
56
58
57
// API.
@@ -75,7 +74,8 @@ function base() {
75
74
let index = - 1
76
75
77
76
while ( ++ index < attachers . length ) {
78
- destination . use ( ...attachers [ index ] )
77
+ const attacher = attachers [ index ]
78
+ destination . use ( ...attacher )
79
79
}
80
80
81
81
destination . data ( structuredClone ( namespace ) )
@@ -129,7 +129,6 @@ function base() {
129
129
options [ 0 ] = undefined
130
130
}
131
131
132
- /** @type {Transformer | void } */
133
132
const transformer = attacher . call ( processor , ...options )
134
133
135
134
if ( typeof transformer === 'function' ) {
@@ -144,7 +143,7 @@ function base() {
144
143
}
145
144
146
145
/**
147
- * @param {Pluggable | null | undefined } [value]
146
+ * @param {Exclude< Pluggable, PluginTuple> | PluggableList | null | undefined } [value]
148
147
* @param {...unknown } options
149
148
* @returns {Processor }
150
149
*/
@@ -176,15 +175,16 @@ function base() {
176
175
return processor
177
176
178
177
/**
179
- * @param {import('../index.js').Pluggable<Array<unknown>> } value
180
- * @returns {void }
178
+ * @param {import('../index.js').Pluggable } value
179
+ * @returns {undefined }
181
180
*/
182
181
function add ( value ) {
183
182
if ( typeof value === 'function' ) {
184
183
addPlugin ( value )
185
184
} else if ( typeof value === 'object' ) {
186
185
if ( Array . isArray ( value ) ) {
187
- const [ plugin , ...options ] = value
186
+ const [ plugin , ...options ] =
187
+ /** @type {[Plugin, ...Array<unknown>] } */ ( value )
188
188
addPlugin ( plugin , ...options )
189
189
} else {
190
190
addPreset ( value )
@@ -196,7 +196,7 @@ function base() {
196
196
197
197
/**
198
198
* @param {Preset } result
199
- * @returns {void }
199
+ * @returns {undefined }
200
200
*/
201
201
function addPreset ( result ) {
202
202
if ( ! ( 'plugins' in result ) && ! ( 'settings' in result ) ) {
@@ -215,7 +215,7 @@ function base() {
215
215
216
216
/**
217
217
* @param {PluggableList | null | undefined } [plugins]
218
- * @returns {void }
218
+ * @returns {undefined }
219
219
*/
220
220
function addList ( plugins ) {
221
221
let index = - 1
@@ -235,7 +235,7 @@ function base() {
235
235
/**
236
236
* @param {Plugin } plugin
237
237
* @param {...unknown } [value]
238
- * @returns {void }
238
+ * @returns {undefined }
239
239
*/
240
240
function addPlugin ( plugin , value ) {
241
241
let index = - 1
@@ -299,7 +299,7 @@ function base() {
299
299
* @param {Node } node
300
300
* @param {RunCallback | VFileCompatible } [doc]
301
301
* @param {RunCallback } [callback]
302
- * @returns {Promise<Node> | void }
302
+ * @returns {Promise<Node> | undefined }
303
303
*/
304
304
function run ( node , doc , callback ) {
305
305
assertNode ( node )
@@ -316,10 +316,11 @@ function base() {
316
316
317
317
executor ( undefined , callback )
318
318
319
+ // Note: `void`s needed for TS.
319
320
/**
320
- * @param {((node: Node) => void) | undefined } resolve
321
- * @param {(error: Error) => void } reject
322
- * @returns {void }
321
+ * @param {((node: Node) => undefined | void) | undefined } resolve
322
+ * @param {(error: Error) => undefined | void } reject
323
+ * @returns {undefined }
323
324
*/
324
325
function executor ( resolve , reject ) {
325
326
// @ts -expect-error: `doc` can’t be a callback anymore, we checked.
@@ -329,7 +330,7 @@ function base() {
329
330
* @param {Error | undefined } error
330
331
* @param {Node } tree
331
332
* @param {VFile } file
332
- * @returns {void }
333
+ * @returns {undefined }
333
334
*/
334
335
function done ( error , tree , file ) {
335
336
tree = tree || node
@@ -362,7 +363,7 @@ function base() {
362
363
/**
363
364
* @param {Error | undefined } [error]
364
365
* @param {Node } [tree]
365
- * @returns {void }
366
+ * @returns {undefined }
366
367
*/
367
368
function done ( error , tree ) {
368
369
bail ( error )
@@ -387,10 +388,11 @@ function base() {
387
388
388
389
executor ( undefined , callback )
389
390
391
+ // Note: `void`s needed for TS.
390
392
/**
391
- * @param {((file: VFile) => void) | undefined } resolve
392
- * @param {(error?: Error | undefined) => void } reject
393
- * @returns {void }
393
+ * @param {((file: VFile) => undefined | void) | undefined } resolve
394
+ * @param {(error?: Error | undefined) => undefined | void } reject
395
+ * @returns {undefined }
394
396
*/
395
397
function executor ( resolve , reject ) {
396
398
const file = vfile ( doc )
@@ -417,7 +419,7 @@ function base() {
417
419
/**
418
420
* @param {Error | undefined } [error]
419
421
* @param {VFile | undefined } [file]
420
- * @returns {void }
422
+ * @returns {undefined }
421
423
*/
422
424
function done ( error , file ) {
423
425
if ( error || ! file ) {
@@ -432,7 +434,7 @@ function base() {
432
434
}
433
435
}
434
436
435
- /** @type {Processor['processSync'] } */
437
+ /** @type {import('../index.js'). Processor['processSync'] } */
436
438
function processSync ( doc ) {
437
439
/** @type {boolean | undefined } */
438
440
let complete
@@ -451,7 +453,7 @@ function base() {
451
453
452
454
/**
453
455
* @param {Error | undefined } [error]
454
- * @returns {void }
456
+ * @returns {undefined }
455
457
*/
456
458
function done ( error ) {
457
459
complete = true
0 commit comments