Skip to content

Commit c4a7d78

Browse files
committed
Add strict to tsconfig.json
1 parent 1bba23e commit c4a7d78

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function headingRange(node, options, handler) {
3737
/** @type {Array.<Node>} */
3838
// @ts-ignore looks like children.
3939
const children = node.children || []
40-
/** @type {boolean} */
40+
/** @type {boolean|undefined} */
4141
let ignoreFinalDefinitions
4242

4343
// Object, not regex.
@@ -65,11 +65,11 @@ export function headingRange(node, options, handler) {
6565
}
6666

6767
let index = -1
68-
/** @type {number} */
68+
/** @type {number|undefined} */
6969
let start
70-
/** @type {number} */
70+
/** @type {number|undefined} */
7171
let end
72-
/** @type {number} */
72+
/** @type {number|undefined} */
7373
let depth
7474

7575
// Find the range.
@@ -95,7 +95,7 @@ export function headingRange(node, options, handler) {
9595
}
9696

9797
// When we have a starting heading.
98-
if (depth) {
98+
if (depth && end !== undefined && start !== undefined) {
9999
if (ignoreFinalDefinitions) {
100100
while (
101101
children[end - 1].type === 'definition' ||

test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ test('mdast-util-heading-range()', (t) => {
1818
() => {
1919
headingRange(
2020
/** @type {Root} */ ({type: 'root', children: []}),
21+
// @ts-expect-error: runtime.
2122
null,
2223
() => {}
2324
)
@@ -30,6 +31,7 @@ test('mdast-util-heading-range()', (t) => {
3031
() => {
3132
headingRange(
3233
/** @type {Root} */ ({type: 'root', children: []}),
34+
// @ts-expect-error: runtime.
3335
undefined,
3436
() => {}
3537
)
@@ -328,7 +330,7 @@ function process(t, value, options) {
328330
headingRange(node, options, (start, _, end, scope) => {
329331
t.equal(typeof scope.start, 'number')
330332
t.assert(typeof scope.end === 'number' || scope.end === null)
331-
t.equal(scope.parent.type, 'root')
333+
t.equal(scope.parent && scope.parent.type, 'root')
332334
return [start, end]
333335
})
334336
}

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)