mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
remove empty return statement at end of fndef (#20)
This commit is contained in:
parent
2ea42c3387
commit
bf416dbb1c
@ -1025,12 +1025,18 @@ default_accumulator = function(self, node)
|
||||
end
|
||||
local implicitly_return
|
||||
implicitly_return = function(scope)
|
||||
local is_top = true
|
||||
local fn
|
||||
fn = function(stm)
|
||||
local t = ntype(stm)
|
||||
if types.manual_return[t] or not types.is_value(stm) then
|
||||
return stm
|
||||
if is_top and t == "return" and stm[2] == "" then
|
||||
return nil
|
||||
else
|
||||
return stm
|
||||
end
|
||||
elseif types.cascading[t] then
|
||||
is_top = false
|
||||
return scope.transform.statement(stm, fn)
|
||||
else
|
||||
if t == "comprehension" and not types.comprehension_has_value(stm) then
|
||||
|
@ -528,11 +528,17 @@ default_accumulator = (node) =>
|
||||
|
||||
|
||||
implicitly_return = (scope) ->
|
||||
is_top = true
|
||||
fn = (stm) ->
|
||||
t = ntype stm
|
||||
if types.manual_return[t] or not types.is_value stm
|
||||
stm
|
||||
-- remove blank return statement
|
||||
if is_top and t == "return" and stm[2] == ""
|
||||
nil
|
||||
else
|
||||
stm
|
||||
elseif types.cascading[t]
|
||||
is_top = false
|
||||
scope.transform.statement stm, fn
|
||||
else
|
||||
if t == "comprehension" and not types.comprehension_has_value stm
|
||||
|
@ -94,9 +94,7 @@ _ = function(self, x, y, z)
|
||||
end
|
||||
self.x, self.z = x, z
|
||||
end
|
||||
x(function()
|
||||
return
|
||||
end)
|
||||
x(function() end)
|
||||
y(function()
|
||||
return 1
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user