Skip to content

Commit 1aa3494

Browse files
committed
Change to yield undefined, not null
You can still pass it, just that *we* don’t.
1 parent fb49556 commit 1aa3494

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ export type Transformer<
672672
* Nothing.
673673
*/
674674
export type TransformCallback<Tree extends Node = Node> = (
675-
error?: Error | null | undefined,
675+
error?: Error | undefined,
676676
node?: Tree | undefined,
677677
file?: VFile | undefined
678678
) => void
@@ -834,7 +834,7 @@ export type CompilerFunction<Tree extends Node = Node, Result = unknown> = (
834834
* Nothing.
835835
*/
836836
export type RunCallback<Tree extends Node = Node> = (
837-
error?: Error | null | undefined,
837+
error?: Error | undefined,
838838
node?: Tree | undefined,
839839
file?: VFile | undefined
840840
) => void
@@ -852,7 +852,7 @@ export type RunCallback<Tree extends Node = Node> = (
852852
* Nothing.
853853
*/
854854
export type ProcessCallback<File extends VFile = VFile> = (
855-
error?: Error | null | undefined,
855+
error?: Error | undefined,
856856
file?: File | undefined
857857
) => void
858858

lib/index.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function base() {
9898
}
9999

100100
// Get `key`.
101-
return (own.call(namespace, key) && namespace[key]) || null
101+
return (own.call(namespace, key) && namespace[key]) || undefined
102102
}
103103

104104
// Set space.
@@ -314,10 +314,10 @@ function base() {
314314
return new Promise(executor)
315315
}
316316

317-
executor(null, callback)
317+
executor(undefined, callback)
318318

319319
/**
320-
* @param {((node: Node) => void) | null} resolve
320+
* @param {((node: Node) => void) | undefined} resolve
321321
* @param {(error: Error) => void} reject
322322
* @returns {void}
323323
*/
@@ -326,7 +326,7 @@ function base() {
326326
transformers.run(node, vfile(doc), done)
327327

328328
/**
329-
* @param {Error | null} error
329+
* @param {Error | undefined} error
330330
* @param {Node} tree
331331
* @param {VFile} file
332332
* @returns {void}
@@ -339,7 +339,7 @@ function base() {
339339
resolve(tree)
340340
} else {
341341
// @ts-expect-error: `callback` is defined if `resolve` is not.
342-
callback(null, tree, file)
342+
callback(undefined, tree, file)
343343
}
344344
}
345345
}
@@ -360,7 +360,7 @@ function base() {
360360
return result
361361

362362
/**
363-
* @param {Error | null} [error]
363+
* @param {Error | undefined} [error]
364364
* @param {Node} [tree]
365365
* @returns {void}
366366
*/
@@ -385,11 +385,11 @@ function base() {
385385
return new Promise(executor)
386386
}
387387

388-
executor(null, callback)
388+
executor(undefined, callback)
389389

390390
/**
391-
* @param {((file: VFile) => void) | null} resolve
392-
* @param {(error?: Error | null | undefined) => void} reject
391+
* @param {((file: VFile) => void) | undefined} resolve
392+
* @param {(error?: Error | undefined) => void} reject
393393
* @returns {void}
394394
*/
395395
function executor(resolve, reject) {
@@ -402,7 +402,7 @@ function base() {
402402
/** @type {unknown} */
403403
const result = processor.stringify(tree, file)
404404

405-
if (result === undefined || result === null) {
405+
if (result === null || result === undefined) {
406406
// Empty.
407407
} else if (looksLikeAVFileValue(result)) {
408408
file.value = result
@@ -415,7 +415,7 @@ function base() {
415415
})
416416

417417
/**
418-
* @param {Error | null | undefined} [error]
418+
* @param {Error | undefined} [error]
419419
* @param {VFile | undefined} [file]
420420
* @returns {void}
421421
*/
@@ -426,7 +426,7 @@ function base() {
426426
resolve(file)
427427
} else {
428428
// @ts-expect-error: `callback` is defined if `resolve` is not.
429-
callback(null, file)
429+
callback(undefined, file)
430430
}
431431
}
432432
}
@@ -450,7 +450,7 @@ function base() {
450450
return file
451451

452452
/**
453-
* @param {Error | null | undefined} [error]
453+
* @param {Error | undefined} [error]
454454
* @returns {void}
455455
*/
456456
function done(error) {

test/data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ test('`data`', async function (t) {
1010
})
1111

1212
await t.test('should yield data as getter (not defined)', async function () {
13-
assert.equal(unified().data('foo'), null)
13+
assert.equal(unified().data('foo'), undefined)
1414
})
1515

1616
await t.test('should yield data as getter (defined)', async function () {
1717
assert.equal(unified().data('foo', 'bar').data('foo'), 'bar')
1818
})
1919

2020
await t.test('should not yield data prototypal fields', async function () {
21-
assert.equal(unified().data('toString'), null)
21+
assert.equal(unified().data('toString'), undefined)
2222
})
2323

2424
await t.test('should yield dataset as getter w/o key', async function () {

test/run.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('`run`', async function (t) {
1212
await t.test('should pass/yield expected values', async function () {
1313
await new Promise(function (resolve) {
1414
unified().run(givenNode, givenFile, function (error, tree, file) {
15-
assert.equal(error, null)
15+
assert.equal(error, undefined)
1616
assert.equal(tree, givenNode)
1717
assert.equal(file, givenFile)
1818
assert.equal(arguments.length, 3)
@@ -24,7 +24,7 @@ test('`run`', async function (t) {
2424
await t.test('should pass a file if implicitly not given', async function () {
2525
await new Promise(function (resolve) {
2626
unified().run(givenNode, function (error, _, file) {
27-
assert.equal(error, null)
27+
assert.equal(error, undefined)
2828
assert.ok(file instanceof VFile)
2929
resolve(undefined)
3030
})
@@ -34,7 +34,7 @@ test('`run`', async function (t) {
3434
await t.test('should pass a file if explicitly not given', async function () {
3535
await new Promise(function (resolve) {
3636
unified().run(givenNode, undefined, function (error, _, file) {
37-
assert.equal(error, null)
37+
assert.equal(error, undefined)
3838
assert.ok(file instanceof VFile)
3939
resolve(undefined)
4040
})
@@ -70,7 +70,7 @@ test('`run`', async function (t) {
7070
}
7171
})
7272
.run(givenNode, function (error, tree) {
73-
assert.equal(error, null)
73+
assert.equal(error, undefined)
7474
assert.equal(tree, otherNode)
7575
resolve(undefined)
7676
})
@@ -128,7 +128,7 @@ test('`run`', async function (t) {
128128
}
129129
})
130130
.run(givenNode, function (error, tree) {
131-
assert.equal(error, null)
131+
assert.equal(error, undefined)
132132
assert.equal(tree, otherNode)
133133
resolve(undefined)
134134
})
@@ -150,7 +150,7 @@ test('`run`', async function (t) {
150150
}
151151
})
152152
.run(givenNode, function (error, tree) {
153-
assert.equal(error, null)
153+
assert.equal(error, undefined)
154154
assert.equal(tree, otherNode)
155155
resolve(undefined)
156156
})
@@ -191,7 +191,7 @@ test('`run`', async function (t) {
191191
}
192192
})
193193
.run(givenNode, function (error, tree) {
194-
assert.equal(error, null)
194+
assert.equal(error, undefined)
195195
assert.equal(tree, otherNode)
196196
resolve(undefined)
197197
})
@@ -212,7 +212,7 @@ test('`run`', async function (t) {
212212
}
213213
})
214214
.run(givenNode, function (error) {
215-
assert.equal(error, null)
215+
assert.equal(error, undefined)
216216
resolve(undefined)
217217
})
218218
})
@@ -239,7 +239,7 @@ test('`run`', async function (t) {
239239
}
240240
})
241241
.run(givenNode, function (error) {
242-
assert.equal(error, null)
242+
assert.equal(error, undefined)
243243
resolve(undefined)
244244
})
245245
})
@@ -277,7 +277,7 @@ test('`run`', async function (t) {
277277
}
278278
})
279279
.run(givenNode, givenFile, function (error, tree, file) {
280-
assert.equal(error, null)
280+
assert.equal(error, undefined)
281281
assert.equal(tree, otherNode)
282282
assert.equal(file, givenFile)
283283
resolve(undefined)

0 commit comments

Comments
 (0)