22 * @typedef {import('mdast').Nodes } MdastNodes
33 * @typedef {import('mdast').Parents } MdastParents
44 *
5+ * @typedef {import('nlcst').Paragraph } NlcstParagraph
6+ * @typedef {import('nlcst').Parents } NlcstParents
57 * @typedef {import('nlcst').Root } NlcstRoot
68 * @typedef {import('nlcst').RootContent } NlcstRootContent
7- * @typedef {import('nlcst').Parents } NlcstParents
9+ * @typedef {import('nlcst').Sentence } NlcstSentence
810 * @typedef {import('nlcst').SentenceContent } NlcstSentenceContent
911 * @typedef {import('nlcst').WhiteSpace } NlcstWhiteSpace
10- * @typedef {import('nlcst').Sentence } NlcstSentence
11- * @typedef {import('nlcst').Paragraph } NlcstParagraph
1212 *
1313 * @typedef {import('unist').Point } Point
1414 *
1919
2020/**
2121 * @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>,
2525 * parse(value: string | null | undefined): NlcstRoot
2626 * tokenize(value: string | null | undefined): Array<NlcstSentenceContent>
2727 * }} ParserInstance
4646 * Info passed around.
4747 * @property {string } doc
4848 * Whole document.
49+ * @property {Array<string> } ignore
50+ * List of mdast node types to ignore.
4951 * @property {Location } place
5052 * Location info.
5153 * @property {ParserInstance } parser
5254 * Parser.
53- * @property {Array<string> } ignore
54- * List of mdast node types to ignore.
5555 * @property {Array<string> } source
5656 * List of mdast node types to mark as source.
5757 */
5858
5959import { toString } from 'nlcst-to-string'
60- import { pointStart , pointEnd } from 'unist-util-position'
60+ import { pointEnd , pointStart } from 'unist-util-position'
6161import { location } from 'vfile-location'
6262
6363const defaultIgnore = [ 'table' , 'tableRow' , 'tableCell' ]
@@ -78,10 +78,10 @@ const terminalMarker = /^([!.?\u2026\u203D]+)$/
7878 * mdast tree to transform.
7979 * @param {VFile } file
8080 * Virtual file.
81- * @param {ParserInstance | ParserConstructor } Parser
81+ * @param {ParserConstructor | ParserInstance } Parser
8282 * Parser to use.
8383 * @param {Options | null | undefined } [options]
84- * Configuration.
84+ * Configuration (optional) .
8585 * @returns {NlcstRoot }
8686 * nlcst tree.
8787 */
@@ -293,7 +293,7 @@ function all(state, parent) {
293293 * nlcst sentence content.
294294 * @param {number | undefined } offset
295295 * Offset.
296- * @returns {void }
296+ * @returns {undefined }
297297 * Nothing.
298298 */
299299function patch ( state , nodes , offset ) {
@@ -310,11 +310,11 @@ function patch(state, nodes, offset) {
310310 const end =
311311 typeof start === 'number' ? start + toString ( node ) . length : undefined
312312
313- // @ts -expect-error: to do: fix this.
313+ const startPoint = state . place . toPoint ( start )
314+ const endPoint = state . place . toPoint ( end )
315+
314316 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
318318
319319 start = end
320320 }
0 commit comments