From 4676814d49e483e446e86c882d583694c4177ff7 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 14 Aug 2023 13:11:12 +0200 Subject: [PATCH] Remove support for compilers returning nullish MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You’re supposed to compile to something. --- index.d.ts | 2 -- index.test-d.ts | 28 +++++++++------------------- lib/index.js | 6 ++---- test/process-compilers.js | 14 -------------- 4 files changed, 11 insertions(+), 39 deletions(-) diff --git a/index.d.ts b/index.d.ts index 713a6b3d..ffb08843 100644 --- a/index.d.ts +++ b/index.d.ts @@ -48,6 +48,4 @@ export interface CompileResultMap { // Note: if `Value` from `VFile` is changed, this should too. Uint8Array: Uint8Array string: string - // Empties. - null: null } diff --git a/index.test-d.ts b/index.test-d.ts index 442c3295..8a3f45f7 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -343,9 +343,7 @@ expectType>(processorWithRemarkParse) expectType(processorWithRemarkParse.parse('')) expectType(processorWithRemarkParse.runSync(mdastRoot)) expectType(processorWithRemarkParse.runSync(hastRoot)) -expectType( - processorWithRemarkParse.stringify(mdastRoot) -) +expectType(processorWithRemarkParse.stringify(mdastRoot)) processorWithRemarkParse.stringify(hastRoot) expectType(processorWithRemarkParse.processSync('')) @@ -361,12 +359,8 @@ expectType(processorWithRemarkLint.parse('')) expectType(processorWithRemarkLint.runSync(mdastRoot)) // @ts-expect-error: not the correct node type. processorWithRemarkLint.runSync(hastRoot) -expectType( - processorWithRemarkLint.stringify(mdastRoot) -) -expectType( - processorWithRemarkLint.stringify(hastRoot) -) +expectType(processorWithRemarkLint.stringify(mdastRoot)) +expectType(processorWithRemarkLint.stringify(hastRoot)) expectType(processorWithRemarkLint.processSync('')) // Inspect/transform plugin (implicit). @@ -386,10 +380,10 @@ expectType(processorWithRemarkLintImplicit.parse('')) expectType(processorWithRemarkLintImplicit.runSync(mdastRoot)) // @ts-expect-error: not the correct node type. processorWithRemarkLintImplicit.runSync(hastRoot) -expectType( +expectType( processorWithRemarkLintImplicit.stringify(mdastRoot) ) -expectType( +expectType( processorWithRemarkLintImplicit.stringify(hastRoot) ) expectType(processorWithRemarkLintImplicit.processSync('')) @@ -406,12 +400,8 @@ expectType(processorWithRemarkRehype.parse('')) expectType(processorWithRemarkRehype.runSync(mdastRoot)) // @ts-expect-error: not the correct node type. processorWithRemarkRehype.runSync(hastRoot) -expectType( - processorWithRemarkRehype.stringify(hastRoot) -) -expectType( - processorWithRemarkRehype.stringify(mdastRoot) -) +expectType(processorWithRemarkRehype.stringify(hastRoot)) +expectType(processorWithRemarkRehype.stringify(mdastRoot)) expectType(processorWithRemarkRehype.processSync('')) // Mutate plugin (implicit). @@ -431,10 +421,10 @@ expectType(processorWithRemarkRehypeImplicit.parse('')) expectType(processorWithRemarkRehypeImplicit.runSync(mdastRoot)) // @ts-expect-error: not the correct node type. processorWithRemarkRehypeImplicit.runSync(hastRoot) -expectType( +expectType( processorWithRemarkRehypeImplicit.stringify(hastRoot) ) -expectType( +expectType( processorWithRemarkRehypeImplicit.stringify(mdastRoot) ) expectType(processorWithRemarkRehypeImplicit.processSync('')) diff --git a/lib/index.js b/lib/index.js index 71c3cff6..0fcc16a5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -791,9 +791,7 @@ export class Processor extends CallableInstance { const compileResult = self.stringify(compileTree, file) - if (compileResult === null || compileResult === undefined) { - // Empty. - } else if (looksLikeAVFileValue(compileResult)) { + if (looksLikeAVFileValue(compileResult)) { file.value = compileResult } else { file.result = compileResult @@ -1020,7 +1018,7 @@ export class Processor extends CallableInstance { * @param {VFileCompatible | undefined} [file] * File associated with `node` (optional); any value accepted as `x` in * `new VFile(x)`. - * @returns {CompileResult extends undefined ? VFileValue | null : CompileResult} + * @returns {CompileResult extends undefined ? VFileValue : CompileResult} * Textual representation of the tree (see note). * * > 👉 **Note**: unified typically compiles by serializing: most compilers diff --git a/test/process-compilers.js b/test/process-compilers.js index 716fbbdf..4234ac3c 100644 --- a/test/process-compilers.js +++ b/test/process-compilers.js @@ -34,20 +34,6 @@ test('process (compilers)', async function (t) { assert.equal(file.result, undefined) }) - await t.test('should compile `null`', async function () { - const processor = unified() - - processor.Parser = simpleParser - processor.Compiler = function () { - return null - } - - const file = await processor.process('alpha') - - assert.equal(file.value, 'alpha') - assert.equal(file.result, undefined) - }) - await t.test('should compile non-text', async function () { const processor = unified() const result = {