1
- import { walk } from 'estree-walker'
2
- import { name as isIdentifierName } from 'estree-util-is-identifier-name'
3
-
4
- const regex = / @ ( j s x | j s x F r a g | j s x I m p o r t S o u r c e | j s x R u n t i m e ) \s + ( \S + ) / g
5
-
6
1
/**
7
2
* @typedef {import('estree-jsx').Node } Node
8
3
* @typedef {import('estree-jsx').Comment } Comment
@@ -28,26 +23,27 @@ const regex = /@(jsx|jsxFrag|jsxImportSource|jsxRuntime)\s+(\S+)/g
28
23
* @typedef {import('estree-jsx').JSXIdentifier } JSXIdentifier
29
24
*
30
25
* @typedef {import('estree-walker').SyncHandler } SyncHandler
31
- */
32
-
33
- /**
34
- * @typedef {Object } BuildJsxOptions
26
+ *
27
+ * @typedef BuildJsxOptions
35
28
* @property {'automatic'|'classic' } [runtime='classic']
36
29
* @property {string } [importSource='react']
37
30
* @property {string } [pragma='React.createElement']
38
31
* @property {string } [pragmaFrag='React.Fragment']
39
32
* @property {boolean } [development=false]
40
33
* @property {string } [filePath]
41
- */
42
-
43
- /**
44
- * @typedef {Object } Annotations
34
+ *
35
+ * @typedef Annotations
45
36
* @property {'automatic'|'classic' } [jsxRuntime]
46
37
* @property {string } [jsx]
47
38
* @property {string } [jsxFrag]
48
39
* @property {string } [jsxImportSource]
49
40
*/
50
41
42
+ import { walk } from 'estree-walker'
43
+ import { name as isIdentifierName } from 'estree-util-is-identifier-name'
44
+
45
+ const regex = / @ ( j s x | j s x F r a g | j s x I m p o r t S o u r c e | j s x R u n t i m e ) \s + ( \S + ) / g
46
+
51
47
/**
52
48
* @template {Node} T
53
49
* @param {T } tree
@@ -170,7 +166,7 @@ export function buildJsx(tree, options = {}) {
170
166
return
171
167
}
172
168
173
- /** @type {Array. <Expression> } */
169
+ /** @type {Array<Expression> } */
174
170
const children = [ ]
175
171
let index = - 1
176
172
@@ -201,19 +197,20 @@ export function buildJsx(tree, options = {}) {
201
197
children . push ( create ( child , { type : 'Literal' , value} ) )
202
198
}
203
199
} else {
204
- // @ts -ignore JSX{Element,Fragment} have already been compiled, and
205
- // `JSXSpreadChild` is not supported in Babel either, so ignore it.
200
+ // @ts -expect-error JSX{Element,Fragment} have already been compiled,
201
+ // and `JSXSpreadChild` is not supported in Babel either, so ignore
202
+ // it.
206
203
children . push ( child )
207
204
}
208
205
}
209
206
210
207
/** @type {MemberExpression|Literal|Identifier } */
211
208
let name
212
- /** @type {Array. <Property> } */
209
+ /** @type {Array<Property> } */
213
210
let fields = [ ]
214
- /** @type {Array. <Expression> } */
211
+ /** @type {Array<Expression> } */
215
212
const objects = [ ]
216
- /** @type {Array. <Expression|SpreadElement> } */
213
+ /** @type {Array<Expression|SpreadElement> } */
217
214
let parameters = [ ]
218
215
/** @type {Expression|undefined } */
219
216
let key
@@ -260,8 +257,8 @@ export function buildJsx(tree, options = {}) {
260
257
)
261
258
}
262
259
263
- // @ts -ignore I can’t see object patterns being used as attribute
264
- // values? 🤷♂️
260
+ // @ts -expect-error I can’t see object patterns being used as
261
+ // attribute values? 🤷♂️
265
262
key = prop . value
266
263
} else {
267
264
fields . push ( prop )
@@ -431,15 +428,15 @@ function toProperty(node) {
431
428
432
429
if ( node . value ) {
433
430
if ( node . value . type === 'JSXExpressionContainer' ) {
434
- // @ts -ignore `JSXEmptyExpression` is not allowed in props.
431
+ // @ts -expect-error `JSXEmptyExpression` is not allowed in props.
435
432
value = node . value . expression
436
433
}
437
434
// Literal or call expression.
438
435
else {
439
- // @ts -ignore : JSX{Element,Fragment} are already compiled to
436
+ // @ts -expect-error : JSX{Element,Fragment} are already compiled to
440
437
// `CallExpression`.
441
438
value = node . value
442
- // @ts -ignore - Remove `raw` so we don’t get character references in
439
+ // @ts -expect-error Remove `raw` so we don’t get character references in
443
440
// strings.
444
441
delete value . raw
445
442
}
0 commit comments