79
79
* @typedef {JSX.Element | string | null | undefined } Child
80
80
* Child.
81
81
*
82
- * @typedef {{children: Array<Child> | undefined , node?: Element | undefined, [prop: string]: Value | Element | undefined | Array<Child>} } Props
82
+ * @typedef {{children? : Array<Child> | Child , node?: Element | undefined, [prop: string]: Value | Element | undefined | Child | Array<Child>} } Props
83
83
* Properties and children.
84
84
*
85
85
* @callback Create
@@ -295,7 +295,7 @@ export function toJsxRuntime(tree, options) {
295
295
return state . create (
296
296
tree ,
297
297
state . Fragment ,
298
- { children : result ? [ result ] : undefined } ,
298
+ { children : result || undefined } ,
299
299
undefined
300
300
)
301
301
}
@@ -348,7 +348,13 @@ function one(state, node, key) {
348
348
}
349
349
}
350
350
351
- props . children = children
351
+ if ( children . length > 0 ) {
352
+ const value = children . length > 1 ? children : children [ 0 ]
353
+
354
+ if ( value ) {
355
+ props . children = value
356
+ }
357
+ }
352
358
353
359
// Restore parent schema.
354
360
state . schema = parentSchema
@@ -375,7 +381,8 @@ function productionCreate(_, jsx, jsxs) {
375
381
return create
376
382
/** @type {Create } */
377
383
function create ( _ , type , props , key ) {
378
- const isStaticChildren = props . children ? props . children . length > 1 : false
384
+ // Only an array when there are 2 or more children.
385
+ const isStaticChildren = Array . isArray ( props . children )
379
386
const fn = isStaticChildren ? jsxs : jsx
380
387
return key ? fn ( type , props , key ) : fn ( type , props )
381
388
}
@@ -393,7 +400,8 @@ function developmentCreate(filePath, jsxDEV) {
393
400
return create
394
401
/** @type {Create } */
395
402
function create ( node , type , props , key ) {
396
- const isStaticChildren = props . children ? props . children . length > 1 : false
403
+ // Only an array when there are 2 or more children.
404
+ const isStaticChildren = Array . isArray ( props . children )
397
405
const point = pointStart ( node )
398
406
return jsxDEV (
399
407
type ,
@@ -417,7 +425,7 @@ function developmentCreate(filePath, jsxDEV) {
417
425
* Info passed around.
418
426
* @param {Parent } node
419
427
* Current element.
420
- * @returns {Array<Child> | undefined }
428
+ * @returns {Array<Child> }
421
429
* Children.
422
430
*/
423
431
function createChildren ( state , node ) {
@@ -444,7 +452,7 @@ function createChildren(state, node) {
444
452
if ( result !== undefined ) children . push ( result )
445
453
}
446
454
447
- return children . length > 0 ? children : undefined
455
+ return children
448
456
}
449
457
450
458
/**
@@ -459,7 +467,7 @@ function createChildren(state, node) {
459
467
*/
460
468
function createProperties ( state , node ) {
461
469
/** @type {Props } */
462
- const props = { children : [ ] }
470
+ const props = { }
463
471
/** @type {string } */
464
472
let prop
465
473
0 commit comments