mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
allow assignment in unless
block, fixes #251
This commit is contained in:
parent
dfc4f7b016
commit
c19a7fd2c3
@ -484,17 +484,35 @@ return Transformer({
|
||||
return wrapped
|
||||
end,
|
||||
unless = function(self, node)
|
||||
local clause = node[2]
|
||||
if ntype(clause) == "assign" then
|
||||
if destructure.has_destructure(clause[2]) then
|
||||
error("destructure not allowed in unless assignment")
|
||||
end
|
||||
return build["do"]({
|
||||
clause,
|
||||
{
|
||||
"if",
|
||||
{
|
||||
"not",
|
||||
clause[2][1]
|
||||
},
|
||||
unpack(node, 3)
|
||||
}
|
||||
})
|
||||
else
|
||||
return {
|
||||
"if",
|
||||
{
|
||||
"not",
|
||||
{
|
||||
"parens",
|
||||
node[2]
|
||||
clause
|
||||
}
|
||||
},
|
||||
unpack(node, 3)
|
||||
}
|
||||
end
|
||||
end,
|
||||
["if"] = function(self, node, ret)
|
||||
if ntype(node[2]) == "assign" then
|
||||
|
@ -280,7 +280,19 @@ Transformer {
|
||||
wrapped
|
||||
|
||||
unless: (node) =>
|
||||
{ "if", {"not", {"parens", node[2]}}, unpack node, 3 }
|
||||
clause = node[2]
|
||||
|
||||
if ntype(clause) == "assign"
|
||||
if destructure.has_destructure clause[2]
|
||||
error "destructure not allowed in unless assignment"
|
||||
|
||||
build.do {
|
||||
clause
|
||||
{ "if", {"not", clause[2][1]}, unpack node, 3 }
|
||||
}
|
||||
|
||||
else
|
||||
{ "if", {"not", {"parens", clause}}, unpack node, 3 }
|
||||
|
||||
if: (node, ret) =>
|
||||
-- expand assign in cond
|
||||
@ -300,7 +312,7 @@ Transformer {
|
||||
}
|
||||
else
|
||||
name = assign[2][1]
|
||||
return build["do"] {
|
||||
return build.do {
|
||||
assign
|
||||
{"if", name, unpack node, 3}
|
||||
}
|
||||
|
@ -147,6 +147,14 @@ print "hello" unless value
|
||||
|
||||
dddd = {1,2,3} unless value
|
||||
|
||||
|
||||
--
|
||||
|
||||
do
|
||||
j = 100
|
||||
unless j = hi!
|
||||
error "not j!"
|
||||
|
||||
----------------
|
||||
|
||||
a = 12
|
||||
|
@ -246,6 +246,15 @@ if not (value) then
|
||||
3
|
||||
}
|
||||
end
|
||||
do
|
||||
local j = 100
|
||||
do
|
||||
j = hi()
|
||||
if not j then
|
||||
error("not j!")
|
||||
end
|
||||
end
|
||||
end
|
||||
local a = 12
|
||||
local c, b
|
||||
if something then
|
||||
|
Loading…
Reference in New Issue
Block a user