diff --git a/moonscript/compile.moon b/moonscript/compile.moon index ed480f1..2062310 100644 --- a/moonscript/compile.moon +++ b/moonscript/compile.moon @@ -82,6 +82,9 @@ class Block_ has_name: (name) => @_names[name] + shadow_name: (name) => + @_names[name] = false + free_name: (prefix, dont_put) => prefix = prefix or "moon" searching = true diff --git a/moonscript/compile/line.moon b/moonscript/compile/line.moon index 02e16f1..123e0b2 100644 --- a/moonscript/compile/line.moon +++ b/moonscript/compile/line.moon @@ -177,6 +177,7 @@ line_compile = \stm {"assign", {items_tmp}, {iter}} block = [s for s in *block] + \shadow_name name for name in *names insert block, 1, {"assign", names, { {"chain", items_tmp, {"index", index_tmp}} }} diff --git a/tests/outputs/lists.lua b/tests/outputs/lists.lua index 92608a8..dce68b5 100644 --- a/tests/outputs/lists.lua +++ b/tests/outputs/lists.lua @@ -152,7 +152,7 @@ local double = (function() do local _item_0 = items for _index_0 = 1, #_item_0 do - x = _item_0[_index_0] + local x = _item_0[_index_0] table.insert(_accum_0, x * 2) end end @@ -161,7 +161,7 @@ end)() do local _item_0 = double for _index_0 = 1, #_item_0 do - x = _item_0[_index_0] + local x = _item_0[_index_0] print(x) end end @@ -170,7 +170,7 @@ local cut = (function() do local _item_0 = items for _index_0 = 1, #_item_0 do - x = _item_0[_index_0] + local x = _item_0[_index_0] if x > 3 then table.insert(_accum_0, x) end @@ -183,7 +183,7 @@ local hello = (function() do local _item_0 = items for _index_0 = 1, #_item_0 do - x = _item_0[_index_0] + local x = _item_0[_index_0] do local _item_1 = items for _index_1 = 1, #_item_1 do