remove empty return statement at end of fndef (#20)

This commit is contained in:
leaf corcoran 2012-01-13 21:24:46 -08:00
parent 2ea42c3387
commit bf416dbb1c
3 changed files with 15 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)