From 1aa3494da4c98b0a1ce4d112c653d86aaa21a4ae Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 10 Aug 2023 16:47:22 +0200 Subject: [PATCH] Change to yield `undefined`, not `null` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You can still pass it, just that *we* don’t. --- index.d.ts | 6 +++--- lib/index.js | 26 +++++++++++++------------- test/data.js | 4 ++-- test/run.js | 20 ++++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4b0f61cc..20c00835 100644 --- a/index.d.ts +++ b/index.d.ts @@ -672,7 +672,7 @@ export type Transformer< * Nothing. */ export type TransformCallback = ( - error?: Error | null | undefined, + error?: Error | undefined, node?: Tree | undefined, file?: VFile | undefined ) => void @@ -834,7 +834,7 @@ export type CompilerFunction = ( * Nothing. */ export type RunCallback = ( - error?: Error | null | undefined, + error?: Error | undefined, node?: Tree | undefined, file?: VFile | undefined ) => void @@ -852,7 +852,7 @@ export type RunCallback = ( * Nothing. */ export type ProcessCallback = ( - error?: Error | null | undefined, + error?: Error | undefined, file?: File | undefined ) => void diff --git a/lib/index.js b/lib/index.js index 3516154c..670d6fe0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -98,7 +98,7 @@ function base() { } // Get `key`. - return (own.call(namespace, key) && namespace[key]) || null + return (own.call(namespace, key) && namespace[key]) || undefined } // Set space. @@ -314,10 +314,10 @@ function base() { return new Promise(executor) } - executor(null, callback) + executor(undefined, callback) /** - * @param {((node: Node) => void) | null} resolve + * @param {((node: Node) => void) | undefined} resolve * @param {(error: Error) => void} reject * @returns {void} */ @@ -326,7 +326,7 @@ function base() { transformers.run(node, vfile(doc), done) /** - * @param {Error | null} error + * @param {Error | undefined} error * @param {Node} tree * @param {VFile} file * @returns {void} @@ -339,7 +339,7 @@ function base() { resolve(tree) } else { // @ts-expect-error: `callback` is defined if `resolve` is not. - callback(null, tree, file) + callback(undefined, tree, file) } } } @@ -360,7 +360,7 @@ function base() { return result /** - * @param {Error | null} [error] + * @param {Error | undefined} [error] * @param {Node} [tree] * @returns {void} */ @@ -385,11 +385,11 @@ function base() { return new Promise(executor) } - executor(null, callback) + executor(undefined, callback) /** - * @param {((file: VFile) => void) | null} resolve - * @param {(error?: Error | null | undefined) => void} reject + * @param {((file: VFile) => void) | undefined} resolve + * @param {(error?: Error | undefined) => void} reject * @returns {void} */ function executor(resolve, reject) { @@ -402,7 +402,7 @@ function base() { /** @type {unknown} */ const result = processor.stringify(tree, file) - if (result === undefined || result === null) { + if (result === null || result === undefined) { // Empty. } else if (looksLikeAVFileValue(result)) { file.value = result @@ -415,7 +415,7 @@ function base() { }) /** - * @param {Error | null | undefined} [error] + * @param {Error | undefined} [error] * @param {VFile | undefined} [file] * @returns {void} */ @@ -426,7 +426,7 @@ function base() { resolve(file) } else { // @ts-expect-error: `callback` is defined if `resolve` is not. - callback(null, file) + callback(undefined, file) } } } @@ -450,7 +450,7 @@ function base() { return file /** - * @param {Error | null | undefined} [error] + * @param {Error | undefined} [error] * @returns {void} */ function done(error) { diff --git a/test/data.js b/test/data.js index e51a786c..671bdaab 100644 --- a/test/data.js +++ b/test/data.js @@ -10,7 +10,7 @@ test('`data`', async function (t) { }) await t.test('should yield data as getter (not defined)', async function () { - assert.equal(unified().data('foo'), null) + assert.equal(unified().data('foo'), undefined) }) await t.test('should yield data as getter (defined)', async function () { @@ -18,7 +18,7 @@ test('`data`', async function (t) { }) await t.test('should not yield data prototypal fields', async function () { - assert.equal(unified().data('toString'), null) + assert.equal(unified().data('toString'), undefined) }) await t.test('should yield dataset as getter w/o key', async function () { diff --git a/test/run.js b/test/run.js index c4caad54..9a8fb1c0 100644 --- a/test/run.js +++ b/test/run.js @@ -12,7 +12,7 @@ test('`run`', async function (t) { await t.test('should pass/yield expected values', async function () { await new Promise(function (resolve) { unified().run(givenNode, givenFile, function (error, tree, file) { - assert.equal(error, null) + assert.equal(error, undefined) assert.equal(tree, givenNode) assert.equal(file, givenFile) assert.equal(arguments.length, 3) @@ -24,7 +24,7 @@ test('`run`', async function (t) { await t.test('should pass a file if implicitly not given', async function () { await new Promise(function (resolve) { unified().run(givenNode, function (error, _, file) { - assert.equal(error, null) + assert.equal(error, undefined) assert.ok(file instanceof VFile) resolve(undefined) }) @@ -34,7 +34,7 @@ test('`run`', async function (t) { await t.test('should pass a file if explicitly not given', async function () { await new Promise(function (resolve) { unified().run(givenNode, undefined, function (error, _, file) { - assert.equal(error, null) + assert.equal(error, undefined) assert.ok(file instanceof VFile) resolve(undefined) }) @@ -70,7 +70,7 @@ test('`run`', async function (t) { } }) .run(givenNode, function (error, tree) { - assert.equal(error, null) + assert.equal(error, undefined) assert.equal(tree, otherNode) resolve(undefined) }) @@ -128,7 +128,7 @@ test('`run`', async function (t) { } }) .run(givenNode, function (error, tree) { - assert.equal(error, null) + assert.equal(error, undefined) assert.equal(tree, otherNode) resolve(undefined) }) @@ -150,7 +150,7 @@ test('`run`', async function (t) { } }) .run(givenNode, function (error, tree) { - assert.equal(error, null) + assert.equal(error, undefined) assert.equal(tree, otherNode) resolve(undefined) }) @@ -191,7 +191,7 @@ test('`run`', async function (t) { } }) .run(givenNode, function (error, tree) { - assert.equal(error, null) + assert.equal(error, undefined) assert.equal(tree, otherNode) resolve(undefined) }) @@ -212,7 +212,7 @@ test('`run`', async function (t) { } }) .run(givenNode, function (error) { - assert.equal(error, null) + assert.equal(error, undefined) resolve(undefined) }) }) @@ -239,7 +239,7 @@ test('`run`', async function (t) { } }) .run(givenNode, function (error) { - assert.equal(error, null) + assert.equal(error, undefined) resolve(undefined) }) }) @@ -277,7 +277,7 @@ test('`run`', async function (t) { } }) .run(givenNode, givenFile, function (error, tree, file) { - assert.equal(error, null) + assert.equal(error, undefined) assert.equal(tree, otherNode) assert.equal(file, givenFile) resolve(undefined)