@@ -125,6 +125,7 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
125125 if ( props . length === 0 ) {
126126 return {
127127 tag,
128+ isComponent,
128129 props : t . nullLiteral ( ) ,
129130 directives,
130131 patchFlag,
@@ -314,6 +315,7 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
314315 return {
315316 tag,
316317 props : propsExpression ,
318+ isComponent,
317319 directives,
318320 patchFlag,
319321 dynamicPropNames,
@@ -371,11 +373,18 @@ const transformJSXElement = (
371373 const {
372374 tag,
373375 props,
376+ isComponent,
374377 directives,
375378 patchFlag,
376379 dynamicPropNames,
377380 } = buildProps ( path , state ) ;
378381
382+ const { scope : { bindings } } = path ;
383+
384+ const bindingsReferenced = Object . keys ( bindings ) . some ( key => bindings [ key ] . referenced ) ;
385+
386+ const useOptimate = ! ( bindingsReferenced && t . isReturnStatement ( path . container ) ) ;
387+
379388 const flagNames = Object . keys ( PatchFlagNames )
380389 . map ( Number )
381390 . filter ( ( n ) => n > 0 && patchFlag & n )
@@ -390,11 +399,18 @@ const transformJSXElement = (
390399 }
391400
392401 // @ts -ignore
393- const createVNode = t . callExpression ( createIdentifier ( state , 'createVNode' ) , [
402+ const createVNode = t . callExpression ( createIdentifier ( state , useOptimate ? 'createVNode' : 'h ') , [
394403 tag ,
395404 // @ts -ignore
396405 compatibleProps ? t . callExpression ( state . get ( 'compatibleProps' ) , [ props ] ) : props ,
397- ! ! children . length ? t . arrayExpression ( children ) : t . nullLiteral ( ) ,
406+ ! ! children . length ? (
407+ isComponent ? t . objectExpression ( [
408+ t . objectProperty (
409+ t . identifier ( 'default' ) ,
410+ t . arrowFunctionExpression ( [ ] , t . arrayExpression ( children ) )
411+ )
412+ ] ) : t . arrayExpression ( children )
413+ ) : t . nullLiteral ( ) ,
398414 ! ! patchFlag && t . addComment ( t . numericLiteral ( patchFlag ) , 'trailing' , ` ${ flagNames } ` , false ) ,
399415 ! ! dynamicPropNames . size
400416 && t . arrayExpression ( [ ...dynamicPropNames . keys ( ) ] . map ( ( name ) => t . stringLiteral ( name as string ) ) ) ,
0 commit comments