Skip to content

Commit 4676814

Browse files
committed
Remove support for compilers returning nullish
You’re supposed to compile to something.
1 parent 56ee288 commit 4676814

File tree

4 files changed

+11
-39
lines changed

4 files changed

+11
-39
lines changed

index.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,4 @@ export interface CompileResultMap {
4848
// Note: if `Value` from `VFile` is changed, this should too.
4949
Uint8Array: Uint8Array
5050
string: string
51-
// Empties.
52-
null: null
5351
}

index.test-d.ts

+9-19
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ expectType<Processor<MdastRoot>>(processorWithRemarkParse)
343343
expectType<MdastRoot>(processorWithRemarkParse.parse(''))
344344
expectType<UnistNode>(processorWithRemarkParse.runSync(mdastRoot))
345345
expectType<UnistNode>(processorWithRemarkParse.runSync(hastRoot))
346-
expectType<Uint8Array | string | null>(
347-
processorWithRemarkParse.stringify(mdastRoot)
348-
)
346+
expectType<Uint8Array | string>(processorWithRemarkParse.stringify(mdastRoot))
349347
processorWithRemarkParse.stringify(hastRoot)
350348
expectType<VFile>(processorWithRemarkParse.processSync(''))
351349

@@ -361,12 +359,8 @@ expectType<UnistNode>(processorWithRemarkLint.parse(''))
361359
expectType<MdastRoot>(processorWithRemarkLint.runSync(mdastRoot))
362360
// @ts-expect-error: not the correct node type.
363361
processorWithRemarkLint.runSync(hastRoot)
364-
expectType<Uint8Array | string | null>(
365-
processorWithRemarkLint.stringify(mdastRoot)
366-
)
367-
expectType<Uint8Array | string | null>(
368-
processorWithRemarkLint.stringify(hastRoot)
369-
)
362+
expectType<Uint8Array | string>(processorWithRemarkLint.stringify(mdastRoot))
363+
expectType<Uint8Array | string>(processorWithRemarkLint.stringify(hastRoot))
370364
expectType<VFile>(processorWithRemarkLint.processSync(''))
371365

372366
// Inspect/transform plugin (implicit).
@@ -386,10 +380,10 @@ expectType<UnistNode>(processorWithRemarkLintImplicit.parse(''))
386380
expectType<MdastRoot>(processorWithRemarkLintImplicit.runSync(mdastRoot))
387381
// @ts-expect-error: not the correct node type.
388382
processorWithRemarkLintImplicit.runSync(hastRoot)
389-
expectType<Uint8Array | string | null>(
383+
expectType<Uint8Array | string>(
390384
processorWithRemarkLintImplicit.stringify(mdastRoot)
391385
)
392-
expectType<Uint8Array | string | null>(
386+
expectType<Uint8Array | string>(
393387
processorWithRemarkLintImplicit.stringify(hastRoot)
394388
)
395389
expectType<VFile>(processorWithRemarkLintImplicit.processSync(''))
@@ -406,12 +400,8 @@ expectType<UnistNode>(processorWithRemarkRehype.parse(''))
406400
expectType<HastRoot>(processorWithRemarkRehype.runSync(mdastRoot))
407401
// @ts-expect-error: not the correct node type.
408402
processorWithRemarkRehype.runSync(hastRoot)
409-
expectType<Uint8Array | string | null>(
410-
processorWithRemarkRehype.stringify(hastRoot)
411-
)
412-
expectType<Uint8Array | string | null>(
413-
processorWithRemarkRehype.stringify(mdastRoot)
414-
)
403+
expectType<Uint8Array | string>(processorWithRemarkRehype.stringify(hastRoot))
404+
expectType<Uint8Array | string>(processorWithRemarkRehype.stringify(mdastRoot))
415405
expectType<VFile>(processorWithRemarkRehype.processSync(''))
416406

417407
// Mutate plugin (implicit).
@@ -431,10 +421,10 @@ expectType<UnistNode>(processorWithRemarkRehypeImplicit.parse(''))
431421
expectType<HastRoot>(processorWithRemarkRehypeImplicit.runSync(mdastRoot))
432422
// @ts-expect-error: not the correct node type.
433423
processorWithRemarkRehypeImplicit.runSync(hastRoot)
434-
expectType<Uint8Array | string | null>(
424+
expectType<Uint8Array | string>(
435425
processorWithRemarkRehypeImplicit.stringify(hastRoot)
436426
)
437-
expectType<Uint8Array | string | null>(
427+
expectType<Uint8Array | string>(
438428
processorWithRemarkRehypeImplicit.stringify(mdastRoot)
439429
)
440430
expectType<VFile>(processorWithRemarkRehypeImplicit.processSync(''))

lib/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,7 @@ export class Processor extends CallableInstance {
791791

792792
const compileResult = self.stringify(compileTree, file)
793793

794-
if (compileResult === null || compileResult === undefined) {
795-
// Empty.
796-
} else if (looksLikeAVFileValue(compileResult)) {
794+
if (looksLikeAVFileValue(compileResult)) {
797795
file.value = compileResult
798796
} else {
799797
file.result = compileResult
@@ -1020,7 +1018,7 @@ export class Processor extends CallableInstance {
10201018
* @param {VFileCompatible | undefined} [file]
10211019
* File associated with `node` (optional); any value accepted as `x` in
10221020
* `new VFile(x)`.
1023-
* @returns {CompileResult extends undefined ? VFileValue | null : CompileResult}
1021+
* @returns {CompileResult extends undefined ? VFileValue : CompileResult}
10241022
* Textual representation of the tree (see note).
10251023
*
10261024
* > 👉 **Note**: unified typically compiles by serializing: most compilers

test/process-compilers.js

-14
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ test('process (compilers)', async function (t) {
3434
assert.equal(file.result, undefined)
3535
})
3636

37-
await t.test('should compile `null`', async function () {
38-
const processor = unified()
39-
40-
processor.Parser = simpleParser
41-
processor.Compiler = function () {
42-
return null
43-
}
44-
45-
const file = await processor.process('alpha')
46-
47-
assert.equal(file.value, 'alpha')
48-
assert.equal(file.result, undefined)
49-
})
50-
5137
await t.test('should compile non-text', async function () {
5238
const processor = unified()
5339
const result = {

0 commit comments

Comments
 (0)