Skip to content

Commit 3993414

Browse files
committed
Add strict to tsconfig.json
1 parent 96df36d commit 3993414

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

lib/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {find, html, svg} from 'property-information'
2727

2828
/**
2929
* @param {HastNode} node
30-
* @param {Context} [ctx]
30+
* @param {Context} ctx
3131
*/
3232
function transform(node, ctx) {
3333
switch (node.type) {
@@ -56,13 +56,13 @@ function transform(node, ctx) {
5656
function root(node, ctx) {
5757
const {doc, fragment, namespace: ctxNamespace} = ctx
5858
const {children = []} = node
59-
const {length: childrenLength} = children
6059

6160
let namespace = ctxNamespace
62-
let rootIsDocument = childrenLength === 0
61+
let rootIsDocument = children.length === 0
62+
let index = -1
6363

64-
for (let i = 0; i < childrenLength; i += 1) {
65-
const child = children[i]
64+
while (++index < children.length) {
65+
const child = children[index]
6666

6767
if (child.type === 'element' && child.tagName === 'html') {
6868
const {properties = {}} = child
@@ -71,7 +71,7 @@ function root(node, ctx) {
7171
rootIsDocument = true
7272

7373
// Take namespace of the first child.
74-
if (typeof ctxNamespace === 'undefined') {
74+
if (ctxNamespace === undefined) {
7575
namespace = String(properties.xmlns || '') || webNamespaces.html
7676
}
7777
}
@@ -82,7 +82,7 @@ function root(node, ctx) {
8282
let result
8383

8484
if (rootIsDocument) {
85-
result = doc.implementation.createDocument(namespace, '', null)
85+
result = doc.implementation.createDocument(namespace || null, '', null)
8686
} else if (fragment) {
8787
result = doc.createDocumentFragment()
8888
} else {
@@ -192,6 +192,7 @@ function element(node, ctx) {
192192
}
193193

194194
if (mustUseProperty) {
195+
// @ts-expect-error: fine.
195196
result[property] = value
196197
}
197198

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"web-namespaces": "^2.0.0"
3939
},
4040
"devDependencies": {
41+
"@types/glob": "^7.0.0",
4142
"@types/jsdom": "^16.0.0",
4243
"@types/tape": "^4.0.0",
4344
"@types/w3c-xmlserializer": "^2.0.0",

test/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ globalThis.document = document
1919

2020
test('hast-util-to-dom', (t) => {
2121
t.equal(
22-
// @ts-ignore runtime.
22+
// @ts-expect-error runtime.
2323
serializeNodeToHtmlString(toDom({type: 'root'})),
2424
'',
2525
'creates an empty root node'
@@ -43,7 +43,7 @@ test('hast-util-to-dom', (t) => {
4343
toDom({
4444
type: 'root',
4545
children: [
46-
{type: 'doctype', name: 'html', public: null, system: null},
46+
{type: 'doctype', name: 'html', public: undefined, system: undefined},
4747
{
4848
type: 'element',
4949
tagName: 'html',
@@ -73,15 +73,15 @@ test('hast-util-to-dom', (t) => {
7373
)
7474

7575
t.equal(
76-
// @ts-ignore runtime.
76+
// @ts-expect-error runtime.
7777
serializeNodeToHtmlString(toDom({type: 'something-else'})),
7878
'<div></div>',
7979
'creates an unknown node in HTML'
8080
)
8181

8282
t.equal(
8383
serializeNodeToHtmlString(
84-
// @ts-ignore runtime.
84+
// @ts-expect-error runtime.
8585
toDom({type: 'something-else'}, {namespace: webNamespaces.svg})
8686
),
8787
'<g/>',
@@ -91,7 +91,7 @@ test('hast-util-to-dom', (t) => {
9191
t.equal(
9292
serializeNodeToHtmlString(
9393
toDom({
94-
// @ts-ignore runtime.
94+
// @ts-expect-error runtime.
9595
type: 'something-else',
9696
children: [{type: 'text', value: 'value'}]
9797
})
@@ -165,7 +165,7 @@ test('hast-util-to-dom', (t) => {
165165
)
166166

167167
t.equal(
168-
// @ts-ignore hast types out of date.
168+
// @ts-expect-error hast types out of date.
169169
serializeNodeToHtmlString(toDom({type: 'doctype'})),
170170
'<!DOCTYPE html>',
171171
'creates a doctype node'
@@ -292,7 +292,7 @@ test('hast-util-to-dom', (t) => {
292292
type: 'root',
293293
children: [h('html', [h('title', 'foo'), h('h1', 'bar')])]
294294
},
295-
// @ts-ignore Minimum of what we need.
295+
// @ts-expect-error Minimum of what we need.
296296
{document: doc}
297297
)
298298
),

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)