Skip to content

Commit c9b0466

Browse files
committed
Update @types/mdast, @types/nlcst, vfile
1 parent 24f97ec commit c9b0466

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

lib/index.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
/**
2-
* @typedef {import('unist').Point} Point
3-
* @typedef {import('unist').Position} UnistPosition
4-
* @typedef {import('unist').Parent} UnistParent
2+
* @typedef {import('mdast').Nodes} MdastNodes
3+
* @typedef {import('mdast').Parents} MdastParents
54
*
65
* @typedef {import('nlcst').Root} NlcstRoot
7-
* @typedef {import('nlcst').Content} NlcstContent
6+
* @typedef {import('nlcst').RootContent} NlcstRootContent
7+
* @typedef {import('nlcst').Parents} NlcstParents
88
* @typedef {import('nlcst').SentenceContent} NlcstSentenceContent
99
* @typedef {import('nlcst').WhiteSpace} NlcstWhiteSpace
1010
* @typedef {import('nlcst').Sentence} NlcstSentence
1111
* @typedef {import('nlcst').Paragraph} NlcstParagraph
1212
*
13-
* @typedef {import('mdast').Root} MdastRoot
14-
* @typedef {import('mdast').Content} MdastContent
13+
* @typedef {import('unist').Point} Point
1514
*
1615
* @typedef {import('vfile').VFile} VFile
1716
*
18-
* @typedef {ReturnType<import('vfile-location').location>} Location
17+
* @typedef {import('vfile-location').Location} Location
1918
*/
2019

2120
/**
22-
* @typedef {MdastRoot | MdastContent} MdastNode
23-
* @typedef {NlcstRoot | NlcstContent} NlcstNode
24-
* @typedef {Extract<NlcstNode, UnistParent>} NlcstParent
25-
* @typedef {Extract<MdastNode, UnistParent>} MdastParent
26-
*
2721
* @typedef {{
2822
* tokenizeSentencePlugins: Array<(node: NlcstSentence) => void>,
2923
* tokenizeParagraphPlugins: Array<(node: NlcstParagraph) => void>,
@@ -40,11 +34,11 @@
4034
* @typedef Options
4135
* Configuration.
4236
* @property {Array<string> | null | undefined} [ignore]
43-
* List of mdast node types to ignore.
37+
* List of mdast node types to ignore (optional).
4438
*
4539
* The types `'table'`, `'tableRow'`, and `'tableCell'` are always ignored.
4640
* @property {Array<string> | null | undefined} [source]
47-
* List of mdast node types to mark as `source`.
41+
* List of mdast node types to mark as `source` (optional).
4842
*
4943
* The type `'inlineCode'` is always marked as source.
5044
*
@@ -80,7 +74,7 @@ const terminalMarker = /^([!.?\u2026\u203D]+)$/
8074
* > 👉 **Note**: `tree` must have positional info and `file` must be a `VFile`
8175
* > corresponding to `tree`.
8276
*
83-
* @param {MdastNode} tree
77+
* @param {MdastNodes} tree
8478
* mdast tree to transform.
8579
* @param {VFile} file
8680
* Virtual file.
@@ -108,7 +102,7 @@ export function toNlcst(tree, file, Parser, options) {
108102
throw new Error('mdast-util-to-nlcst expected parser')
109103
}
110104

111-
if (!pointStart(tree).line || !pointStart(tree).column) {
105+
if (!pointStart(tree)) {
112106
throw new Error('mdast-util-to-nlcst expected position on nodes')
113107
}
114108

@@ -197,7 +191,7 @@ function sentenceContentToRoot(state, nodes) {
197191
*
198192
* @param {State} state
199193
* State.
200-
* @param {MdastNode} node
194+
* @param {MdastNodes} node
201195
* mdast node.
202196
* @returns {Array<NlcstSentenceContent> | undefined}
203197
* nlcst sentence content.
@@ -243,7 +237,7 @@ function one(state, node) {
243237
*
244238
* @param {State} state
245239
* State.
246-
* @param {MdastParent} parent
240+
* @param {MdastParents} parent
247241
* mdast parent node.
248242
* @returns {Array<NlcstSentenceContent>}
249243
* nlcst sentence content.
@@ -261,8 +255,8 @@ function all(state, parent) {
261255

262256
if (
263257
end &&
264-
end.line !== null &&
265-
start.line !== null &&
258+
typeof end.line === 'number' &&
259+
start &&
266260
start.line !== end.line
267261
) {
268262
/** @type {NlcstWhiteSpace} */
@@ -295,7 +289,7 @@ function all(state, parent) {
295289
*
296290
* @param {State} state
297291
* State.
298-
* @param {Array<NlcstContent>} nodes
292+
* @param {Array<NlcstRootContent>} nodes
299293
* nlcst sentence content.
300294
* @param {number | undefined} offset
301295
* Offset.
@@ -331,10 +325,10 @@ function patch(state, nodes, offset) {
331325
/**
332326
* A function that splits one node into several nodes.
333327
*
334-
* @template {NlcstParent} TheNode
328+
* @template {NlcstParents} TheNode
335329
* @param {TheNode} node
336330
* @param {RegExp} expression
337-
* @param {NlcstContent['type']} childType
331+
* @param {NlcstRootContent['type']} childType
338332
* @returns {Array<TheNode>}
339333
*/
340334
function splitNode(node, childType, expression) {

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
"index.js"
3636
],
3737
"dependencies": {
38-
"@types/mdast": "^3.0.0",
39-
"@types/nlcst": "^1.0.0",
40-
"@types/unist": "^2.0.0",
38+
"@types/mdast": "^4.0.0",
39+
"@types/nlcst": "^2.0.0",
40+
"@types/unist": "^3.0.0",
4141
"nlcst-to-string": "^3.0.0",
42-
"unist-util-position": "^4.0.0",
43-
"vfile": "^5.0.0",
44-
"vfile-location": "^4.0.0"
42+
"unist-util-position": "^5.0.0",
43+
"vfile": "^6.0.0",
44+
"vfile-location": "^5.0.0"
4545
},
4646
"devDependencies": {
4747
"@types/node": "^20.0.0",
@@ -58,7 +58,7 @@
5858
"prettier": "^2.0.0",
5959
"remark-cli": "^11.0.0",
6060
"remark-preset-wooorm": "^9.0.0",
61-
"to-vfile": "^7.0.0",
61+
"to-vfile": "^8.0.0",
6262
"type-coverage": "^2.0.0",
6363
"typescript": "^5.0.0",
6464
"xo": "^0.54.0"

test/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ test('fixtures', async () => {
271271
config.extensions.push(frontmatter())
272272
}
273273

274-
const mdast = fromMarkdown(String(input), config)
274+
// To do: remove cast when `from-markdown` releases.
275+
const mdast = /** @type {Root} */ (fromMarkdown(String(input), config))
275276

276277
assert.deepEqual(
277278
toNlcst(mdast, input, ParseLatin, options),

0 commit comments

Comments
 (0)