@@ -127,18 +127,21 @@ export default (babel) => {
127
127
function transformComponentChildren ( path , children , opts ) {
128
128
const filteredChildren = filterChildren ( children ) ;
129
129
if ( ! filteredChildren . length ) return ;
130
- let child = filteredChildren . length === 1 ?
131
- filteredChildren [ 0 ] :
132
- t . JSXFragment ( t . JSXOpeningFragment ( ) , t . JSXClosingFragment ( ) , children ) ;
130
+ let child , dynamic ;
131
+ if ( filteredChildren . length === 1 ) {
132
+ if ( t . isJSXExpressionContainer ( filteredChildren [ 0 ] ) ) dynamic = checkParens ( filteredChildren [ 0 ] , path )
133
+ child = filteredChildren [ 0 ]
134
+ } else child = t . JSXFragment ( t . JSXOpeningFragment ( ) , t . JSXClosingFragment ( ) , children ) ;
135
+
133
136
child = generateHTMLNode ( path , child , opts ) ;
134
137
if ( child == null ) return ;
135
138
if ( child . id ) {
136
139
registerTemplate ( path , child , filteredChildren . length !== 1 ) ;
137
140
if ( ! child . exprs . length && child . decl . declarations . length === 1 )
138
- return child . decl . declarations [ 0 ] . init ;
139
- else return t . callExpression ( t . arrowFunctionExpression ( [ ] , t . blockStatement ( [ child . decl , ...child . exprs , t . returnStatement ( child . id ) ] ) ) , [ ] ) ;
141
+ return [ child . decl . declarations [ 0 ] . init ] ;
142
+ else return [ t . callExpression ( t . arrowFunctionExpression ( [ ] , t . blockStatement ( [ child . decl , ...child . exprs , t . returnStatement ( child . id ) ] ) ) , [ ] ) ] ;
140
143
}
141
- return child . exprs [ 0 ] ;
144
+ return [ child . exprs [ 0 ] , dynamic ] ;
142
145
}
143
146
144
147
// reduce unnecessary refs
@@ -230,9 +233,11 @@ export default (babel) => {
230
233
}
231
234
} ) ;
232
235
233
- const children = transformComponentChildren ( path , jsx . children , opts ) ;
234
- if ( children )
235
- runningObject . push ( t . objectProperty ( t . identifier ( "children" ) , children ) ) ;
236
+ const childResult = transformComponentChildren ( path , jsx . children , opts ) ;
237
+ if ( childResult && childResult [ 0 ] ) {
238
+ childResult [ 1 ] && dynamic . push ( t . stringLiteral ( 'children' ) )
239
+ runningObject . push ( t . objectProperty ( t . identifier ( "children" ) , childResult [ 0 ] ) ) ;
240
+ }
236
241
237
242
if ( runningObject . length )
238
243
props . push ( t . objectExpression ( runningObject ) ) ;
0 commit comments