extract declarations doesn't puke on nil statement in body

This commit is contained in:
leaf corcoran 2013-01-23 18:02:21 -08:00
parent af2c443807
commit c9b121c046
4 changed files with 39 additions and 13 deletions

View File

@ -99,19 +99,31 @@ extract_declarations = function(self, body, start, out)
out = { }
end
for i = start, #body do
local stm = self.transform.statement(body[i])
body[i] = stm
local _exp_0 = stm[1]
if "assign" == _exp_0 or "declare" == _exp_0 then
local _list_0 = stm[2]
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
if type(name) == "string" then
insert(out, name)
end
local _continue_0 = false
repeat
local stm = body[i]
if stm == nil then
_continue_0 = true
break
end
elseif "group" == _exp_0 then
extract_declarations(self, stm[2], 1, out)
stm = self.transform.statement(stm)
body[i] = stm
local _exp_0 = stm[1]
if "assign" == _exp_0 or "declare" == _exp_0 then
local _list_0 = stm[2]
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
if type(name) == "string" then
insert(out, name)
end
end
elseif "group" == _exp_0 then
extract_declarations(self, stm[2], 1, out)
end
_continue_0 = true
until true
if not _continue_0 then
break
end
end
return out

View File

@ -47,7 +47,9 @@ is_singular = (body) ->
-- this mutates body searching for assigns
extract_declarations = (body=@current_stms, start=@current_stm_i + 1, out={}) =>
for i=start,#body
stm = @transform.statement body[i]
stm = body[i]
continue if stm == nil
stm = @transform.statement stm
body[i] = stm
switch stm[1]
when "assign", "declare"

View File

@ -75,4 +75,9 @@ do
d = 2323
do
local *
-- this generates a nil value in the body
for a in *{} do a
g = 2323 -- test if anything leaked

View File

@ -70,4 +70,11 @@ do
d = 200
d = 2323
end
do
local _list_0 = { }
for _index_0 = 1, #_list_0 do
local a = _list_0[_index_0]
local _ = a
end
end
local g = 2323