Skip to content

Commit a662be1

Browse files
wooormremcohaszing
andcommitted
Fix types of classic, automatic runtime
Co-authored-by: Remco Haszing <[email protected]>
1 parent 9b5ebe5 commit a662be1

27 files changed

+422
-37
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.DS_Store
2-
*.d.ts
32
*.log
43
coverage/
54
node_modules/
65
test/jsx-*.js
76
yarn.lock
7+
**/*.d.ts
8+
!lib/jsx-classic.d.ts
9+
!lib/jsx-automatic.d.ts

html.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @typedef {import('./lib/index.js').Child} Child Acceptable child value
3+
* @typedef {import('./lib/index.js').Properties} Properties Acceptable properties value.
4+
*/
5+
6+
export {h} from './lib/html.js'

html/jsx-runtime.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @typedef {import('../lib/runtime.js').JSXProps}} JSXProps
3+
*/
4+
5+
export * from '../lib/runtime-html.js'

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
/**
2+
* @typedef {import('./lib/index.js').Child} Child Acceptable child value
3+
* @typedef {import('./lib/index.js').Properties} Properties Acceptable properties value.
4+
*/
5+
16
export {h, s} from './lib/index.js'

jsx-runtime.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @typedef {import('./lib/runtime.js').JSXProps}} JSXProps
3+
*/
4+
5+
export * from './lib/runtime-html.js'

lib/core.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/**
2-
* @typedef {import('hast').Root} HastRoot
3-
* @typedef {import('hast').Element} HastElement
2+
* @typedef {import('hast').Root} Root
3+
* @typedef {import('hast').Element} Element
44
* @typedef {import('hast').Properties} Properties
5-
* @typedef {HastRoot['children'][number]} HastChild
6-
* @typedef {import('property-information').html['property'][string]} Info
7-
* @typedef {typeof import('property-information').html} Schema
8-
*/
9-
10-
/**
11-
* @typedef {HastRoot|HastElement} HResult
5+
* @typedef {Root['children'][number]} Child
6+
* @typedef {Child|Root} Node
7+
* @typedef {import('property-information').Info} Info
8+
* @typedef {import('property-information').Schema} Schema
9+
*
10+
* @typedef {Root|Element} HResult
1211
* @typedef {string|number} HStyleValue
1312
* @typedef {Object.<string, HStyleValue>} HStyle
1413
* @typedef {string|number|boolean|null|undefined} HPrimitiveValue
@@ -17,9 +16,8 @@
1716
* @typedef {{[property: string]: HPropertyValue|HStyle}} HProperties
1817
*
1918
* @typedef {string|number|null|undefined} HPrimitiveChild
20-
* @typedef {HastChild|HastRoot} HNodeChild
21-
* @typedef {Array.<HPrimitiveChild|HNodeChild>} HArrayChild
22-
* @typedef {HPrimitiveChild|HNodeChild|HArrayChild} HChild
19+
* @typedef {Array.<Node|HPrimitiveChild>} HArrayChild
20+
* @typedef {Node|HPrimitiveChild|HArrayChild} HChild
2321
*/
2422

2523
import {find, normalize} from 'property-information'
@@ -42,10 +40,10 @@ export function core(schema, defaultTagName, caseSensitive) {
4240
const h =
4341
/**
4442
* @type {{
45-
* (): HastRoot
46-
* (selector: null|undefined, ...children: HChild[]): HastRoot
47-
* (selector: string, properties: HProperties, ...children: HChild[]): HastElement
48-
* (selector: string, ...children: HChild[]): HastElement
43+
* (): Root
44+
* (selector: null|undefined, ...children: HChild[]): Root
45+
* (selector: string, properties: HProperties, ...children: HChild[]): Element
46+
* (selector: string, ...children: HChild[]): Element
4947
* }}
5048
*/
5149
(
@@ -59,7 +57,7 @@ export function core(schema, defaultTagName, caseSensitive) {
5957
*/
6058
function (selector, properties, ...children) {
6159
var index = -1
62-
/** @type {HResult|HastElement} */
60+
/** @type {HResult} */
6361
var node
6462
/** @type {string} */
6563
var key
@@ -202,7 +200,7 @@ function addProperty(schema, properties, key, value) {
202200
}
203201

204202
/**
205-
* @param {Array.<HastChild>} nodes
203+
* @param {Array.<Child>} nodes
206204
* @param {HChild} value
207205
* @returns {void}
208206
*/

lib/html.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* @typedef {import('./core.js').HChild} Child Acceptable child value
3+
* @typedef {import('./core.js').HProperties} Properties Acceptable properties value.
4+
*
5+
* @typedef {import('./jsx-classic').Element} h.JSX.Element
6+
* @typedef {import('./jsx-classic').IntrinsicAttributes} h.JSX.IntrinsicAttributes
7+
* @typedef {import('./jsx-classic').IntrinsicElements} h.JSX.IntrinsicElements
8+
* @typedef {import('./jsx-classic').ElementChildrenAttribute} h.JSX.ElementChildrenAttribute
9+
*/
10+
111
import {html} from 'property-information'
212
import {core} from './core.js'
313

lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
/**
2+
* @typedef {import('./core.js').HChild} Child Acceptable child value
3+
* @typedef {import('./core.js').HProperties} Properties Acceptable properties value.
4+
*/
5+
16
export {h} from './html.js'
27
export {s} from './svg.js'

lib/jsx-automatic.d.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {HProperties, HChild, HResult} from './core.js'
2+
3+
export namespace JSX {
4+
/**
5+
* This defines the return value of JSX syntax.
6+
*/
7+
type Element = HResult
8+
9+
/**
10+
* This disallows the use of functional components.
11+
*/
12+
type IntrinsicAttributes = never
13+
14+
/**
15+
* This defines the prop types for known elements.
16+
*
17+
* For `hastscript` this defines any string may be used in combination with `hast` `Properties`.
18+
*
19+
* This **must** be an interface.
20+
*/
21+
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
22+
interface IntrinsicElements {
23+
[name: string]:
24+
| HProperties
25+
| {
26+
/**
27+
* The prop that matches `ElementChildrenAttribute` key defines the type of JSX children, defines the children type.
28+
*/
29+
children?: HChild
30+
}
31+
}
32+
33+
/**
34+
* The key of this interface defines as what prop children are passed.
35+
*/
36+
interface ElementChildrenAttribute {
37+
/**
38+
* Only the key matters, not the value.
39+
*/
40+
children?: never
41+
}
42+
}

lib/jsx-automatic.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Empty (only used for TypeScript).
2+
export {}

0 commit comments

Comments
 (0)