Skip to content

Commit 92bcd71

Browse files
committed
Add strict to tsconfig.json
1 parent dc9155e commit 92bcd71

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
/**
3030
* @callback ReplaceFunction
31-
* @param {...unknown} parameters
31+
* @param {...any} parameters
3232
* @returns {Array.<Content>|Content|string|false|undefined|null}
3333
*/
3434

@@ -47,7 +47,7 @@ export const defaultIgnore = ['title', 'script', 'style', 'svg', 'math']
4747
* @param {Options} [options]
4848
*/
4949
export function findAndReplace(tree, find, replace, options) {
50-
/** @type {Options} */
50+
/** @type {Options|undefined} */
5151
let settings
5252
/** @type {FindAndReplaceSchema|FindAndReplaceList} */
5353
let schema
@@ -79,7 +79,7 @@ export function findAndReplace(tree, find, replace, options) {
7979
/** @type {import('unist-util-visit-parents').Visitor<Text>} */
8080
function visitor(node, parents) {
8181
let index = -1
82-
/** @type {Parent} */
82+
/** @type {Parent|undefined} */
8383
let grandparent
8484

8585
while (++index < parents.length) {
@@ -100,7 +100,9 @@ export function findAndReplace(tree, find, replace, options) {
100100
grandparent = parent
101101
}
102102

103-
return handler(node, grandparent)
103+
if (grandparent) {
104+
return handler(node, grandparent)
105+
}
104106
}
105107

106108
/**
@@ -115,7 +117,7 @@ export function findAndReplace(tree, find, replace, options) {
115117
let index = parent.children.indexOf(node)
116118
/** @type {Array.<Content>} */
117119
let nodes = []
118-
/** @type {number} */
120+
/** @type {number|undefined} */
119121
let position
120122

121123
find.lastIndex = 0
@@ -127,17 +129,19 @@ export function findAndReplace(tree, find, replace, options) {
127129
// @ts-expect-error this is perfectly fine, typescript.
128130
let value = replace(...match, {index: match.index, input: match.input})
129131

130-
if (typeof value === 'string' && value.length > 0) {
131-
value = {type: 'text', value}
132+
if (typeof value === 'string') {
133+
value = value.length > 0 ? {type: 'text', value} : undefined
132134
}
133135

134136
if (value !== false) {
135137
if (start !== position) {
136138
nodes.push({type: 'text', value: node.value.slice(start, position)})
137139
}
138140

139-
if (value) {
140-
nodes = [].concat(nodes, value)
141+
if (Array.isArray(value)) {
142+
nodes.push(...value)
143+
} else if (value) {
144+
nodes.push(value)
141145
}
142146

143147
start = position + match[0].length

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
"typeCoverage": {
7777
"atLeast": 100,
7878
"detail": true,
79-
"strict": true
79+
"strict": true,
80+
"#": "needed `any`s",
81+
"ignoreFiles": [
82+
"index.d.ts"
83+
]
8084
}
8185
}

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)