Skip to content

Commit 9551cf0

Browse files
committed
Add more docs to types
1 parent e20d4b4 commit 9551cf0

File tree

5 files changed

+58
-25
lines changed

5 files changed

+58
-25
lines changed

Diff for: lib/core.js

+40-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
/**
22
* @typedef {import('hast').Root} Root
3+
* @typedef {import('hast').Content} Content
34
* @typedef {import('hast').Element} Element
45
* @typedef {import('hast').Properties} Properties
5-
* @typedef {Root['children'][number]} Child
6-
* @typedef {Child|Root} Node
76
* @typedef {import('property-information').Info} Info
87
* @typedef {import('property-information').Schema} Schema
8+
*/
9+
10+
/**
11+
* @typedef {Content | Root} Node
12+
* Any concrete `hast` node.
13+
* @typedef {Root | Element} HResult
14+
* Result from a `h` (or `s`) call.
915
*
10-
* @typedef {Root|Element} HResult
11-
* @typedef {string|number} HStyleValue
16+
* @typedef {string | number} HStyleValue
17+
* Value for a CSS style field.
1218
* @typedef {Record<string, HStyleValue>} HStyle
13-
* @typedef {string|number|boolean|null|undefined} HPrimitiveValue
14-
* @typedef {Array<string|number>} HArrayValue
15-
* @typedef {HPrimitiveValue|HArrayValue} HPropertyValue
16-
* @typedef {{[property: string]: HPropertyValue|HStyle}} HProperties
17-
* Acceptable properties value.
19+
* Supported value of a `style` prop.
20+
* @typedef {string | number | boolean | null | undefined} HPrimitiveValue
21+
* Primitive property value.
22+
* @typedef {Array<string | number>} HArrayValue
23+
* List of property values for space- or comma separated values (such as `className`).
24+
* @typedef {HPrimitiveValue | HArrayValue} HPropertyValue
25+
* Primitive value or list value.
26+
* @typedef {{[property: string]: HPropertyValue | HStyle}} HProperties
27+
* Acceptable value for element properties.
1828
*
19-
* @typedef {string|number|null|undefined} HPrimitiveChild
20-
* @typedef {Array<Node|HPrimitiveChild>} HArrayChild
21-
* @typedef {Node|HPrimitiveChild|HArrayChild} HChild
22-
* Acceptable child value
29+
* @typedef {string | number | null | undefined} HPrimitiveChild
30+
* Primitive children, either ignored (nullish), or turned into text nodes.
31+
* @typedef {Array<Node | HPrimitiveChild>} HArrayChild
32+
* List of children.
33+
* @typedef {Node | HPrimitiveChild | HArrayChild} HChild
34+
* Acceptable child value.
2335
*/
2436

