mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
assignment declaration is pulled out of line decorators #44
This commit is contained in:
parent
e1f31d9e8d
commit
063b50a38f
@ -551,6 +551,7 @@ Statement = Transformer({
|
||||
end,
|
||||
decorated = function(self, node)
|
||||
local stm, dec = unpack(node, 2)
|
||||
local wrapped
|
||||
local _exp_0 = dec[1]
|
||||
if "if" == _exp_0 then
|
||||
local cond, fail = unpack(dec, 2)
|
||||
@ -562,7 +563,7 @@ Statement = Transformer({
|
||||
}
|
||||
}
|
||||
end
|
||||
return {
|
||||
wrapped = {
|
||||
"if",
|
||||
cond,
|
||||
{
|
||||
@ -571,7 +572,7 @@ Statement = Transformer({
|
||||
fail
|
||||
}
|
||||
elseif "unless" == _exp_0 then
|
||||
return {
|
||||
wrapped = {
|
||||
"unless",
|
||||
dec[2],
|
||||
{
|
||||
@ -579,14 +580,35 @@ Statement = Transformer({
|
||||
}
|
||||
}
|
||||
elseif "comprehension" == _exp_0 then
|
||||
return {
|
||||
wrapped = {
|
||||
"comprehension",
|
||||
stm,
|
||||
dec[2]
|
||||
}
|
||||
else
|
||||
return error("Unknown decorator " .. dec[1])
|
||||
wrapped = error("Unknown decorator " .. dec[1])
|
||||
end
|
||||
if ntype(stm) == "assign" then
|
||||
wrapped = build.group({
|
||||
build.declare({
|
||||
names = (function()
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 0
|
||||
local _list_0 = stm[2]
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local name = _list_0[_index_0]
|
||||
if type(name) == "string" then
|
||||
_len_0 = _len_0 + 1
|
||||
_accum_0[_len_0] = name
|
||||
end
|
||||
end
|
||||
return _accum_0
|
||||
end)()
|
||||
}),
|
||||
wrapped
|
||||
})
|
||||
end
|
||||
return wrapped
|
||||
end,
|
||||
unless = function(self, node)
|
||||
return {
|
||||
|
@ -247,7 +247,7 @@ Statement = Transformer {
|
||||
decorated: (node) =>
|
||||
stm, dec = unpack node, 2
|
||||
|
||||
switch dec[1]
|
||||
wrapped = switch dec[1]
|
||||
when "if"
|
||||
cond, fail = unpack dec, 2
|
||||
fail = { "else", { fail } } if fail
|
||||
@ -259,6 +259,14 @@ Statement = Transformer {
|
||||
else
|
||||
error "Unknown decorator " .. dec[1]
|
||||
|
||||
if ntype(stm) == "assign"
|
||||
wrapped = build.group {
|
||||
build.declare names: [name for name in *stm[2] when type(name) == "string"]
|
||||
wrapped
|
||||
}
|
||||
|
||||
wrapped
|
||||
|
||||
unless: (node) =>
|
||||
{ "if", {"not", {"parens", node[2]}}, unpack node, 3 }
|
||||
|
||||
|
@ -113,10 +113,10 @@ x = unless true
|
||||
x = unless true and false
|
||||
print "cool!"
|
||||
|
||||
x = unless false then print "cool!"
|
||||
x = unless false then print "cool!" else print "no way!"
|
||||
y = unless false then print "cool!"
|
||||
y = unless false then print "cool!" else print "no way!"
|
||||
|
||||
x = unless nil
|
||||
z = unless nil
|
||||
print "hello"
|
||||
else
|
||||
print "world"
|
||||
@ -141,4 +141,10 @@ print "hello" unless value
|
||||
|
||||
dddd = {1,2,3} unless value
|
||||
|
||||
----------------
|
||||
|
||||
a = 12
|
||||
a,c,b = "cool" if something
|
||||
|
||||
|
||||
|
||||
|
@ -176,18 +176,19 @@ end
|
||||
if not (true and false) then
|
||||
x = print("cool!")
|
||||
end
|
||||
local y
|
||||
if not (false) then
|
||||
x = print("cool!")
|
||||
y = print("cool!")
|
||||
end
|
||||
if not (false) then
|
||||
x = print("cool!")
|
||||
y = print("cool!")
|
||||
else
|
||||
x = print("no way!")
|
||||
y = print("no way!")
|
||||
end
|
||||
if not (nil) then
|
||||
x = print("hello")
|
||||
z = print("hello")
|
||||
else
|
||||
x = print("world")
|
||||
z = print("world")
|
||||
end
|
||||
print((function()
|
||||
if not (true) then
|
||||
@ -221,10 +222,16 @@ end)())
|
||||
if not (value) then
|
||||
print("hello")
|
||||
end
|
||||
local dddd
|
||||
if not (value) then
|
||||
local dddd = {
|
||||
dddd = {
|
||||
1,
|
||||
2,
|
||||
3
|
||||
}
|
||||
end
|
||||
local a = 12
|
||||
local c, b
|
||||
if something then
|
||||
a, c, b = "cool"
|
||||
end
|
Loading…
Reference in New Issue
Block a user