@@ -281,11 +281,9 @@ export function buildJsx(tree, options) {
281
281
282
282
/** @type {MemberExpression | Literal | Identifier } */
283
283
let name
284
- /** @type {Array<Property> } */
285
- let fields = [ ]
284
+ /** @type {Array<Property | SpreadElement > } */
285
+ const fields = [ ]
286
286
/** @type {Array<Expression> } */
287
- const objects = [ ]
288
- /** @type {Array<Expression | SpreadElement> } */
289
287
let parameters = [ ]
290
288
/** @type {Expression | undefined } */
291
289
let key
@@ -314,12 +312,12 @@ export function buildJsx(tree, options) {
314
312
const attribute = attributes [ index ]
315
313
316
314
if ( attribute . type === 'JSXSpreadAttribute' ) {
317
- if ( fields . length > 0 ) {
318
- objects . push ( { type : 'ObjectExpression' , properties : fields } )
319
- fields = [ ]
315
+ if ( attribute . argument . type === 'ObjectExpression' ) {
316
+ fields . push ( ...attribute . argument . properties )
317
+ } else {
318
+ fields . push ( { type : 'SpreadElement' , argument : attribute . argument } )
320
319
}
321
320
322
- objects . push ( attribute . argument )
323
321
spread = true
324
322
} else {
325
323
const prop = toProperty ( attribute )
@@ -373,33 +371,11 @@ export function buildJsx(tree, options) {
373
371
parameters = children
374
372
}
375
373
376
- if ( fields . length > 0 ) {
377
- objects . push ( { type : 'ObjectExpression' , properties : fields } )
378
- }
379
-
380
- /** @type {Expression | undefined } */
381
- let props
382
374
/** @type {MemberExpression | Literal | Identifier } */
383
375
let callee
384
376
385
- if ( objects . length > 1 ) {
386
- // Don’t mutate the first object, shallow clone instead.
387
- if ( objects [ 0 ] . type !== 'ObjectExpression' ) {
388
- objects . unshift ( { type : 'ObjectExpression' , properties : [ ] } )
389
- }
390
-
391
- props = {
392
- type : 'CallExpression' ,
393
- callee : toMemberExpression ( 'Object.assign' ) ,
394
- arguments : objects ,
395
- optional : false
396
- }
397
- } else if ( objects . length > 0 ) {
398
- props = objects [ 0 ]
399
- }
400
-
401
377
if ( automatic ) {
402
- parameters . push ( props || { type : 'ObjectExpression' , properties : [ ] } )
378
+ parameters . push ( { type : 'ObjectExpression' , properties : fields } )
403
379
404
380
if ( key ) {
405
381
parameters . push ( key )
@@ -470,9 +446,10 @@ export function buildJsx(tree, options) {
470
446
}
471
447
// Classic.
472
448
else {
473
- // There are props or children.
474
- if ( props || parameters . length > 0 ) {
475
- parameters . unshift ( props || { type : 'Literal' , value : null } )
449
+ if ( fields . length > 0 ) {
450
+ parameters . unshift ( { type : 'ObjectExpression' , properties : fields } )
451
+ } else if ( parameters . length > 0 ) {
452
+ parameters . unshift ( { type : 'Literal' , value : null } )
476
453
}
477
454
478
455
callee = toMemberExpression (
0 commit comments