Skip to content

Commit efa708e

Browse files
committed
Update for changes in @types/unist
1 parent 10db24c commit efa708e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
2+
* @typedef {Extract<import('mdast').Root|import('mdast').Content, import('unist').Parent>} Parent
23
* @typedef {import('mdast').ListItem} ListItem
34
* @typedef {import('mdast').Paragraph} Paragraph
45
* @typedef {import('mdast').BlockContent} BlockContent
@@ -27,19 +28,15 @@ export const gfmTaskListItemToMarkdown = {
2728

2829
/** @type {FromMarkdownHandle} */
2930
function exitCheck(token) {
31+
const node = /** @type {ListItem} */ (this.stack[this.stack.length - 2])
3032
// 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'
3334
}
3435

3536
/** @type {FromMarkdownHandle} */
3637
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])
4340
const siblings = parent.children
4441
const head = node.children[0]
4542
let index = -1
@@ -67,12 +64,13 @@ function exitParagraphWithTaskListItem(token) {
6764

6865
if (head.value.length === 0) {
6966
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+
) {
7272
head.position.start.column++
73-
// @ts-expect-error: must be true.
7473
head.position.start.offset++
75-
// @ts-expect-error: must be true.
7674
node.position.start = Object.assign({}, head.position.start)
7775
}
7876
}

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ test('mdast -> markdown', (t) => {
311311
checked: true,
312312
children: [
313313
{
314+
// @ts-expect-error: definitions are fine.
314315
type: 'definition',
315316
label: 'd',
316317
title: null,

0 commit comments

Comments
 (0)