@@ -277,9 +277,9 @@ export function handleCreateServerFn(
277277 }
278278 }
279279
280- const handlerFnPath = handler ?. firstArgPath
280+ const handlerArgPath = handler ?. firstArgPath
281281
282- if ( ! handler || ! handlerFnPath ?. node ) {
282+ if ( ! handler || ! handlerArgPath ?. node ) {
283283 throw codeFrameError (
284284 context . code ,
285285 candidatePath . node . callee . loc ! ,
@@ -288,14 +288,46 @@ export function handleCreateServerFn(
288288 }
289289
290290 // Validate the handler argument is an expression (not a SpreadElement, etc.)
291- if ( ! t . isExpression ( handlerFnPath . node ) ) {
291+ if ( ! t . isExpression ( handlerArgPath . node ) ) {
292292 throw codeFrameError (
293293 context . code ,
294- handlerFnPath . node . loc ! ,
295- `handler() must be called with an expression, not a ${ handlerFnPath . node . type } ` ,
294+ handlerArgPath . node . loc ! ,
295+ `handler() must be called with an expression, not a ${ handlerArgPath . node . type } ` ,
296296 )
297297 }
298298
299+ let handlerFnPath = handlerArgPath as babel . NodePath < t . Expression >
300+
301+ if ( handlerArgPath . isObjectExpression ( ) ) {
302+ const handlerPropertyPath = handlerArgPath
303+ . get ( 'properties' )
304+ . find (
305+ ( propertyPath ) =>
306+ propertyPath . isObjectProperty ( ) &&
307+ ! propertyPath . node . computed &&
308+ t . isIdentifier ( propertyPath . node . key , { name : 'handler' } ) ,
309+ )
310+
311+ if ( ! handlerPropertyPath ) {
312+ throw codeFrameError (
313+ context . code ,
314+ handlerArgPath . node . loc ! ,
315+ `handler() object argument must have a "handler" property!` ,
316+ )
317+ }
318+
319+ const valuePath = handlerPropertyPath . get ( 'value' )
320+ if ( ! valuePath . isExpression ( ) ) {
321+ throw codeFrameError (
322+ context . code ,
323+ valuePath . node . loc ! ,
324+ `handler() object "handler" property must be an expression, not a ${ valuePath . node . type } ` ,
325+ )
326+ }
327+
328+ handlerFnPath = valuePath
329+ }
330+
299331 const handlerFn = handlerFnPath . node
300332
301333 // Register function only from caller files (not provider files)
@@ -405,7 +437,7 @@ export function handleCreateServerFn(
405437
406438 // Replace ONLY the handler argument with the RPC stub
407439 // Keep the createServerFn().handler() wrapper intact for client middleware
408- handlerFnPath . replaceWith ( rpcStub )
440+ handlerArgPath . replaceWith ( rpcStub )
409441 }
410442 }
411443
0 commit comments