Skip to content

Commit 2dcd77e

Browse files
committed
Update dev-dependencies
1 parent f212eaf commit 2dcd77e

9 files changed

Lines changed: 192 additions & 83 deletions

‎lib/automatic-runtime-html.d.ts‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/naming-convention */
1+
/* eslint-disable @typescript-eslint/naming-convention -- names are defined by JSX. */
22

33
import type {Element, Root} from 'hast'
44
import type {Child} from './create-h.js'
@@ -9,28 +9,16 @@ export * from './jsx-automatic.js'
99
export const Fragment: null
1010

1111
export const jsxDEV: {
12-
(
13-
type: null,
14-
properties: {children?: Child},
15-
key?: string | null | undefined
16-
): Root
17-
(type: string, properties: JSXProps, key?: string | null | undefined): Element
12+
(type: null, properties: {children?: Child}, key?: string | null): Root
13+
(type: string, properties: JSXProps, key?: string | null): Element
1814
}
1915

2016
export const jsxs: {
21-
(
22-
type: null,
23-
properties: {children?: Child},
24-
key?: string | null | undefined
25-
): Root
26-
(type: string, properties: JSXProps, key?: string | null | undefined): Element
17+
(type: null, properties: {children?: Child}, key?: string | null): Root
18+
(type: string, properties: JSXProps, key?: string | null): Element
2719
}
2820

2921
export const jsx: {
30-
(
31-
type: null,
32-
properties: {children?: Child},
33-
key?: string | null | undefined
34-
): Root
35-
(type: string, properties: JSXProps, key?: string | null | undefined): Element
22+
(type: null, properties: {children?: Child}, key?: string | null): Root
23+
(type: string, properties: JSXProps, key?: string | null): Element
3624
}

‎lib/automatic-runtime-svg.d.ts‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/naming-convention */
1+
/* eslint-disable @typescript-eslint/naming-convention -- names are defined by JSX. */
22

33
import type {Element, Root} from 'hast'
44
import type {Child} from './create-h.js'
@@ -9,28 +9,16 @@ export * from './jsx-automatic.js'
99
export const Fragment: null
1010

1111
export const jsxDEV: {
12-
(
13-
type: null,
14-
properties: {children?: Child},
15-
key?: string | null | undefined
16-
): Root
17-
(type: string, properties: JSXProps, key?: string | null | undefined): Element
12+
(type: null, properties: {children?: Child}, key?: string | null): Root
13+
(type: string, properties: JSXProps, key?: string | null): Element
1814
}
1915

2016
export const jsxs: {
21-
(
22-
type: null,
23-
properties: {children?: Child},
24-
key?: string | null | undefined
25-
): Root
26-
(type: string, properties: JSXProps, key?: string | null | undefined): Element
17+
(type: null, properties: {children?: Child}, key?: string | null): Root
18+
(type: string, properties: JSXProps, key?: string | null): Element
2719
}
2820

2921
export const jsx: {
30-
(
31-
type: null,
32-
properties: {children?: Child},
33-
key?: string | null | undefined
34-
): Root
35-
(type: string, properties: JSXProps, key?: string | null | undefined): Element
22+
(type: null, properties: {children?: Child}, key?: string | null): Root
23+
(type: string, properties: JSXProps, key?: string | null): Element
3624
}

