|
1 | 1 | /**
|
| 2 | + * @typedef {Extract<import('mdast').Root|import('mdast').Content, import('unist').Parent>} Parent |
2 | 3 | * @typedef {import('mdast').ListItem} ListItem
|
3 | 4 | * @typedef {import('mdast').Paragraph} Paragraph
|
4 | 5 | * @typedef {import('mdast').BlockContent} BlockContent
|
@@ -27,19 +28,15 @@ export const gfmTaskListItemToMarkdown = {
|
27 | 28 |
|
28 | 29 | /** @type {FromMarkdownHandle} */
|
29 | 30 | function exitCheck(token) {
|
| 31 | + const node = /** @type {ListItem} */ (this.stack[this.stack.length - 2]) |
30 | 32 | // We’re always in a paragraph, in a list item.
|
31 |
| - this.stack[this.stack.length - 2].checked = |
32 |
| - token.type === 'taskListCheckValueChecked' |
| 33 | + node.checked = token.type === 'taskListCheckValueChecked' |
33 | 34 | }
|
34 | 35 |
|
35 | 36 | /** @type {FromMarkdownHandle} */
|
36 | 37 | function exitParagraphWithTaskListItem(token) {
|
37 |
| - const parent = this.stack[this.stack.length - 2] |
38 |
| - /** @type {Paragraph} */ |
39 |
| - // @ts-expect-error: must be true. |
40 |
| - const node = this.stack[this.stack.length - 1] |
41 |
| - /** @type {BlockContent[]} */ |
42 |
| - // @ts-expect-error: check whether `parent` is a `listItem` later. |
| 38 | + const parent = /** @type {Parent} */ (this.stack[this.stack.length - 2]) |
| 39 | + const node = /** @type {Paragraph} */ (this.stack[this.stack.length - 1]) |
43 | 40 | const siblings = parent.children
|
44 | 41 | const head = node.children[0]
|
45 | 42 | let index = -1
|
@@ -67,12 +64,13 @@ function exitParagraphWithTaskListItem(token) {
|
67 | 64 |
|
68 | 65 | if (head.value.length === 0) {
|
69 | 66 | node.children.shift()
|
70 |
| - } else { |
71 |
| - // @ts-expect-error: must be true. |
| 67 | + } else if ( |
| 68 | + node.position && |
| 69 | + head.position && |
| 70 | + typeof head.position.start.offset === 'number' |
| 71 | + ) { |
72 | 72 | head.position.start.column++
|
73 |
| - // @ts-expect-error: must be true. |
74 | 73 | head.position.start.offset++
|
75 |
| - // @ts-expect-error: must be true. |
76 | 74 | node.position.start = Object.assign({}, head.position.start)
|
77 | 75 | }
|
78 | 76 | }
|
|
0 commit comments