Skip to content

Commit 33e7950

Browse files
committed
Add strict to tsconfig.json
1 parent e2fa2fd commit 33e7950

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

index.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,25 @@ const markerExpression = new RegExp(
2525

2626
/**
2727
* Parse a comment marker.
28-
* @param {unknown} node
28+
* @param {unknown} value
2929
* @returns {Marker|null}
3030
*/
31-
export function commentMarker(node) {
32-
if (
33-
node &&
34-
typeof node === 'object' &&
35-
// @ts-ignore hush
36-
(node.type === 'html' || node.type === 'comment')
37-
) {
38-
// @ts-ignore hush
39-
const match = node.value.match(
40-
// @ts-ignore hush
41-
node.type === 'comment' ? commentExpression : markerExpression
31+
export function commentMarker(value) {
32+
if (applicable(value)) {
33+
const match = value.value.match(
34+
value.type === 'comment' ? commentExpression : markerExpression
4235
)
4336

44-
// @ts-ignore hush
45-
if (match && match[0].length === node.value.length) {
46-
// @ts-ignore hush
47-
const offset = node.type === 'comment' ? 1 : 2
37+
if (match && match[0].length === value.value.length) {
38+
const offset = value.type === 'comment' ? 1 : 2
4839
const parameters = parseParameters(match[offset + 1] || '')
4940

5041
if (parameters) {
5142
return {
5243
name: match[offset],
5344
attributes: match[offset + 2] || '',
5445
parameters,
55-
// @ts-ignore hush
56-
node
46+
node: value
5747
}
5848
}
5949
}
@@ -106,3 +96,17 @@ function parseParameters(value) {
10696
return ''
10797
}
10898
}
99+
100+
/**
101+
* @param {unknown} value
102+
* @returns {value is HtmlNode | CommentNode}
103+
*/
104+
function applicable(value) {
105+
return Boolean(
106+
value &&
107+
typeof value === 'object' &&
108+
'type' in value &&
109+
// @ts-expect-error hush
110+
(value.type === 'html' || value.type === 'comment')
111+
)
112+
}

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import test from 'tape'
88
import {commentMarker} from './index.js'
99

1010
test('commentMaker(node)', (t) => {
11+
// @ts-expect-error: runtime: not enough arguments.
1112
t.equal(commentMarker(), null, 'should work without node')
1213

1314
/** @type {Paragraph} */

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)