‎lib/create-automatic-runtime.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@
2020
*/
2121
export function createAutomaticRuntime(f) {
2222
/**
23+
* Create a root or an element.
24+
*
2325
* @overload
2426
* @param {null} type
27+
* `null` to get a root.
2528
* @param {{children?: Child}} properties
29+
* Properties with children.
2630
* @param {string | null | undefined} [key]
31+
* Key (ignored).
2732
* @returns {Root}
33+
* Root.
2834
*
2935
* @overload
3036
* @param {string} type
37+
* Element name.
3138
* @param {JSXProps} properties
39+
* Properties with children.
3240
* @param {string | null | undefined} [key]
41+
* Key (ignored).
3342
* @returns {Element}
43+
* Element.
3444
*
3545
* @param {string | null} type
3646
* Element name or `null` to get a root.

‎lib/create-h.js‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ import {find, normalize} from 'property-information'
6464
import {parse as parseSpaces} from 'space-separated-tokens'
6565

6666
/**
67+
* Create an `h` function.
68+
*
6769
* @param {Schema} schema
6870
* Schema to use.
6971
* @param {string} defaultTagName
@@ -81,19 +83,29 @@ export function createH(schema, defaultTagName, caseSensitive) {
8183
*
8284
* @overload
8385
* @param {null | undefined} [selector]
86+
* Nothing to get a root.
8487
* @param {...Child} children
88+
* Children.
8589
* @returns {Root}
90+
* Root.
8691
*
8792
* @overload
8893
* @param {string} selector
94+
* Selector.
8995
* @param {Properties} properties
96+
* Properties.
9097
* @param {...Child} children
98+
* Children.
9199
* @returns {Element}
100+
* Element.
92101
*
93102
* @overload
94103
* @param {string} selector
104+
* Selector.
95105
* @param {...Child} children
106+
* Children.
96107
* @returns {Element}
108+
* Element.
97109
*
98110
* @param {string | null | undefined} [selector]
99111
* Selector.
@@ -196,6 +208,8 @@ function isChild(value) {
196208
}
197209

198210
/**
211+
* Add a property.
212+
*
199213
* @param {Schema} schema
200214
* Schema.
201215
* @param {Properties} properties
@@ -208,13 +222,13 @@ function isChild(value) {
208222
* Nothing.
209223
*/
210224
function addProperty(schema, properties, key, value) {
225+
// Ignore nullish and NaN values.
226+
if (value === null || value === undefined) return
227+
211228
const info = find(schema, key)
212229
/** @type {PropertyValue} */
213230
let result
214231

215-
// Ignore nullish and NaN values.
216-
if (value === null || value === undefined) return
217-
218232
if (typeof value === 'number') {
219233
// Ignore NaN.
220234
if (Number.isNaN(value)) return
@@ -261,15 +275,16 @@ function addProperty(schema, properties, key, value) {
261275
// Class names (which can be added both on the `selector` and here).
262276
if (info.property === 'className' && Array.isArray(properties.className)) {
263277
// Assume no booleans in `className`.
264-
result = properties.className.concat(
265-
/** @type {Array<number | string> | number | string} */ (result)
266-
)
278+
const add = /** @type {Array<number | string> | number | string} */ (result)
279+
result = [...properties.className, ...(Array.isArray(add) ? add : [add])]
267280
}
268281

269282
properties[info.property] = result
270283
}
271284

272285
/**
286+
* Add a child.
287+
*
273288
* @param {Array<RootContent>} nodes
274289
* Children.
275290
* @param {Child} value

‎package.json‎

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
"space-separated-tokens": "^2.0.0"
1313
},
1414
"description": "hast utility to create trees",
15-
"devDependencies#": "note: some bug with `typescript` 5.5 being broken",
1615
"devDependencies": {
17-
"@types/node": "^22.0.0",
16+
"@types/node": "^26.0.0",
1817
"acorn-jsx": "^5.0.0",
19-
"c8": "^10.0.0",
18+
"c8": "^12.0.0",
2019
"esast-util-from-js": "^2.0.0",
2120
"estree-util-build-jsx": "^3.0.0",
2221
"estree-util-to-js": "^2.0.0",
2322
"prettier": "^3.0.0",
2423
"remark-cli": "^12.0.0",
2524
"remark-preset-wooorm": "^11.0.0",
2625
"svg-tag-names": "^3.0.0",
27-
"tsd": "^0.31.0",
26+
"tsd": "^0.33.0",
2827
"type-coverage": "^2.0.0",
29-
"typescript": "^5.0.0",
30-
"xo": "^0.60.0"
28+
"typescript": "^6.0.0",
29+
"xo": "^5.0.0"
3130
},
3231
"exports": {
3332
"./jsx-dev-runtime": "./lib/automatic-runtime-html.js",
@@ -94,33 +93,5 @@
9493
"strict": true
9594
},
9695
"type": "module",
97-
"version": "9.0.1",
98-
"xo": {
99-
"overrides": [
100-
{
101-
"files": [
102-
"**/*.ts"
103-
],
104-
"rules": {
105-
"@typescript-eslint/array-type": [
106-
"error",
107-
{
108-
"default": "generic"
109-
}
110-
],
111-
"@typescript-eslint/ban-types": [
112-
"error",
113-
{
114-
"extendDefaults": true
115-
}
116-
],
117-
"@typescript-eslint/consistent-type-definitions": [
118-
"error",
119-
"interface"
120-
]
121-
}
122-
}
123-
],
124-
"prettier": true
125-
}
96+
"version": "9.0.1"
12697
}

‎test/core.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ test('property values (unknown)', async function (t) {
477477
await t.test(
478478
'should ignore properties with a value of `NaN`',
479479
async function () {
480-
assert.deepEqual(h('', {foo: Number.NaN}), {
480+
assert.deepEqual(h('', {foo: NaN}), {
481481
type: 'element',
482482
tagName: 'div',
483483
properties: {},
@@ -605,6 +605,18 @@ test('list properties', async function (t) {
605605
}
606606
)
607607

608+
await t.test(
609+
'should add a number `className` to classes from the selector',
610+
async function () {
611+
assert.deepEqual(h('.foo', {className: 1}), {
612+
type: 'element',
613+
tagName: 'div',
614+
properties: {className: ['foo', 1]},
615+
children: []
616+
})
617+
}
618+
)
619+
608620
await t.test(
609621
'should cast know comma-separated `array` values',
610622
async function () {

‎test/index.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* eslint-disable import/no-unassigned-import */
1+
/* eslint-disable import-x/no-unassigned-import, node-test/no-import-test-files -- these files register tests. */
22
import './core.js'
33
import './jsx-build-jsx-classic.js'
44
import './jsx-build-jsx-automatic.js'
55
import './jsx-build-jsx-automatic-development.js'
6-
/* eslint-enable import/no-unassigned-import */

‎tsconfig.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
"lib": ["es2022"],
1111
"module": "node16",
1212
"strict": true,
13-
"target": "es2022"
13+
"target": "es2022",
14+
"types": ["node"]
1415
},
1516
"exclude": ["coverage/", "node_modules/"],
1617
"include": [
1718
"**/**.js",
1819
"**/**.jsx",
20+
"test-d/**/*.ts",
21+
"test-d/**/*.tsx",
1922
"lib/automatic-runtime-html.d.ts",
2023
"lib/automatic-runtime-svg.d.ts",
2124
"lib/jsx-automatic.d.ts",

0 commit comments

Comments
 (0)