File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -271,12 +271,17 @@ __originalConsole.log('__RESULT__', JSON.stringify({
271271 const lines = trimmedCode . split ( '\n' ) ;
272272 const lastLine = lines [ lines . length - 1 ] . trim ( ) ;
273273
274- // Check if code already contains a return statement
274+ // Check if code already contains a TOP-LEVEL return statement
275275 // (avoid wrapping multi-line returns like: return { ... };)
276- const hasReturnStatement = trimmedCode . includes ( 'return ' ) ;
276+ // NOTE: Don't just check for 'return' anywhere - it might be inside a function!
277+ // Simple heuristic: check if last 3 lines contain a return statement
278+ const hasTopLevelReturn = lines . some ( ( line , idx ) => {
279+ if ( idx < lines . length - 3 ) return false ; // Only check last few lines
280+ return line . trim ( ) . startsWith ( 'return ' ) ;
281+ } ) ;
277282
278- // If code already has a return statement, don't modify it
279- if ( hasReturnStatement ) {
283+ // If code already has a top-level return statement, don't modify it
284+ if ( hasTopLevelReturn ) {
280285 wrappedCode = trimmedCode ;
281286 } else {
282287 // Check if last line is a bare expression that should become a return
You can’t perform that action at this time.
0 commit comments