Skip to content

Commit 31ab7f7

Browse files
committed
Update tsconfig.json
1 parent 27917c4 commit 31ab7f7

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @typedef {import('./lib/index.js').XChild}} Child
2+
* @typedef {import('./lib/index.js').XChild} Child
33
* Acceptable child value
4-
* @typedef {import('./lib/index.js').XAttributes}} Attributes
4+
* @typedef {import('./lib/index.js').XAttributes} Attributes
55
* Acceptable attributes value.
66
*/
77

jsx-dev-runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export {Fragment} from './jsx-runtime.js'
1313
export const jsxDEV =
1414
/**
1515
* @type {{
16-
* (name: null|undefined, props: {children?: XChild}, ...unused: unknown[]): Root
16+
* (name: null | undefined, props: {children?: XChild}, ...unused: unknown[]): Root
1717
* (name: string, props: JSXProps, ...unused: unknown[]): Element
1818
* }}
1919
*/

lib/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
/**
22
* @typedef {import('xast').Root} Root
33
* @typedef {import('xast').Element} Element
4+
*/
5+
6+
/**
47
* @typedef {Root['children'][number]} Child
5-
* @typedef {Child|Root} Node
6-
* @typedef {Root|Element} XResult
7-
* @typedef {string|number|boolean|null|undefined} XValue
8+
* @typedef {Child | Root} Node
9+
* @typedef {Root | Element} XResult
10+
* @typedef {string | number | boolean | null | undefined} XValue
811
* @typedef {{[attribute: string]: XValue}} XAttributes Attributes to support JS primitive types
912
*
10-
* @typedef {string|number|null|undefined} XPrimitiveChild
11-
* @typedef {Array<Node|XPrimitiveChild>} XArrayChild
12-
* @typedef {Node|XPrimitiveChild|XArrayChild} XChild
13+
* @typedef {string | number | null | undefined} XPrimitiveChild
14+
* @typedef {Array<Node | XPrimitiveChild>} XArrayChild
15+
* @typedef {Node | XPrimitiveChild | XArrayChild} XChild
1316
* @typedef {import('./jsx-classic.js').Element} x.JSX.Element
1417
* @typedef {import('./jsx-classic.js').IntrinsicAttributes} x.JSX.IntrinsicAttributes
1518
* @typedef {import('./jsx-classic.js').IntrinsicElements} x.JSX.IntrinsicElements
@@ -19,15 +22,15 @@
1922
/**
2023
* Create XML trees in xast.
2124
*
22-
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as `rdf:RDF`). Pass `null|undefined` to build a root.
25+
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as `rdf:RDF`). Pass `null | undefined` to build a root.
2326
* @param attributes Map of attributes. Nullish (null or undefined) or NaN values are ignored, other values (strings, booleans) are cast to strings.
2427
* @param children (Lists of) child nodes. When strings are encountered, they are mapped to Text nodes.
2528
*/
2629
export const x =
2730
/**
2831
* @type {{
2932
* (): Root
30-
* (name: null|undefined, ...children: Array<XChild>): Root
33+
* (name: null | undefined, ...children: Array<XChild>): Root
3134
* (name: string, attributes: XAttributes, ...children: Array<XChild>): Element
3235
* (name: string, ...children: Array<XChild>): Element
3336
* }}
@@ -36,8 +39,8 @@ export const x =
3639
/**
3740
* Hyperscript compatible DSL for creating virtual xast trees.
3841
*
39-
* @param {string|null} [name]
40-
* @param {XAttributes|XChild} [attributes]
42+
* @param {string | null} [name]
43+
* @param {XAttributes | XChild} [attributes]
4144
* @param {Array<XChild>} children
4245
* @returns {XResult}
4346
*/
@@ -112,7 +115,7 @@ function addChild(nodes, value) {
112115
}
113116

