Skip to content

Commit 37bd298

Browse files
committed
Update tsconfig.json
1 parent aa617b4 commit 37bd298

File tree

7 files changed

+50
-46
lines changed

7 files changed

+50
-46
lines changed

Diff for: lib/index.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {one} from './tree.js'
1515
* @param {Options} [options]
1616
* @returns {string}
1717
*/
18+
// eslint-disable-next-line complexity
1819
export function toHtml(node, options = {}) {
1920
const quote = options.quote || '"'
2021
/** @type {Quote} */
@@ -32,20 +33,20 @@ export function toHtml(node, options = {}) {
3233
omit: options.omitOptionalTags ? omission : undefined,
3334
quote,
3435
alternative,
35-
smart: options.quoteSmart,
36-
unquoted: options.preferUnquoted,
37-
tight: options.tightAttributes,
38-
upperDoctype: options.upperDoctype,
39-
tightDoctype: options.tightDoctype,
40-
bogusComments: options.bogusComments,
41-
tightLists: options.tightCommaSeparatedLists,
42-
tightClose: options.tightSelfClosing,
43-
collapseEmpty: options.collapseEmptyAttributes,
44-
dangerous: options.allowDangerousHtml,
36+
smart: options.quoteSmart || false,
37+
unquoted: options.preferUnquoted || false,
38+
tight: options.tightAttributes || false,
39+
upperDoctype: options.upperDoctype || false,
40+
tightDoctype: options.tightDoctype || false,
41+
bogusComments: options.bogusComments || false,
42+
tightLists: options.tightCommaSeparatedLists || false,
43+
tightClose: options.tightSelfClosing || false,
44+
collapseEmpty: options.collapseEmptyAttributes || false,
45+
dangerous: options.allowDangerousHtml || false,
4546
voids: options.voids || htmlVoidElements.concat(),
4647
entities: options.entities || {},
47-
close: options.closeSelfClosing,
48-
closeEmpty: options.closeEmptyElements
48+
close: options.closeSelfClosing || false,
49+
closeEmpty: options.closeEmptyElements || false
4950
}
5051

5152
return one(

Diff for: lib/omission/opening.js

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function colgroup(node, index, parent) {
8282

8383
// Previous colgroup was already omitted.
8484
if (
85+
parent &&
8586
isElement(previous, 'colgroup') &&
8687
closing(previous, parent.children.indexOf(previous), parent)
8788
) {
@@ -102,6 +103,7 @@ function tbody(node, index, parent) {
102103

103104
// Previous table section was already omitted.
104105
if (
106+
parent &&
105107
isElement(previous, ['thead', 'tbody']) &&
106108
closing(previous, parent.children.indexOf(previous), parent)
107109
) {

Diff for: lib/omission/util/siblings.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ function siblings(increment) {
1919
/**
2020
* Find applicable siblings in a direction.
2121
*
22-
* @param {Parent} parent
23-
* @param {number} index
24-
* @param {boolean} [includeWhitespace=false]
22+
* @param {Parent | null | undefined} parent
23+
* @param {number | null | undefined} index
24+
* @param {boolean | null | undefined} [includeWhitespace=false]
2525
* @returns {Child}
2626
*/
2727
function sibling(parent, index, includeWhitespace) {
28-
const siblings = parent && parent.children
29-
let offset = index + increment
28+
const siblings = parent ? parent.children : []
29+
let offset = (index || 0) + increment
3030
let next = siblings && siblings[offset]
3131

3232
if (!includeWhitespace) {

Diff for: lib/tree.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function one(ctx, node, index, parent) {
5151
* Serialize all children of `parent`.
5252
*
5353
* @param {Context} ctx
54-
* @param {Parent} parent
54+
* @param {Parent | null | undefined} parent
5555
* @returns {string}
5656
*/
5757
export function all(ctx, parent) {
@@ -133,7 +133,7 @@ export function element(ctx, node, index, parent) {
133133

134134
/**
135135
* @param {Context} ctx
136-
* @param {Properties} props
136+
* @param {Properties | undefined} props
137137
* @returns {string}
138138
*/
139139
function serializeAttributes(ctx, props) {
@@ -142,20 +142,20 @@ function serializeAttributes(ctx, props) {
142142
let index = -1
143143
/** @type {string} */
144144
let key
145-
/** @type {string} */
146-
let value
147-
/** @type {string} */
148-
let last
149145

150-
for (key in props) {
151-
if (props[key] !== undefined && props[key] !== null) {
152-
value = serializeAttribute(ctx, key, props[key])
153-
if (value) values.push(value)
146+
if (props) {
147+
for (key in props) {
148+
if (props[key] !== undefined && props[key] !== null) {
149+
const value = serializeAttribute(ctx, key, props[key])
150+
if (value) values.push(value)
151+
}
154152
}
155153
}
156154

157155
while (++index < values.length) {
158-
last = ctx.tight ? values[index].charAt(values[index].length - 1) : null
156+
const last = ctx.tight
157+
? values[index].charAt(values[index].length - 1)
158+
: null
159159

160160
// In tight mode, don’t add a space after quoted attributes.
161161
if (index !== values.length - 1 && last !== '"' && last !== "'") {
@@ -176,7 +176,7 @@ function serializeAttributes(ctx, props) {
176176
function serializeAttribute(ctx, key, value) {
177177
const info = find(ctx.schema, key)
178178
let quote = ctx.quote
179-
/** @type {string} */
179+
/** @type {string | undefined} */
180180
let result
181181

182182
if (info.overloadedBoolean && (value === info.attribute || value === '')) {

Diff for: lib/types.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
* @callback Handle
1818
* @param {Context} context
1919
* @param {Node} node
20-
* @param {number|null} index
21-
* @param {Parent|null} parent
20+
* @param {number | null} index
21+
* @param {Parent | undefined | null} parent
2222
* @returns {string}
2323
*
2424
* @callback OmitHandle
2525
* @param {Element} node
26-
* @param {number|null} index
27-
* @param {Parent|null} parent
26+
* @param {number | null | undefined} index
27+
* @param {Parent | null | undefined} parent
2828
* @returns {boolean}
2929
*
30-
* @typedef {{opening?: OmitHandle, closing?: OmitHandle}} Omission
30+
* @typedef {{opening: OmitHandle, closing: OmitHandle}} Omission
3131
*
3232
* @typedef {'html'|'svg'} Space
3333
* @typedef {'"'|"'"} Quote
@@ -57,7 +57,7 @@
5757
* @property {number} valid
5858
* @property {number} safe
5959
* @property {Schema} schema
60-
* @property {Omission} omit
60+
* @property {Omission | undefined} omit
6161
* @property {Quote} quote
6262
* @property {Quote} alternative
6363
* @property {boolean} smart

Diff for: package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"prettier": "^2.0.0",
5353
"remark-cli": "^11.0.0",
5454
"remark-preset-wooorm": "^9.0.0",
55-
"rimraf": "^3.0.0",
5655
"tape": "^5.0.0",
5756
"type-coverage": "^2.0.0",
5857
"typescript": "^4.0.0",
@@ -61,9 +60,9 @@
6160
},
6261
"scripts": {
6362
"prepack": "npm run build && npm run format",
64-
"build": "rimraf \"{lib,test}/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
63+
"build": "tsc --build --clean && tsc --build && type-coverage",
6564
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
66-
"test-api": "node test/index.js",
65+
"test-api": "node --conditions development test/index.js",
6766
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
6867
"test": "npm run build && npm run format && npm run test-coverage"
6968
},

Diff for: tsconfig.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"include": ["*.js", "lib/**/*.js", "test/**/*.js"],
2+
"include": ["**/**.js"],
3+
"exclude": ["coverage/", "node_modules/"],
34
"compilerOptions": {
4-
"target": "ES2020",
5-
"lib": ["ES2020"],
6-
"module": "ES2020",
7-
"moduleResolution": "node",
8-
"allowJs": true,
95
"checkJs": true,
106
"declaration": true,
117
"emitDeclarationOnly": true,
12-
"allowSyntheticDefaultImports": true,
13-
"skipLibCheck": true
8+
"exactOptionalPropertyTypes": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"lib": ["es2020"],
11+
"module": "node16",
12+
"newLine": "lf",
13+
"skipLibCheck": true,
14+
"strict": true,
15+
"target": "es2020"
1416
}
1517
}

0 commit comments

Comments
 (0)