@@ -158,6 +158,9 @@ const parseAttributeJSXAttribute = (t, path, attributes, tagName, elementType) =
158
158
} else {
159
159
name = namePath . get ( 'name' ) . node
160
160
}
161
+ if ( prefixes . includes ( name ) && t . isJSXExpressionContainer ( path . get ( 'value' ) ) ) {
162
+ return t . JSXSpreadAttribute ( t . objectExpression ( [ t . objectProperty ( t . stringLiteral ( name ) , path . get ( 'value' ) . node . expression ) ] ) )
163
+ }
161
164
162
165
; [ name , ...modifiers ] = name . split ( '_' )
163
166
; [ name , argument ] = name . split ( ':' )
@@ -233,16 +236,24 @@ const parseAttributeJSXSpreadAttribute = (t, path, attributes, attributesArray)
233
236
* @param t
234
237
* @param paths Array<JSXAttribute | JSXSpreadAttribute>
235
238
* @param tag Identifier | StringLiteral | MemberExpression
239
+ * @param openingElementPath JSXOpeningElement
236
240
* @returns Array<Expression>
237
241
*/
238
- const getAttributes = ( t , paths , tag ) => {
242
+ const getAttributes = ( t , paths , tag , openingElementPath ) => {
239
243
const attributesArray = [ ]
240
244
let attributes = { }
241
245
242
246
const { tagName, canContainDomProps, elementType } = parseMagicDomPropsInfo ( t , paths , tag )
243
247
paths . forEach ( path => {
244
248
if ( t . isJSXAttribute ( path ) ) {
245
- parseAttributeJSXAttribute ( t , path , attributes , tagName , elementType )
249
+ const possibleSpreadNode = parseAttributeJSXAttribute ( t , path , attributes , tagName , elementType )
250
+ if ( possibleSpreadNode ) {
251
+ openingElementPath . node . attributes . push ( possibleSpreadNode )
252
+ const attributePaths = openingElementPath . get ( 'attributes' )
253
+ const lastAttributePath = attributePaths [ attributePaths . length - 1 ]
254
+ attributes = parseAttributeJSXSpreadAttribute ( t , lastAttributePath , attributes , attributesArray )
255
+ lastAttributePath . remove ( )
256
+ }
246
257
return
247
258
}
248
259
/* istanbul ignore else */
@@ -328,7 +339,8 @@ const transformAttributes = (t, attributes) =>
328
339
const transformJSXElement = ( t , path ) => {
329
340
const tag = getTag ( t , path . get ( 'openingElement' ) )
330
341
const children = getChildren ( t , path . get ( 'children' ) )
331
- const attributes = getAttributes ( t , path . get ( 'openingElement.attributes' ) , tag )
342
+ const openingElementPath = path . get ( 'openingElement' )
343
+ const attributes = getAttributes ( t , openingElementPath . get ( 'attributes' ) , tag , openingElementPath )
332
344
333
345
const args = [ tag ]
334
346
if ( attributes ) {
0 commit comments