Skip to content

Commit fc69128

Browse files
committed
Add strict to tsconfig.json
1 parent 33f8984 commit fc69128

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
* @property {Parent|null} parent
1010
*
1111
* @callback Handler
12-
* @param {Node|undefined} start
12+
* @param {Node} start
1313
* @param {Array.<Node>} between
14-
* @param {Node|undefined} end
14+
* @param {Node} end
1515
* @param {ZoneInfo} info
16+
* @returns {Array.<Node>|null|undefined|void}
1617
*/
1718

1819
import {commentMarker} from 'mdast-comment-marker'
@@ -24,11 +25,11 @@ import {visit} from 'unist-util-visit'
2425
* @param {Handler} callback
2526
*/
2627
export function zone(node, name, callback) {
27-
/** @type {number} */
28+
/** @type {number|undefined} */
2829
let level
29-
/** @type {Node} */
30+
/** @type {Node|undefined} */
3031
let marker
31-
/** @type {Parent} */
32+
/** @type {Parent|undefined} */
3233
let scope
3334

3435
visit(node, gather)
@@ -43,14 +44,14 @@ export function zone(node, name, callback) {
4344
info && info.name === name && info.attributes.match(/(start|end)\b/)
4445
const type = match && match[0]
4546

46-
if (type) {
47+
if (parent && index !== null && type) {
4748
if (!scope && type === 'start') {
4849
level = 0
4950
marker = node
5051
scope = parent
5152
}
5253

53-
if (scope && parent === scope) {
54+
if (typeof level === 'number' && marker && scope && parent === scope) {
5455
if (type === 'start') {
5556
level++
5657
} else {

test/fixtures/replace-children/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default function assertion(_, zone, tree) {
1010
function handle(start, _, end) {
1111
return [
1212
start,
13-
{
13+
/** @type {import('mdast').Heading} */ ({
1414
type: 'heading',
1515
depth: 2,
1616
children: [{type: 'text', value: 'Bar'}]
17-
},
17+
}),
1818
end
1919
]
2020
}

test/index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ test('mdast-zone', async (t) => {
1515
const root = path.join('test', 'fixtures')
1616
const fixtures = fs.readdirSync(root)
1717
let index = -1
18-
/** @type {string} */
19-
let output
20-
/** @type {string} */
21-
let name
22-
/** @type {(t: Test, zone: Zone, node: Node) => void} */
23-
let mod
2418

2519
while (++index < fixtures.length) {
26-
name = fixtures[index]
27-
output = null
20+
const name = fixtures[index]
21+
/** @type {string|undefined} */
22+
let output
2823

2924
if (isHidden(name)) continue
3025

@@ -33,7 +28,8 @@ test('mdast-zone', async (t) => {
3328
} catch {}
3429

3530
/* eslint-disable no-await-in-loop */
36-
mod =
31+
/** @type {(t: Test, zone: Zone, node: Node) => void} */
32+
const mod =
3733
// @ts-ignore hush.
3834
(await import(new URL('fixtures/' + name + '/index.js', import.meta.url)))
3935
.default // type-coverage:ignore-line

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)