13
13
* @typedef {import('estree-jsx').JSXNamespacedName } JSXNamespacedName
14
14
* @typedef {import('estree-jsx').JSXIdentifier } JSXIdentifier
15
15
*
16
+ * @typedef {'automatic' | 'classic' } Runtime
17
+ *
16
18
* @typedef Options
17
- * Configuration (optional) .
19
+ * Configuration.
18
20
*
19
21
* > 👉 **Note**: you can also configure `runtime`, `importSource`, `pragma`,
20
22
* > and `pragmaFrag` from within files through comments.
21
- * @property {'automatic' | 'classic' } [runtime='classic']
23
+ * @property {Runtime | null | undefined } [runtime='classic']
22
24
* Choose the runtime.
23
25
*
24
26
* Comment form: `@jsxRuntime theRuntime`.
25
- * @property {string } [importSource='react']
27
+ * @property {string | null | undefined } [importSource='react']
26
28
* Place to import `jsx`, `jsxs`, `jsxDEV`, and/or `Fragment` from, when the
27
29
* effective runtime is automatic.
28
30
*
29
31
* Comment form: `@jsxImportSource theSource`.
30
32
*
31
33
* > 👉 **Note**: `/jsx-runtime` or `/jsx-dev-runtime` is appended to this
32
34
* > provided source.
33
- * > In CJS, that can resolve to a file, as in `theSource/jsx-runtime.js`,
35
+ * > In CJS, that can resolve to a file ( as in `theSource/jsx-runtime.js`) ,
34
36
* > but for ESM an export map needs to be set up to point to files:
35
37
* >
36
38
* > ```js
41
43
* > "./jsx-dev-runtime": "./path/to/jsx-runtime.js"
42
44
* > // …
43
45
* > ```
44
- * @property {string } [pragma='React.createElement']
46
+ * @property {string | null | undefined } [pragma='React.createElement']
45
47
* Identifier or member expression to call when the effective runtime is
46
48
* classic.
47
49
*
48
50
* Comment form: `@jsx identifier`.
49
- * @property {string } [pragmaFrag='React.Fragment']
51
+ * @property {string | null | undefined } [pragmaFrag='React.Fragment']
50
52
* Identifier or member expression to use as a symbol for fragments when the
51
53
* effective runtime is classic.
52
54
*
53
55
* Comment form: `@jsxFrag identifier`.
54
- * @property {boolean } [development=false]
56
+ * @property {boolean | null | undefined } [development=false]
55
57
* Import `jsxDEV` from `theSource/jsx-dev-runtime.js` and add location info
56
58
* on where a component originated from.
57
59
*
58
60
* This helps debugging but adds a lot of code that you don’t want in
59
61
* production.
60
62
* Only used in the automatic runtime.
61
- * @property {string } [filePath]
63
+ * @property {string | null | undefined } [filePath]
62
64
* File path to the original source file.
65
+ *
63
66
* Used in the location info when using the automatic runtime with
64
67
* `development: true`.
65
68
*
66
69
* @typedef Annotations
67
- * @property {'automatic' | 'classic' } [jsxRuntime]
68
- * @property {string } [jsx]
69
- * @property {string } [jsxFrag]
70
- * @property {string } [jsxImportSource]
70
+ * State where info from comments is gathered.
71
+ * @property {Runtime | undefined } [jsxRuntime]
72
+ * Runtime.
73
+ * @property {string | undefined } [jsx]
74
+ * JSX identifier (`pragma`).
75
+ * @property {string | undefined } [jsxFrag]
76
+ * JSX identifier of fragment (`pragmaFrag`).
77
+ * @property {string | undefined } [jsxImportSource]
78
+ * Where to import an automatic JSX runtime from.
79
+ *
80
+ * @typedef Imports
81
+ * State of used identifiers from the automatic runtime.
82
+ * @property {boolean | undefined } [fragment]
83
+ * Symbol of `Fragment`.
84
+ * @property {boolean | undefined } [jsx]
85
+ * Symbol of `jsx`.
86
+ * @property {boolean | undefined } [jsxs]
87
+ * Symbol of `jsxs`.
88
+ * @property {boolean | undefined } [jsxDEV]
89
+ * Symbol of `jsxDEV`.
71
90
*/
72
91
73
92
import { walk } from 'estree-walker'
@@ -79,6 +98,7 @@ const regex = /@(jsx|jsxFrag|jsxImportSource|jsxRuntime)\s+(\S+)/g
79
98
* Turn JSX in `tree` into function calls: `<x />` -> `h('x')`!
80
99
*
81
100
* @template {Node} Tree
101
+ * Node type.
82
102
* @param {Tree } tree
83
103
* Tree to transform.
84
104
* @param {Options } [options={}]
@@ -91,7 +111,7 @@ export function buildJsx(tree, options = {}) {
91
111
let automatic = options . runtime === 'automatic'
92
112
/** @type {Annotations } */
93
113
const annotations = { }
94
- /** @type {{fragment?: boolean, jsx?: boolean, jsxs?: boolean, jsxDEV?: boolean} } */
114
+ /** @type {Imports } */
95
115
const imports = { }
96
116
97
117
walk ( tree , {
@@ -444,7 +464,6 @@ export function buildJsx(tree, options = {}) {
444
464
parameters . unshift ( name )
445
465
446
466
// Types of `estree-walker` are wrong
447
- // type-coverage:ignore-next-line
448
467
this . replace (
449
468
create ( node , {
450
469
type : 'CallExpression' ,
0 commit comments