2537
import {find, normalize} from 'property-information'
@@ -43,7 +55,7 @@ export function core(schema, defaultTagName, caseSensitive) {
4355
/**
4456
* @type {{
4557
* (): Root
46-
* (selector: null|undefined, ...children: Array<HChild>): Root
58+
* (selector: null | undefined, ...children: Array<HChild>): Root
4759
* (selector: string, properties?: HProperties, ...children: Array<HChild>): Element
4860
* (selector: string, ...children: Array<HChild>): Element
4961
* }}
@@ -52,8 +64,8 @@ export function core(schema, defaultTagName, caseSensitive) {
5264
/**
5365
* Hyperscript compatible DSL for creating virtual hast trees.
5466
*
55-
* @param {string|null} [selector]
56-
* @param {HProperties|HChild} [properties]
67+
* @param {string | null} [selector]
68+
* @param {HProperties | HChild} [properties]
5769
* @param {Array<HChild>} children
5870
* @returns {HResult}
5971
*/
@@ -108,7 +120,7 @@ export function core(schema, defaultTagName, caseSensitive) {
108120
}
109121

110122
/**
111-
* @param {HProperties|HChild} value
123+
* @param {HProperties | HChild} value
112124
* @param {string} name
113125
* @returns {value is HProperties}
114126
*/
@@ -141,7 +153,7 @@ function isProperties(value, name) {
141153
* @param {Schema} schema
142154
* @param {Properties} properties
143155
* @param {string} key
144-
* @param {HStyle|HPropertyValue} value
156+
* @param {HStyle | HPropertyValue} value
145157
* @returns {void}
146158
*/
147159
function addProperty(schema, properties, key, value) {
@@ -181,7 +193,7 @@ function addProperty(schema, properties, key, value) {
181193
}
182194

183195
if (Array.isArray(result)) {
184-
/** @type {Array<string|number>} */
196+
/** @type {Array<string | number>} */
185197
const finalResult = []
186198

187199
while (++index < result.length) {
@@ -202,7 +214,7 @@ function addProperty(schema, properties, key, value) {
202214
}
203215

204216
/**
205-
* @param {Array<Child>} nodes
217+
* @param {Array<Content>} nodes
206218
* @param {HChild} value
207219
* @returns {void}
208220
*/
@@ -254,8 +266,12 @@ function parsePrimitive(info, name, value) {
254266
}
255267

256268
/**
269+
* Serialize a `style` object as a string.
270+
*
257271
* @param {HStyle} value
272+
* Style object.
258273
* @returns {string}
274+
* CSS string.
259275
*/
260276
function style(value) {
261277
/** @type {Array<string>} */
@@ -273,8 +289,12 @@ function style(value) {
273289
}
274290

275291
/**
292+
* Create a map to adjust casing.
293+
*
276294
* @param {Array<string>} values
295+
* List of properly cased keys.
277296
* @returns {Record<string, string>}
297+
* Map of lowercase keys to uppercase keys.
278298
*/
279299
function createAdjustMap(values) {
280300
/** @type {Record<string, string>} */

Diff for: lib/html.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
2-
* @typedef {import('./core.js').HChild} Child Acceptable child value
3-
* @typedef {import('./core.js').HProperties} Properties Acceptable properties value.
2+
* @typedef {import('./core.js').HChild} Child
3+
* Acceptable child value.
4+
* @typedef {import('./core.js').HProperties} Properties
5+
* Acceptable value for element properties.
6+
* @typedef {import('./core.js').HResult} Result
7+
* Result from a `h` (or `s`) call.
48
*
59
* @typedef {import('./jsx-classic.js').Element} h.JSX.Element
610
* @typedef {import('./jsx-classic.js').IntrinsicAttributes} h.JSX.IntrinsicAttributes

Diff for: lib/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/**
22
* @typedef {import('./core.js').HChild} Child
3+
* Acceptable child value.
34
* @typedef {import('./core.js').HProperties} Properties
5+
* Acceptable value for element properties.
46
* @typedef {import('./core.js').HResult} Result
7+
* Result from a `h` (or `s`) call.
58
*/
69

710
export {h} from './html.js'

Diff for: lib/runtime.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@
88
* @typedef {import('./core.js').HStyle} HStyle
99
* @typedef {import('./core.js').core} Core
1010
*
11-
* @typedef {Record<string, HPropertyValue|HStyle|HChild>} JSXProps
11+
* @typedef {Record<string, HPropertyValue | HStyle | HChild>} JSXProps
1212
*/
1313

1414
/**
15+
* Create an automatic runtime.
16+
*
1517
* @param {ReturnType<Core>} f
1618
*/
1719
export function runtime(f) {
1820
const jsx =
1921
/**
2022
* @type {{
21-
* (type: null|undefined, props: {children?: HChild}, key?: string): Root
23+
* (type: null | undefined, props: {children?: HChild}, key?: string): Root
2224
* (type: string, props: JSXProps, key?: string): Element
2325
* }}
2426
*/
2527
(
2628
/**
27-
* @param {string|null} type
29+
* @param {string | null} type
2830
* @param {HProperties & {children?: HChild}} props
2931
* @returns {HResult}
3032
*/

Diff for: lib/svg.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
22
* @typedef {import('./core.js').HChild} Child
3+
* Acceptable child value.
34
* @typedef {import('./core.js').HProperties} Properties
5+
* Acceptable value for element properties.
6+
* @typedef {import('./core.js').HResult} Result
7+
* Result from a `h` (or `s`) call.
48
*
59
* @typedef {import('./jsx-classic.js').Element} s.JSX.Element
610
* @typedef {import('./jsx-classic.js').IntrinsicAttributes} s.JSX.IntrinsicAttributes

0 commit comments

Comments
 (0)