make mtype not error when passed smart node fix #52

fixes error when returning if/elseif assignment block
This commit is contained in:
leaf corcoran 2012-11-27 18:35:07 -08:00
parent 48662adc3b
commit 3adaed672e
4 changed files with 45 additions and 4 deletions

View File

@ -5,7 +5,18 @@ local data = require("moonscript.data")
local reversed = util.reversed
local ntype, build, smart_node, is_slice, value_is_singular = types.ntype, types.build, types.smart_node, types.is_slice, types.value_is_singular
local insert = table.insert
local mtype = util.moon.type
local mtype
do
local moon_type = util.moon.type
mtype = function(val)
local t = type(val)
if "table" == t and rawget(val, "__class") then
return moon_type(val)
else
return t
end
end
end
local implicitly_return
do
local _parent_0 = nil
@ -182,7 +193,7 @@ apply_to_last = function(stms, fn)
local last_exp_id = 0
for i = #stms, 1, -1 do
local stm = stms[i]
if stm and util.moon.type(stm) ~= Run then
if stm and mtype(stm) ~= Run then
last_exp_id = i
break
end

View File

@ -9,7 +9,15 @@ import reversed from util
import ntype, build, smart_node, is_slice, value_is_singular from types
import insert from table
mtype = util.moon.type
mtype = do
moon_type = util.moon.type
-- lets us check a smart node without throwing an error
(val) ->
t = type(val)
if "table" == t and rawget(val, "__class")
moon_type val
else
t
export Statement, Value, NameProxy, LocalName, Run
@ -67,7 +75,7 @@ apply_to_last = (stms, fn) ->
last_exp_id = 0
for i = #stms, 1, -1
stm = stms[i]
if stm and util.moon.type(stm) != Run
if stm and mtype(stm) != Run
last_exp_id = i
break

View File

@ -89,6 +89,12 @@ elseif z = true
else
four
kzy = ->
if something = true
1
elseif another = false
2
---
unless true

View File

@ -150,6 +150,22 @@ else
end
end
end
local kzy
kzy = function()
do
local something = true
if something then
return 1
else
do
local another = false
if another then
return 2
end
end
end
end
end
if not (true) then
print("cool!")
end