Skip to content

Commit e69b3a8

Browse files
committed
Fix for changes in @types/unist
1 parent 402d779 commit e69b3a8

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @typedef {import('unist').Node} Node
3+
* @typedef {import('unist').Literal<string>} Literal
34
* @typedef {import('unist').Parent} Parent
45
* @typedef {import('unist').Point} Point
56
* @typedef {import('mdast').Content} Content
@@ -163,11 +164,7 @@ function all(config, parent) {
163164
)
164165
patch(config, [lineEnding], end.offset)
165166

166-
if (
167-
'value' in lineEnding &&
168-
typeof lineEnding.value === 'string' &&
169-
lineEnding.value.length < 2
170-
) {
167+
if (literal(lineEnding) && lineEnding.value.length < 2) {
171168
lineEnding.value = '\n\n'
172169
}
173170

@@ -219,3 +216,11 @@ function patch(config, nodes, offset) {
219216

220217
return nodes
221218
}
219+
220+
/**
221+
* @param {Node} node
222+
* @returns {node is Literal}
223+
*/
224+
function literal(node) {
225+
return 'value' in node
226+
}

test/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @typedef {import('unist').Node} Node
3+
* @typedef {import('unist').Literal<string>} Literal
34
* @typedef {import('vfile').VFile} VFile
45
*/
56

@@ -73,31 +74,35 @@ test('mdast-util-to-nlcst', function (t) {
7374

7475
t.throws(
7576
function () {
76-
toNlcst({type: 'text', value: 'foo'}, vfile(), ParseLatin)
77+
toNlcst(
78+
/** @type {Literal} */ ({type: 'text', value: 'foo'}),
79+
vfile(),
80+
ParseLatin
81+
)
7782
},
7883
/mdast-util-to-nlcst expected position on nodes/,
7984
'should fail when not given positional information'
8085
)
8186

8287
t.doesNotThrow(function () {
8388
toNlcst(
84-
{
89+
/** @type {Literal} */ ({
8590
type: 'text',
8691
value: 'foo',
8792
position: {start: {line: 1, column: 1}, end: {line: 1, column: 4}}
88-
},
93+
}),
8994
vfile(),
9095
ParseEnglish
9196
)
9297
}, 'should accept a parser constructor')
9398

9499
t.doesNotThrow(function () {
95100
toNlcst(
96-
{
101+
/** @type {Literal} */ ({
97102
type: 'text',
98103
value: 'foo',
99104
position: {start: {line: 1, column: 1}, end: {line: 1, column: 4}}
100-
},
105+
}),
101106
vfile(),
102107
new ParseDutch()
103108
)

0 commit comments

Comments
 (0)