114117
/**
115-
* @param {XAttributes|XChild} value
118+
* @param {XAttributes | XChild} value
116119
* @returns {value is XAttributes}
117120
*/
118121
function isAttributes(value) {

lib/runtime.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @typedef {import('./index.js').XAttributes} XAttributes
77
* @typedef {import('./index.js').XValue} XValue
88
*
9-
* @typedef {{[x: string]: XValue|XChild}} JSXProps
9+
* @typedef {{[x: string]: XValue | XChild}} JSXProps
1010
*/
1111

1212
import {x} from './index.js'
@@ -17,19 +17,19 @@ export * from './jsx-automatic.js'
1717
/**
1818
* Create XML trees in xast through JSX.
1919
*
20-
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as `rdf:RDF`). Pass `null|undefined` to build a root.
20+
* @param name Qualified name. Case sensitive and can contain a namespace prefix (such as `rdf:RDF`). Pass `null | undefined` to build a root.
2121
* @param props Map of attributes. Nullish (null or undefined) or NaN values are ignored, other values (strings, booleans) are cast to strings. `children` can contain one child or a list of children. When strings are encountered, they are mapped to text nodes.
2222
*/
2323
export const jsx =
2424
/**
2525
* @type {{
26-
* (name: null|undefined, props: {children?: XChild}, key?: string): Root
26+
* (name: null | undefined, props: {children?: XChild}, key?: string): Root
2727
* (name: string, props: JSXProps, key?: string): Element
2828
* }}
2929
*/
3030
(
3131
/**
32-
* @param {string|null} name
32+
* @param {string | null} name
3333
* @param {XAttributes & {children?: XChild}} props
3434
* @returns {XResult}
3535
*/

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"prettier": "^2.0.0",
6060
"remark-cli": "^11.0.0",
6161
"remark-preset-wooorm": "^9.0.0",
62-
"rimraf": "^3.0.0",
6362
"tape": "^5.0.0",
6463
"tsd": "^0.25.0",
6564
"type-coverage": "^2.0.0",
@@ -69,11 +68,11 @@
6968
},
7069
"scripts": {
7170
"prepack": "npm run build && npm run format",
72-
"build": "rimraf \"{script/**,test/**,}*.d.ts\" \"lib/{index,runtime}.d.ts\" && tsc && tsd && type-coverage",
73-
"generate": "node script/generate-jsx",
71+
"generate": "node script/generate-jsx.js",
72+
"build": "tsc --build --clean && tsc --build && tsd && type-coverage",
7473
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
75-
"test-api": "node test/index.js",
76-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
74+
"test-api": "node --conditions development test.js",
75+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
7776
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
7877
},
7978
"prettier": {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ When nullish, a [`Root`][root] is built instead.
215215

216216
###### `attributes`
217217

218-
Map of attributes (`Record<string, string|number|boolean|null|undefined>`,
218+
Map of attributes (`Record<string, string | number | boolean | null | undefined>`,
219219
optional).
220220
Nullish (`null` or `undefined`) or `NaN` values are ignored, other values are
221221
turned to strings.

test/jsx.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @jsxImportSource xastscript */
2+
13
import test from 'tape'
24
import {u} from 'unist-builder'
35
import {x} from '../index.js'
@@ -9,6 +11,8 @@ test('name', (t) => {
911

1012
const A = 'a'
1113

14+
// Note: this file is a template, generated with different runtimes.
15+
// @ts-ignore: TS (depending on this build) sometimes doesn’t understand.
1216
t.deepEqual(<A />, x(A), 'should support an uppercase tag name')
1317

1418
t.deepEqual(
@@ -42,6 +46,8 @@ test('name', (t) => {
4246
const com = {acme: {a: 'A', b: 'B'}}
4347

4448
t.deepEqual(
49+
// Note: this file is a template, generated with different runtimes.
50+
// @ts-ignore: TS (depending on this build) sometimes doesn’t understand.
4551
<com.acme.a />,
4652
x(com.acme.a),
4753
'should support members as names (`a.b`)'

tsconfig.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
{
2-
"include": [
3-
"*.js",
4-
"script/**/*.js",
5-
"test/**/*.js",
6-
"lib/index.js",
7-
"lib/runtime.js",
8-
"lib/jsx-automatic.d.ts",
9-
"lib/jsx-classic.d.ts"
2+
"include": ["**/**.js", "**/**.jsx"],
3+
"exclude": [
4+
"coverage/",
5+
"node_modules/",
6+
"lib/jsx-automatic.js",
7+
"lib/jsx-classic.js"
108
],
119
"compilerOptions": {
12-
"target": "ES2020",
13-
"lib": ["ES2020"],
14-
"module": "Node16",
15-
"allowJs": true,
1610
"checkJs": true,
1711
"declaration": true,
1812
"emitDeclarationOnly": true,
19-
"allowSyntheticDefaultImports": true,
13+
"exactOptionalPropertyTypes": true,
14+
"forceConsistentCasingInFileNames": true,
15+
"lib": ["es2020"],
16+
"module": "node16",
17+
"newLine": "lf",
2018
"skipLibCheck": true,
21-
"strictNullChecks": true,
22-
"strict": true
19+
"strict": true,
20+
"target": "es2020",
21+
"jsx": "preserve"
2322
}
2423
}

0 commit comments

Comments
 (0)