mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
fixed implicit return on statement and tmp values for chain calls
This commit is contained in:
parent
8fb80ee799
commit
1bea9f1402
@ -26,6 +26,13 @@ moonlib =
|
|||||||
|
|
||||||
cascading = Set{ "if" }
|
cascading = Set{ "if" }
|
||||||
|
|
||||||
|
-- does this always return a value
|
||||||
|
has_value = (node) ->
|
||||||
|
if ntype(node) == "chain"
|
||||||
|
ntype(node[#node]) != "call"
|
||||||
|
else
|
||||||
|
true
|
||||||
|
|
||||||
line_compile =
|
line_compile =
|
||||||
assign: (node) =>
|
assign: (node) =>
|
||||||
_, names, values = unpack node
|
_, names, values = unpack node
|
||||||
@ -394,12 +401,16 @@ B =
|
|||||||
concat [@value v for v in *values], delim
|
concat [@value v for v in *values], delim
|
||||||
|
|
||||||
stm: (node, ...) =>
|
stm: (node, ...) =>
|
||||||
fn = line_compile[node[1]]
|
fn = line_compile[ntype(node)]
|
||||||
if not fn
|
if not fn
|
||||||
return @stm {"assign", {"_"}, {node}}
|
-- coerce value into statement
|
||||||
|
if has_value node
|
||||||
out = fn self, node, ...
|
@stm {"assign", {"_"}, {node}}
|
||||||
@add_line out if out
|
else
|
||||||
|
@add_line @value node
|
||||||
|
else
|
||||||
|
out = fn self, node, ...
|
||||||
|
@add_line out if out
|
||||||
|
|
||||||
ret_stms: (stms, ret) =>
|
ret_stms: (stms, ret) =>
|
||||||
if not ret
|
if not ret
|
||||||
@ -411,15 +422,20 @@ B =
|
|||||||
@stm stms[i]
|
@stm stms[i]
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
if stms[i]
|
last_exp = stms[i]
|
||||||
if cascading[ntype(stms[i])]
|
|
||||||
@stm stms[i], ret
|
if last_exp
|
||||||
else
|
if cascading[ntype(last_exp)]
|
||||||
|
@stm last_exp, ret
|
||||||
|
elseif @is_value last_exp
|
||||||
line = ret stms[i]
|
line = ret stms[i]
|
||||||
if @is_stm line
|
if @is_stm line
|
||||||
@stm line
|
@stm line
|
||||||
else
|
else
|
||||||
@stm strms[i]
|
error "got a value from implicit return"
|
||||||
|
else
|
||||||
|
-- nothing we can do with a statement except show it
|
||||||
|
@stm last_exp
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user