Skip to content

Commit 343fae5

Browse files
committed
Add strict to tsconfig.json
1 parent 860a8e5 commit 343fae5

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

lib/index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
import {embedded} from 'hast-util-embedded'
2323
import {convertElement} from 'hast-util-is-element'
2424
import {phrasing} from 'hast-util-phrasing'
25+
// @ts-expect-error: to do type.
2526
import toString from 'hast-util-to-string'
2627
import {whitespace} from 'hast-util-whitespace'
2728
import {toString as nlcstToString} from 'nlcst-to-string'
2829
import {pointStart} from 'unist-util-position'
2930
import vfileLocation from 'vfile-location'
3031

31-
const push = [].push
32-
3332
const source = convertElement(['code', dataNlcstSourced])
3433
const ignore = convertElement([
3534
'script',
@@ -181,7 +180,7 @@ export function toNlcst(tree, file, Parser) {
181180
function implicit(children) {
182181
let index = -1
183182
let start = -1
184-
/** @type {boolean} */
183+
/** @type {boolean|undefined} */
185184
let viable
186185

187186
while (++index <= children.length) {
@@ -203,7 +202,7 @@ export function toNlcst(tree, file, Parser) {
203202
find(child)
204203
}
205204

206-
viable = null
205+
viable = undefined
207206
start = -1
208207
}
209208
}
@@ -213,12 +212,12 @@ export function toNlcst(tree, file, Parser) {
213212
* Convert `node` (hast) to nlcst.
214213
*
215214
* @param {Node} node
216-
* @returns {Array.<UnistNode>}
215+
* @returns {Array.<UnistNode>|undefined}
217216
*/
218217
function one(node) {
219-
/** @type {Array.<UnistNode>} */
218+
/** @type {Array.<UnistNode>|undefined} */
220219
let replacement
221-
/** @type {boolean} */
220+
/** @type {boolean|undefined} */
222221
let change
223222

224223
if (node.type === 'text') {
@@ -239,7 +238,7 @@ export function toNlcst(tree, file, Parser) {
239238
}
240239
}
241240

242-
return change
241+
return change && replacement
243242
? patch(replacement, location, location.toOffset(pointStart(node)))
244243
: replacement
245244
}
@@ -256,7 +255,7 @@ export function toNlcst(tree, file, Parser) {
256255
let index = -1
257256

258257
while (++index < children.length) {
259-
push.apply(results, one(children[index]) || [])
258+
results.push(...(one(children[index]) || []))
260259
}
261260

262261
return results
@@ -306,13 +305,13 @@ export function toNlcst(tree, file, Parser) {
306305
* @returns {boolean}
307306
*/
308307
function dataNlcstSourced(node) {
309-
return node.properties.dataNlcst === 'source'
308+
return Boolean(node.properties && node.properties.dataNlcst === 'source')
310309
}
311310

312311
/**
313312
* @param {Element} node
314313
* @returns {boolean}
315314
*/
316315
function dataNlcstIgnore(node) {
317-
return node.properties.dataNlcst === 'ignore'
316+
return Boolean(node.properties && node.properties.dataNlcst === 'ignore')
318317
}

test/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import path from 'path'
33
import test from 'tape'
44
import rehype from 'rehype'
55
import vfile from 'vfile'
6+
// @ts-expect-error: to do type.
67
import {ParseLatin} from 'parse-latin'
8+
// @ts-expect-error: to do type.
79
import {ParseDutch} from 'parse-dutch'
10+
// @ts-expect-error: to do type.
811
import {ParseEnglish} from 'parse-english'
912
import {isHidden} from 'is-hidden'
1013
import {toNlcst} from '../index.js'

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)