Skip to content

Commit

Permalink
Remove support for compilers returning nullish
Browse files Browse the repository at this point in the history
You’re supposed to compile to something.
  • Loading branch information
wooorm committed Aug 14, 2023
1 parent 56ee288 commit 4676814
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 39 deletions.
2 changes: 0 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ export interface CompileResultMap {
// Note: if `Value` from `VFile` is changed, this should too.
Uint8Array: Uint8Array
string: string
// Empties.
null: null
}
28 changes: 9 additions & 19 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ expectType<Processor<MdastRoot>>(processorWithRemarkParse)
expectType<MdastRoot>(processorWithRemarkParse.parse(''))
expectType<UnistNode>(processorWithRemarkParse.runSync(mdastRoot))
expectType<UnistNode>(processorWithRemarkParse.runSync(hastRoot))
expectType<Uint8Array | string | null>(
processorWithRemarkParse.stringify(mdastRoot)
)
expectType<Uint8Array | string>(processorWithRemarkParse.stringify(mdastRoot))
processorWithRemarkParse.stringify(hastRoot)
expectType<VFile>(processorWithRemarkParse.processSync(''))

Expand All @@ -361,12 +359,8 @@ expectType<UnistNode>(processorWithRemarkLint.parse(''))
expectType<MdastRoot>(processorWithRemarkLint.runSync(mdastRoot))
// @ts-expect-error: not the correct node type.
processorWithRemarkLint.runSync(hastRoot)
expectType<Uint8Array | string | null>(
processorWithRemarkLint.stringify(mdastRoot)
)
expectType<Uint8Array | string | null>(
processorWithRemarkLint.stringify(hastRoot)
)
expectType<Uint8Array | string>(processorWithRemarkLint.stringify(mdastRoot))
expectType<Uint8Array | string>(processorWithRemarkLint.stringify(hastRoot))
expectType<VFile>(processorWithRemarkLint.processSync(''))

// Inspect/transform plugin (implicit).
Expand All @@ -386,10 +380,10 @@ expectType<UnistNode>(processorWithRemarkLintImplicit.parse(''))
expectType<MdastRoot>(processorWithRemarkLintImplicit.runSync(mdastRoot))
// @ts-expect-error: not the correct node type.
processorWithRemarkLintImplicit.runSync(hastRoot)
expectType<Uint8Array | string | null>(
expectType<Uint8Array | string>(
processorWithRemarkLintImplicit.stringify(mdastRoot)
)
expectType<Uint8Array | string | null>(
expectType<Uint8Array | string>(
processorWithRemarkLintImplicit.stringify(hastRoot)
)
expectType<VFile>(processorWithRemarkLintImplicit.processSync(''))
Expand All @@ -406,12 +400,8 @@ expectType<UnistNode>(processorWithRemarkRehype.parse(''))
expectType<HastRoot>(processorWithRemarkRehype.runSync(mdastRoot))
// @ts-expect-error: not the correct node type.
processorWithRemarkRehype.runSync(hastRoot)
expectType<Uint8Array | string | null>(
processorWithRemarkRehype.stringify(hastRoot)
)
expectType<Uint8Array | string | null>(
processorWithRemarkRehype.stringify(mdastRoot)
)
expectType<Uint8Array | string>(processorWithRemarkRehype.stringify(hastRoot))
expectType<Uint8Array | string>(processorWithRemarkRehype.stringify(mdastRoot))
expectType<VFile>(processorWithRemarkRehype.processSync(''))

// Mutate plugin (implicit).
Expand All @@ -431,10 +421,10 @@ expectType<UnistNode>(processorWithRemarkRehypeImplicit.parse(''))
expectType<HastRoot>(processorWithRemarkRehypeImplicit.runSync(mdastRoot))
// @ts-expect-error: not the correct node type.
processorWithRemarkRehypeImplicit.runSync(hastRoot)
expectType<Uint8Array | string | null>(
expectType<Uint8Array | string>(
processorWithRemarkRehypeImplicit.stringify(hastRoot)
)
expectType<Uint8Array | string | null>(
expectType<Uint8Array | string>(
processorWithRemarkRehypeImplicit.stringify(mdastRoot)
)
expectType<VFile>(processorWithRemarkRehypeImplicit.processSync(''))
Expand Down
6 changes: 2 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions test/process-compilers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 4676814

Please sign in to comment.