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
|
end
|
||||||
local implicitly_return
|
local implicitly_return
|
||||||
implicitly_return = function(scope)
|
implicitly_return = function(scope)
|
||||||
|
local is_top = true
|
||||||
local fn
|
local fn
|
||||||
fn = function(stm)
|
fn = function(stm)
|
||||||
local t = ntype(stm)
|
local t = ntype(stm)
|
||||||
if types.manual_return[t] or not types.is_value(stm) then
|
if types.manual_return[t] or not types.is_value(stm) then
|
||||||
|
if is_top and t == "return" and stm[2] == "" then
|
||||||
|
return nil
|
||||||
|
else
|
||||||
return stm
|
return stm
|
||||||
|
end
|
||||||
elseif types.cascading[t] then
|
elseif types.cascading[t] then
|
||||||
|
is_top = false
|
||||||
return scope.transform.statement(stm, fn)
|
return scope.transform.statement(stm, fn)
|
||||||
else
|
else
|
||||||
if t == "comprehension" and not types.comprehension_has_value(stm) then
|
if t == "comprehension" and not types.comprehension_has_value(stm) then
|
||||||
|
@ -528,11 +528,17 @@ default_accumulator = (node) =>
|
|||||||
|
|
||||||
|
|
||||||
implicitly_return = (scope) ->
|
implicitly_return = (scope) ->
|
||||||
|
is_top = true
|
||||||
fn = (stm) ->
|
fn = (stm) ->
|
||||||
t = ntype stm
|
t = ntype stm
|
||||||
if types.manual_return[t] or not types.is_value 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] == ""
|
||||||
|
nil
|
||||||
|
else
|
||||||
stm
|
stm
|
||||||
elseif types.cascading[t]
|
elseif types.cascading[t]
|
||||||
|
is_top = false
|
||||||
scope.transform.statement stm, fn
|
scope.transform.statement stm, fn
|
||||||
else
|
else
|
||||||
if t == "comprehension" and not types.comprehension_has_value stm
|
if t == "comprehension" and not types.comprehension_has_value stm
|
||||||
|
@ -94,9 +94,7 @@ _ = function(self, x, y, z)
|
|||||||
end
|
end
|
||||||
self.x, self.z = x, z
|
self.x, self.z = x, z
|
||||||
end
|
end
|
||||||
x(function()
|
x(function() end)
|
||||||
return
|
|
||||||
end)
|
|
||||||
y(function()
|
y(function()
|
||||||
return 1
|
return 1
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user