diff --git a/moonscript/transform.lua b/moonscript/transform.lua index a0a407c..d216b4c 100644 --- a/moonscript/transform.lua +++ b/moonscript/transform.lua @@ -1228,6 +1228,10 @@ implicitly_return = function(scope) local fn fn = function(stm) local t = ntype(stm) + if t == "decorated" then + stm = scope.transform.statement(stm) + t = ntype(stm) + end if types.manual_return[t] or not types.is_value(stm) then if is_top and t == "return" and stm[2] == "" then return nil diff --git a/moonscript/transform.moon b/moonscript/transform.moon index 129dadf..1ee2d74 100644 --- a/moonscript/transform.moon +++ b/moonscript/transform.moon @@ -627,6 +627,12 @@ implicitly_return = (scope) -> is_top = true fn = (stm) -> t = ntype stm + + -- expand decorated + if t == "decorated" + stm = scope.transform.statement stm + t = ntype stm + if types.manual_return[t] or not types.is_value stm -- remove blank return statement if is_top and t == "return" and stm[2] == "" diff --git a/tests/inputs/funcs.moon b/tests/inputs/funcs.moon index 3837e18..8c17439 100644 --- a/tests/inputs/funcs.moon +++ b/tests/inputs/funcs.moon @@ -57,5 +57,5 @@ y -> return 1 z -> return 1, "hello", "world" k -> if yes then return else return - +-> real_name if something diff --git a/tests/outputs/funcs.lua b/tests/outputs/funcs.lua index c24de22..98a3f5f 100644 --- a/tests/outputs/funcs.lua +++ b/tests/outputs/funcs.lua @@ -107,4 +107,9 @@ k(function() else return end -end) \ No newline at end of file +end) +_ = function() + if something then + return real_name + end +end \ No newline at end of file