1
1
/**
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
5
4
*
6
5
* @typedef {import('nlcst').Root } NlcstRoot
7
- * @typedef {import('nlcst').Content } NlcstContent
6
+ * @typedef {import('nlcst').RootContent } NlcstRootContent
7
+ * @typedef {import('nlcst').Parents } NlcstParents
8
8
* @typedef {import('nlcst').SentenceContent } NlcstSentenceContent
9
9
* @typedef {import('nlcst').WhiteSpace } NlcstWhiteSpace
10
10
* @typedef {import('nlcst').Sentence } NlcstSentence
11
11
* @typedef {import('nlcst').Paragraph } NlcstParagraph
12
12
*
13
- * @typedef {import('mdast').Root } MdastRoot
14
- * @typedef {import('mdast').Content } MdastContent
13
+ * @typedef {import('unist').Point } Point
15
14
*
16
15
* @typedef {import('vfile').VFile } VFile
17
16
*
18
- * @typedef {ReturnType< import('vfile-location').location> } Location
17
+ * @typedef {import('vfile-location').Location } Location
19
18
*/
20
19
21
20
/**
22
- * @typedef {MdastRoot | MdastContent } MdastNode
23
- * @typedef {NlcstRoot | NlcstContent } NlcstNode
24
- * @typedef {Extract<NlcstNode, UnistParent> } NlcstParent
25
- * @typedef {Extract<MdastNode, UnistParent> } MdastParent
26
- *
27
21
* @typedef {{
28
22
* tokenizeSentencePlugins: Array<(node: NlcstSentence) => void>,
29
23
* tokenizeParagraphPlugins: Array<(node: NlcstParagraph) => void>,
40
34
* @typedef Options
41
35
* Configuration.
42
36
* @property {Array<string> | null | undefined } [ignore]
43
- * List of mdast node types to ignore.
37
+ * List of mdast node types to ignore (optional) .
44
38
*
45
39
* The types `'table'`, `'tableRow'`, and `'tableCell'` are always ignored.
46
40
* @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) .
48
42
*
49
43
* The type `'inlineCode'` is always marked as source.
50
44
*
@@ -80,7 +74,7 @@ const terminalMarker = /^([!.?\u2026\u203D]+)$/
80
74
* > 👉 **Note**: `tree` must have positional info and `file` must be a `VFile`
81
75
* > corresponding to `tree`.
82
76
*
83
- * @param {MdastNode } tree
77
+ * @param {MdastNodes } tree
84
78
* mdast tree to transform.
85
79
* @param {VFile } file
86
80
* Virtual file.
@@ -108,7 +102,7 @@ export function toNlcst(tree, file, Parser, options) {
108
102
throw new Error ( 'mdast-util-to-nlcst expected parser' )
109
103
}
110
104
111
- if ( ! pointStart ( tree ) . line || ! pointStart ( tree ) . column ) {
105
+ if ( ! pointStart ( tree ) ) {
112
106
throw new Error ( 'mdast-util-to-nlcst expected position on nodes' )
113
107
}
114
108
@@ -197,7 +191,7 @@ function sentenceContentToRoot(state, nodes) {
197
191
*
198
192
* @param {State } state
199
193
* State.
200
- * @param {MdastNode } node
194
+ * @param {MdastNodes } node
201
195
* mdast node.
202
196
* @returns {Array<NlcstSentenceContent> | undefined }
203
197
* nlcst sentence content.
@@ -243,7 +237,7 @@ function one(state, node) {
243
237
*
244
238
* @param {State } state
245
239
* State.
246
- * @param {MdastParent } parent
240
+ * @param {MdastParents } parent
247
241
* mdast parent node.
248
242
* @returns {Array<NlcstSentenceContent> }
249
243
* nlcst sentence content.
@@ -261,8 +255,8 @@ function all(state, parent) {
261
255
262
256
if (
263
257
end &&
264
- end . line !== null &&
265
- start . line !== null &&
258
+ typeof end . line === 'number' &&
259
+ start &&
266
260
start . line !== end . line
267
261
) {
268
262
/** @type {NlcstWhiteSpace } */
@@ -295,7 +289,7 @@ function all(state, parent) {
295
289
*
296
290
* @param {State } state
297
291
* State.
298
- * @param {Array<NlcstContent > } nodes
292
+ * @param {Array<NlcstRootContent > } nodes
299
293
* nlcst sentence content.
300
294
* @param {number | undefined } offset
301
295
* Offset.
@@ -331,10 +325,10 @@ function patch(state, nodes, offset) {
331
325
/**
332
326
* A function that splits one node into several nodes.
333
327
*
334
- * @template {NlcstParent } TheNode
328
+ * @template {NlcstParents } TheNode
335
329
* @param {TheNode } node
336
330
* @param {RegExp } expression
337
- * @param {NlcstContent ['type'] } childType
331
+ * @param {NlcstRootContent ['type'] } childType
338
332
* @returns {Array<TheNode> }
339
333
*/
340
334
function splitNode ( node , childType , expression ) {
0 commit comments