2
2
* @typedef {import('mdast').Nodes } MdastNodes
3
3
* @typedef {import('mdast').Parents } MdastParents
4
4
*
5
+ * @typedef {import('nlcst').Paragraph } NlcstParagraph
6
+ * @typedef {import('nlcst').Parents } NlcstParents
5
7
* @typedef {import('nlcst').Root } NlcstRoot
6
8
* @typedef {import('nlcst').RootContent } NlcstRootContent
7
- * @typedef {import('nlcst').Parents } NlcstParents
9
+ * @typedef {import('nlcst').Sentence } NlcstSentence
8
10
* @typedef {import('nlcst').SentenceContent } NlcstSentenceContent
9
11
* @typedef {import('nlcst').WhiteSpace } NlcstWhiteSpace
10
- * @typedef {import('nlcst').Sentence } NlcstSentence
11
- * @typedef {import('nlcst').Paragraph } NlcstParagraph
12
12
*
13
13
* @typedef {import('unist').Point } Point
14
14
*
19
19
20
20
/**
21
21
* @typedef {{
22
- * tokenizeSentencePlugins: Array<(node: NlcstSentence) => void>,
23
- * tokenizeParagraphPlugins: Array<(node: NlcstParagraph) => void>,
24
- * tokenizeRootPlugins: Array<(node: NlcstRoot) => void>,
22
+ * tokenizeSentencePlugins: Array<(node: NlcstSentence) => undefined | void>,
23
+ * tokenizeParagraphPlugins: Array<(node: NlcstParagraph) => undefined | void>,
24
+ * tokenizeRootPlugins: Array<(node: NlcstRoot) => undefined | void>,
25
25
* parse(value: string | null | undefined): NlcstRoot
26
26
* tokenize(value: string | null | undefined): Array<NlcstSentenceContent>
27
27
* }} ParserInstance
46
46
* Info passed around.
47
47
* @property {string } doc
48
48
* Whole document.
49
+ * @property {Array<string> } ignore
50
+ * List of mdast node types to ignore.
49
51
* @property {Location } place
50
52
* Location info.
51
53
* @property {ParserInstance } parser
52
54
* Parser.
53
- * @property {Array<string> } ignore
54
- * List of mdast node types to ignore.
55
55
* @property {Array<string> } source
56
56
* List of mdast node types to mark as source.
57
57
*/
58
58
59
59
import { toString } from 'nlcst-to-string'
60
- import { pointStart , pointEnd } from 'unist-util-position'
60
+ import { pointEnd , pointStart } from 'unist-util-position'
61
61
import { location } from 'vfile-location'
62
62
63
63
const defaultIgnore = [ 'table' , 'tableRow' , 'tableCell' ]
@@ -78,10 +78,10 @@ const terminalMarker = /^([!.?\u2026\u203D]+)$/
78
78
* mdast tree to transform.
79
79
* @param {VFile } file
80
80
* Virtual file.
81
- * @param {ParserInstance | ParserConstructor } Parser
81
+ * @param {ParserConstructor | ParserInstance } Parser
82
82
* Parser to use.
83
83
* @param {Options | null | undefined } [options]
84
- * Configuration.
84
+ * Configuration (optional) .
85
85
* @returns {NlcstRoot }
86
86
* nlcst tree.
87
87
*/
@@ -293,7 +293,7 @@ function all(state, parent) {
293
293
* nlcst sentence content.
294
294
* @param {number | undefined } offset
295
295
* Offset.
296
- * @returns {void }
296
+ * @returns {undefined }
297
297
* Nothing.
298
298
*/
299
299
function patch ( state , nodes , offset ) {
@@ -310,11 +310,11 @@ function patch(state, nodes, offset) {
310
310
const end =
311
311
typeof start === 'number' ? start + toString ( node ) . length : undefined
312
312
313
- // @ts -expect-error: to do: fix this.
313
+ const startPoint = state . place . toPoint ( start )
314
+ const endPoint = state . place . toPoint ( end )
315
+
314
316
node . position =
315
- start !== undefined && end !== undefined
316
- ? { start : state . place . toPoint ( start ) , end : state . place . toPoint ( end ) }
317
- : undefined
317
+ startPoint && endPoint ? { start : startPoint , end : endPoint } : undefined
318
318
319
319
start = end
320
320
}
0 commit comments