Skip to content

Commit

Permalink
Change to yield undefined, not null
Browse files Browse the repository at this point in the history
You can still pass it, just that *we* don’t.
  • Loading branch information
wooorm committed Aug 10, 2023
1 parent fb49556 commit 1aa3494
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ export type Transformer<
* Nothing.
*/
export type TransformCallback<Tree extends Node = Node> = (
error?: Error | null | undefined,
error?: Error | undefined,
node?: Tree | undefined,
file?: VFile | undefined
) => void
Expand Down Expand Up @@ -834,7 +834,7 @@ export type CompilerFunction<Tree extends Node = Node, Result = unknown> = (
* Nothing.
*/
export type RunCallback<Tree extends Node = Node> = (
error?: Error | null | undefined,
error?: Error | undefined,
node?: Tree | undefined,
file?: VFile | undefined
) => void
Expand All @@ -852,7 +852,7 @@ export type RunCallback<Tree extends Node = Node> = (
* Nothing.
*/
export type ProcessCallback<File extends VFile = VFile> = (
error?: Error | null | undefined,
error?: Error | undefined,
file?: File | undefined
) => void

Expand Down
26 changes: 13 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
*/
Expand All @@ -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}
Expand All @@ -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)
}
}
}
Expand All @@ -360,7 +360,7 @@ function base() {
return result

/**
* @param {Error | null} [error]
* @param {Error | undefined} [error]
* @param {Node} [tree]
* @returns {void}
*/
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -415,7 +415,7 @@ function base() {
})

/**
* @param {Error | null | undefined} [error]
* @param {Error | undefined} [error]
* @param {VFile | undefined} [file]
* @returns {void}
*/
Expand All @@ -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)
}
}
}
Expand All @@ -450,7 +450,7 @@ function base() {
return file

/**
* @param {Error | null | undefined} [error]
* @param {Error | undefined} [error]
* @returns {void}
*/
function done(error) {
Expand Down
4 changes: 2 additions & 2 deletions test/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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 () {
assert.equal(unified().data('foo', 'bar').data('foo'), 'bar')
})

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 () {
Expand Down
20 changes: 10 additions & 10 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand All @@ -212,7 +212,7 @@ test('`run`', async function (t) {
}
})
.run(givenNode, function (error) {
assert.equal(error, null)
assert.equal(error, undefined)
resolve(undefined)
})
})
Expand All @@ -239,7 +239,7 @@ test('`run`', async function (t) {
}
})
.run(givenNode, function (error) {
assert.equal(error, null)
assert.equal(error, undefined)
resolve(undefined)
})
})
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1aa3494

Please sign in to comment.