Skip to content

Commit a0f2c46

Browse files
committed
Change to return undefined, not null
1 parent 82c674d commit a0f2c46

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

lib/index.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ const markerExpression = new RegExp(
3737
'(\\s*<!--' + commentExpression.source + '-->\\s*)'
3838
)
3939

40-
// To do: next major: replace `null` with `undefined` in API output.
4140
/**
4241
* Parse a comment marker.
4342
*
4443
* @param {unknown} value
4544
* Thing to parse, typically `Node`.
46-
* @returns {Marker | null}
47-
* Info when applicable or `null`.
45+
* @returns {Marker | undefined}
46+
* Info when applicable or `undefined`.
4847
*/
4948
export function commentMarker(value) {
5049
if (
@@ -53,17 +52,9 @@ export function commentMarker(value) {
5352
value.type === 'mdxFlowExpression' ||
5453
value.type === 'mdxTextExpression')
5554
) {
56-
/** @type {RegExpMatchArray | null | undefined} */
57-
let match
58-
59-
if (value.type === 'html') {
60-
match = value.value.match(markerExpression)
61-
} else if (
62-
value.type === 'mdxFlowExpression' ||
63-
value.type === 'mdxTextExpression'
64-
) {
65-
match = value.value.match(esCommentExpression)
66-
}
55+
const match = value.value.match(
56+
value.type === 'html' ? markerExpression : esCommentExpression
57+
)
6758

6859
if (match && match[0].length === value.value.length) {
6960
const parameters = parseParameters(match[3] || '')
@@ -78,8 +69,6 @@ export function commentMarker(value) {
7869
}
7970
}
8071
}
81-
82-
return null
8372
}
8473

8574
/**

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Yields:
103103
value: `<!--foo bar baz=12.4 qux="test test" quux='false'-->`
104104
}
105105
}
106-
null
106+
undefined
107107
{
108108
name: 'lint',
109109
attributes: 'disable heading-style',
@@ -131,7 +131,7 @@ Parse a comment marker.
131131

132132
###### Returns
133133

134-
Info ([`Marker`][api-marker]) when applicable or `null`.
134+
Info ([`Marker`][api-marker]) when applicable or `undefined`.
135135

136136
### `Marker`
137137

test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ test('commentMaker', async function (t) {
1313
assert.equal(
1414
// @ts-expect-error: check that the runtime handles a missing node.
1515
commentMarker(),
16-
null
16+
undefined
1717
)
1818
})
1919

2020
await t.test('should work without html node', async function () {
2121
const paragraph = {type: 'paragraph', children: []}
2222

23-
assert.equal(commentMarker(paragraph), null)
23+
assert.equal(commentMarker(paragraph), undefined)
2424
})
2525

2626
await t.test('should work without comment', async function () {
2727
const html = {type: 'html', value: '<div></div>'}
2828

29-
assert.equal(commentMarker(html), null)
29+
assert.equal(commentMarker(html), undefined)
3030
})
3131

3232
await t.test('should work for empty comments', async function () {
3333
const html = {type: 'html', value: '<!-- -->'}
3434

35-
assert.equal(commentMarker(html), null)
35+
assert.equal(commentMarker(html), undefined)
3636
})
3737

3838
await t.test('should work for partial comments', async function () {
3939
const html = {type: 'html', value: '<!--foo-->this is something else.'}
4040

41-
assert.equal(commentMarker(html), null)
41+
assert.equal(commentMarker(html), undefined)
4242
})
4343

4444
await t.test('should support a marker without attributes', async function () {
@@ -160,7 +160,7 @@ test('commentMaker', async function (t) {
160160
async function () {
161161
const html = {type: 'html', value: '<!--foo bar=-->'}
162162

163-
assert.equal(commentMarker(html), null)
163+
assert.equal(commentMarker(html), undefined)
164164
}
165165
)
166166

@@ -169,7 +169,7 @@ test('commentMaker', async function (t) {
169169
async function () {
170170
const html = {type: 'html', value: '<!--foo bar= qux-->'}
171171

172-
assert.equal(commentMarker(html), null)
172+
assert.equal(commentMarker(html), undefined)
173173
}
174174
)
175175

@@ -178,7 +178,7 @@ test('commentMaker', async function (t) {
178178
async function () {
179179
const html = {type: 'html', value: '<!--foo |-->'}
180180

181-
assert.equal(commentMarker(html), null)
181+
assert.equal(commentMarker(html), undefined)
182182
}
183183
)
184184

0 commit comments

Comments
 (0)