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,
|
end,
|
||||||
decorated = function(self, node)
|
decorated = function(self, node)
|
||||||
local stm, dec = unpack(node, 2)
|
local stm, dec = unpack(node, 2)
|
||||||
|
local wrapped
|
||||||
local _exp_0 = dec[1]
|
local _exp_0 = dec[1]
|
||||||
if "if" == _exp_0 then
|
if "if" == _exp_0 then
|
||||||
local cond, fail = unpack(dec, 2)
|
local cond, fail = unpack(dec, 2)
|
||||||
@ -562,7 +563,7 @@ Statement = Transformer({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
return {
|
wrapped = {
|
||||||
"if",
|
"if",
|
||||||
cond,
|
cond,
|
||||||
{
|
{
|
||||||
@ -571,7 +572,7 @@ Statement = Transformer({
|
|||||||
fail
|
fail
|
||||||
}
|
}
|
||||||
elseif "unless" == _exp_0 then
|
elseif "unless" == _exp_0 then
|
||||||
return {
|
wrapped = {
|
||||||
"unless",
|
"unless",
|
||||||
dec[2],
|
dec[2],
|
||||||
{
|
{
|
||||||
@ -579,14 +580,35 @@ Statement = Transformer({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif "comprehension" == _exp_0 then
|
elseif "comprehension" == _exp_0 then
|
||||||
return {
|
wrapped = {
|
||||||
"comprehension",
|
"comprehension",
|
||||||
stm,
|
stm,
|
||||||
dec[2]
|
dec[2]
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return error("Unknown decorator " .. dec[1])
|
wrapped = error("Unknown decorator " .. dec[1])
|
||||||
end
|
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,
|
end,
|
||||||
unless = function(self, node)
|
unless = function(self, node)
|
||||||
return {
|
return {
|
||||||
|
@ -247,7 +247,7 @@ Statement = Transformer {
|
|||||||
decorated: (node) =>
|
decorated: (node) =>
|
||||||
stm, dec = unpack node, 2
|
stm, dec = unpack node, 2
|
||||||
|
|
||||||
switch dec[1]
|
wrapped = switch dec[1]
|
||||||
when "if"
|
when "if"
|
||||||
cond, fail = unpack dec, 2
|
cond, fail = unpack dec, 2
|
||||||
fail = { "else", { fail } } if fail
|
fail = { "else", { fail } } if fail
|
||||||
@ -259,6 +259,14 @@ Statement = Transformer {
|
|||||||
else
|
else
|
||||||
error "Unknown decorator " .. dec[1]
|
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) =>
|
unless: (node) =>
|
||||||
{ "if", {"not", {"parens", node[2]}}, unpack node, 3 }
|
{ "if", {"not", {"parens", node[2]}}, unpack node, 3 }
|
||||||
|
|
||||||
|
@ -113,10 +113,10 @@ x = unless true
|
|||||||
x = unless true and false
|
x = unless true and false
|
||||||
print "cool!"
|
print "cool!"
|
||||||
|
|
||||||
x = unless false then print "cool!"
|
y = unless false then print "cool!"
|
||||||
x = unless false then print "cool!" else print "no way!"
|
y = unless false then print "cool!" else print "no way!"
|
||||||
|
|
||||||
x = unless nil
|
z = unless nil
|
||||||
print "hello"
|
print "hello"
|
||||||
else
|
else
|
||||||
print "world"
|
print "world"
|
||||||
@ -141,4 +141,10 @@ print "hello" unless value
|
|||||||
|
|
||||||
dddd = {1,2,3} 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
|
if not (true and false) then
|
||||||
x = print("cool!")
|
x = print("cool!")
|
||||||
end
|
end
|
||||||
|
local y
|
||||||
if not (false) then
|
if not (false) then
|
||||||
x = print("cool!")
|
y = print("cool!")
|
||||||
end
|
end
|
||||||
if not (false) then
|
if not (false) then
|
||||||
x = print("cool!")
|
y = print("cool!")
|
||||||
else
|
else
|
||||||
x = print("no way!")
|
y = print("no way!")
|
||||||
end
|
end
|
||||||
if not (nil) then
|
if not (nil) then
|
||||||
x = print("hello")
|
z = print("hello")
|
||||||
else
|
else
|
||||||
x = print("world")
|
z = print("world")
|
||||||
end
|
end
|
||||||
print((function()
|
print((function()
|
||||||
if not (true) then
|
if not (true) then
|
||||||
@ -221,10 +222,16 @@ end)())
|
|||||||
if not (value) then
|
if not (value) then
|
||||||
print("hello")
|
print("hello")
|
||||||
end
|
end
|
||||||
|
local dddd
|
||||||
if not (value) then
|
if not (value) then
|
||||||
local dddd = {
|
dddd = {
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3
|
3
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
local a = 12
|
||||||
|
local c, b
|
||||||
|
if something then
|
||||||
|
a, c, b = "cool"
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user