@@ -210,6 +210,18 @@ with_continue_listener = function(body)
210210end
211211do
212212 local _base_0 = {
213+ transform_once = function (self , scope , node , ...)
214+ if self .seen_nodes [node ] then
215+ return node
216+ end
217+ self .seen_nodes [node ] = true
218+ local transformer = self .transformers [ntype (node )]
219+ if transformer then
220+ return transformer (scope , node , ... ) or node
221+ else
222+ return node
223+ end
224+ end ,
213225 transform = function (self , scope , node , ...)
214226 if self .seen_nodes [node ] then
215227 return node
@@ -314,6 +326,18 @@ Statement = Transformer({
314326 root_stms = function (self , body )
315327 return apply_to_last (body , implicitly_return (self ))
316328 end ,
329+ [" return" ] = function (self , node )
330+ node [2 ] = Value :transform_once (self , node [2 ])
331+ if " block_exp" == ntype (node [2 ]) then
332+ local block_exp = node [2 ]
333+ local block_body = block_exp [2 ]
334+ local idx = # block_body
335+ node [2 ] = block_body [idx ]
336+ block_body [idx ] = node
337+ return build .group (block_body )
338+ end
339+ return node
340+ end ,
317341 declare_glob = function (self , node )
318342 local names = extract_declarations (self )
319343 if node [2 ] == " ^" then
@@ -370,7 +394,7 @@ Statement = Transformer({
370394 }
371395 })
372396 elseif " comprehension" == _exp_0 or " tblcomprehension" == _exp_0 or " foreach" == _exp_0 or " for" == _exp_0 or " while" == _exp_0 then
373- return build .assign_one (first_name , Value . transformers [ first_value [ 1 ]] (self , first_value ))
397+ return build .assign_one (first_name , Value : transform_once (self , first_value ))
374398 end
375399 end
376400 local transformed
0 commit comments