Skip to content

Commit 5911a1f

Browse files
committed
Add strict to tsconfig.json
1 parent 49c419a commit 5911a1f

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

index.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('mdast').Content} Node
2+
* @typedef {import('mdast').Content|import('mdast').Root} Node
33
*/
44

55
import {visit} from 'unist-util-visit'
@@ -12,37 +12,39 @@ import {visit} from 'unist-util-visit'
1212
* @returns {T}
1313
*/
1414
export function compact(tree) {
15-
visit(tree, visitor)
16-
17-
return tree
18-
19-
/** @type {import('unist-util-visit').Visitor<Node>} */
20-
function visitor(child, index, parent) {
21-
const siblings = parent ? parent.children : []
22-
const previous = index && siblings[index - 1]
23-
24-
if (
25-
(child.type === 'text' || child.type === 'blockquote') &&
26-
previous &&
27-
child.type === previous.type
28-
) {
29-
if ('value' in child) {
30-
// @ts-ignore must be text.
31-
previous.value += child.value
15+
visit(
16+
tree,
17+
/** @type {import('unist-util-visit').Visitor<Node>} */
18+
// @ts-expect-error: fine.
19+
(child, index, parent) => {
20+
if (
21+
parent &&
22+
index &&
23+
(child.type === 'text' || child.type === 'blockquote') &&
24+
child.type === parent.children[index - 1].type
25+
) {
26+
const previous = parent.children[index - 1]
27+
28+
if ('value' in child) {
29+
// @ts-expect-error must be text.
30+
previous.value += child.value
31+
}
32+
33+
if ('children' in child) {
34+
// @ts-expect-error must be block quote.
35+
previous.children = previous.children.concat(child.children)
36+
}
37+
38+
parent.children.splice(index, 1)
39+
40+
if (previous.position && child.position) {
41+
previous.position.end = child.position.end
42+
}
43+
44+
return index
3245
}
33-
34-
if ('children' in child) {
35-
// @ts-ignore must be block quote.
36-
previous.children = previous.children.concat(child.children)
37-
}
38-
39-
siblings.splice(index, 1)
40-
41-
if (previous.position && child.position) {
42-
previous.position.end = child.position.end
43-
}
44-
45-
return index
4646
}
47-
}
47+
)
48+
49+
return tree
4850
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"declaration": true,
1111
"emitDeclarationOnly": true,
1212
"allowSyntheticDefaultImports": true,
13-
"skipLibCheck": true
13+
"skipLibCheck": true,
14+
"strict": true
1415
}
1516
}

0 commit comments

Comments
 (0)