Skip to content

Commit ac15c85

Browse files
committed
Add strict to tsconfig.json
1 parent 367baf3 commit ac15c85

File tree

8 files changed

+63
-46
lines changed

8 files changed

+63
-46
lines changed

lib/index.js

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ import {toH} from 'hast-to-hyperscript'
3232
import {webNamespaces} from 'web-namespaces'
3333
import {zwitch} from 'zwitch'
3434

35+
const ns = /** @type {Record<string, string>} */ (webNamespaces)
36+
3537
const own = {}.hasOwnProperty
3638

39+
// @ts-expect-error: hush.
3740
const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
3841

3942
/**
@@ -44,7 +47,7 @@ const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
4447
* @returns {P5Node}
4548
*/
4649
export function toParse5(tree, space) {
47-
// @ts-ignore Types are wrong.
50+
// @ts-expect-error Types are wrong.
4851
return one(tree, space === 'svg' ? svg : html)
4952
}
5053

@@ -60,7 +63,7 @@ function root(node, schema) {
6063
mode: (node.data || {}).quirksMode ? 'quirks' : 'no-quirks',
6164
childNodes: []
6265
}
63-
// @ts-ignore Assume correct children.
66+
// @ts-expect-error Assume correct children.
6467
p5.childNodes = all(node.children, p5, schema)
6568
return patch(node, p5)
6669
}
@@ -73,7 +76,7 @@ function root(node, schema) {
7376
function fragment(node, schema) {
7477
/** @type {P5Fragment} */
7578
const p5 = {nodeName: '#document-fragment', childNodes: []}
76-
// @ts-ignore Assume correct children.
79+
// @ts-expect-error Assume correct children.
7780
p5.childNodes = all(node.children, p5, schema)
7881
return patch(node, p5)
7982
}
@@ -99,11 +102,15 @@ function doctype(node) {
99102
* @returns {P5Text}
100103
*/
101104
function text(node) {
102-
return patch(node, {
103-
nodeName: '#text',
104-
value: node.value,
105-
parentNode: undefined
106-
})
105+
return patch(
106+
node,
107+
// @ts-expect-error: no `parentNode`
108+
/** @type {P5Text} */ ({
109+
nodeName: '#text',
110+
value: node.value,
111+
parentNode: undefined
112+
})
113+
)
107114
}
108115

109116
/**
@@ -112,11 +119,15 @@ function text(node) {
112119
* @returns {P5Comment}
113120
*/
114121
function comment(node) {
115-
return patch(node, {
116-
nodeName: '#comment',
117-
data: node.value,
118-
parentNode: undefined
119-
})
122+
return patch(
123+
node,
124+
// @ts-expect-error: no `parentNode`
125+
/** @type {P5Comment} */ ({
126+
nodeName: '#comment',
127+
data: node.value,
128+
parentNode: undefined
129+
})
130+
)
120131
}
121132

122133
/**
@@ -126,7 +137,7 @@ function comment(node) {
126137
*/
127138
function element(node, schema) {
128139
/** @type {Space} */
129-
// @ts-ignore Assume space.
140+
// @ts-expect-error Assume space.
130141
const space = schema.space
131142
return toH(h, Object.assign({}, node, {children: []}), {space})
132143

@@ -167,7 +178,7 @@ function element(node, schema) {
167178
value.prefix = key.slice(0, index)
168179
}
169180

170-
value.namespace = webNamespaces[info.space]
181+
value.namespace = ns[info.space]
171182
}
172183

173184
values.push(value)
@@ -176,19 +187,24 @@ function element(node, schema) {
176187
if (schema.space === 'html' && node.tagName === 'svg') schema = svg
177188

178189
/** @type {P5Element} */
179-
const p5 = patch(node, {
180-
nodeName: name,
181-
tagName: name,
182-
attrs: values,
183-
namespaceURI: webNamespaces[schema.space],
184-
childNodes: [],
185-
parentNode: undefined
186-
})
187-
188-
// @ts-ignore Assume correct children.
190+
const p5 = patch(
191+
node,
192+
// @ts-expect-error: no `parentNode`
193+
/** @type {P5Element} */ ({
194+
nodeName: name,
195+
tagName: name,
196+
attrs: values,
197+
// @ts-expect-error: html and svg both have a space.
198+
namespaceURI: ns[schema.space],
199+
childNodes: [],
200+
parentNode: undefined
201+
})
202+
)
203+
204+
// @ts-expect-error Assume correct children.
189205
p5.childNodes = all(node.children, p5, schema)
190206

191-
// @ts-ignore Types are wrong.
207+
// @ts-expect-error Types are wrong.
192208
if (name === 'template') p5.content = fragment(node.content, schema)
193209

194210
return p5
@@ -209,10 +225,10 @@ function all(children, p5, schema) {
209225
if (children) {
210226
while (++index < children.length) {
211227
/** @type {P5Child} */
212-
// @ts-ignore Assume child.
228+
// @ts-expect-error Assume child.
213229
const child = one(children[index], schema)
214230

215-
// @ts-ignore types are wrong.
231+
// @ts-expect-error types are wrong.
216232
child.parentNode = p5
217233

218234
result.push(child)
@@ -234,7 +250,7 @@ function patch(node, p5) {
234250
const position = node.position
235251

236252
if (position && position.start && position.end) {
237-
// @ts-ignore Types are wrong.
253+
// @ts-expect-error Types are wrong.
238254
p5.sourceCodeLocation = {
239255
startLine: position.start.line,
240256
startCol: position.start.column,

test/comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test('comment', (t) => {
66
const actual = toParse5({type: 'comment', value: 'Alpha'})
77
const expected = parse5.parseFragment('<!--Alpha-->').childNodes[0]
88

9-
expected.parentNode = undefined
9+
Object.assign(expected, {parentNode: undefined})
1010

1111
t.deepEqual(actual, expected, 'should transform comments')
1212

test/doctype.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('doctype', (t) => {
1111
})
1212
const expected = parse5.parse('<!DOCTYPE html>').childNodes[0]
1313

14-
expected.parentNode = undefined
14+
Object.assign(expected, {parentNode: undefined})
1515

1616
st.deepEqual(actual, expected)
1717

@@ -22,7 +22,7 @@ test('doctype', (t) => {
2222
const actual = toParse5({type: 'doctype', name: 'html'})
2323
const expected = parse5.parse('<!doctypehtml>').childNodes[0]
2424

25-
expected.parentNode = undefined
25+
Object.assign(expected, {parentNode: undefined})
2626

2727
st.deepEqual(actual, expected)
2828

test/element.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('element', (t) => {
1212
})
1313
const expected = parse5.parseFragment('<h1>Alpha').childNodes[0]
1414

15-
delete expected.parentNode
15+
Object.assign(expected, {parentNode: undefined})
1616

1717
st.deepEqual(json(actual), json(expected))
1818

@@ -87,31 +87,31 @@ test('element', (t) => {
8787
].join('')
8888
).childNodes[0]
8989

90-
delete expected.parentNode
90+
Object.assign(expected, {parentNode: undefined})
9191

9292
st.deepEqual(json(actual), json(expected))
9393

9494
st.end()
9595
})
9696

9797
t.test('should transform void elements', (st) => {
98-
// @ts-ignore runtime.
98+
// @ts-expect-error runtime.
9999
const actual = toParse5({
100100
type: 'element',
101101
tagName: 'img',
102102
properties: {src: '#', alt: ''}
103103
})
104104
const expected = parse5.parseFragment('<img src=# alt="">').childNodes[0]
105105

106-
delete expected.parentNode
106+
Object.assign(expected, {parentNode: undefined})
107107

108108
st.deepEqual(json(actual), json(expected))
109109

110110
st.end()
111111
})
112112

113113
t.test('should transform templates with elements', (st) => {
114-
// @ts-ignore runtime.
114+
// @ts-expect-error runtime.
115115
const actual = toParse5({
116116
type: 'element',
117117
tagName: 'template',
@@ -124,15 +124,15 @@ test('element', (t) => {
124124
const expected = parse5.parseFragment('<template id="a">Alpha</template>')
125125
.childNodes[0]
126126

127-
delete expected.parentNode
127+
Object.assign(expected, {parentNode: undefined})
128128

129129
st.deepEqual(json(actual), json(expected))
130130

131131
st.end()
132132
})
133133

134134
t.test('should transform templates with text', (st) => {
135-
// @ts-ignore runtime.
135+
// @ts-expect-error runtime.
136136
const actual = toParse5({
137137
type: 'element',
138138
tagName: 'template',
@@ -159,7 +159,7 @@ test('element', (t) => {
159159
'<template id="b"><b>bold</b> and <i>italic</i></template>'
160160
).childNodes[0]
161161

162-
delete expected.parentNode
162+
Object.assign(expected, {parentNode: undefined})
163163

164164
st.deepEqual(json(actual), json(expected))
165165

test/position.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ test('position', (t) => {
2727
sourceCodeLocationInfo: true
2828
}).childNodes[0]
2929

30-
delete expected.parentNode
30+
Object.assign(expected, {parentNode: undefined})
3131

32-
// @ts-ignore Types are wrong.
32+
// @ts-expect-error Types are wrong.
3333
// Not possible yet to map this one.
3434
delete expected.sourceCodeLocation.startTag
3535

test/svg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test('svg', (t) => {
3939
].join('')
4040
).childNodes[0]
4141

42-
delete expected.parentNode
42+
Object.assign(expected, {parentNode: undefined})
4343

4444
st.deepEqual(json(actual), json(expected))
4545

@@ -58,7 +58,7 @@ test('svg', (t) => {
5858

5959
const expected = parse5.parseFragment(
6060
'<svg><circle cx="60" cy="60" r="50" fill="red"/></svg>'
61-
// @ts-ignore runtime.
61+
// @ts-expect-error runtime.
6262
).childNodes[0].childNodes[0]
6363

6464
delete expected.parentNode

test/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {toParse5} from '../index.js'
55
test('text', (t) => {
66
const expected = parse5.parseFragment('Alpha').childNodes[0]
77

8-
expected.parentNode = undefined
8+
Object.assign(expected, {parentNode: undefined})
99

1010
t.deepEqual(
1111
toParse5({type: 'text', value: 'Alpha'}),

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)