mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
add implicit return to end of files #46
This commit is contained in:
parent
19a8047618
commit
1be72f57b7
@ -586,6 +586,14 @@ RootBlock = (function()
|
||||
__tostring = function(self)
|
||||
return "RootBlock<>"
|
||||
end,
|
||||
root_stms = function(self, stms)
|
||||
stms = transform.Statement.transformers.root_stms(self, stms)
|
||||
local _list_0 = stms
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local s = _list_0[_index_0]
|
||||
self:stm(s)
|
||||
end
|
||||
end,
|
||||
render = function(self)
|
||||
local buffer = self._lines:flatten()
|
||||
if buffer[#buffer] == "\n" then
|
||||
@ -652,11 +660,7 @@ tree = function(tree, scope)
|
||||
end
|
||||
assert(tree, "missing tree")
|
||||
local runner = coroutine.create(function()
|
||||
local _list_0 = tree
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local line = _list_0[_index_0]
|
||||
scope:stm(line)
|
||||
end
|
||||
return scope:root_stms(tree)
|
||||
end)
|
||||
local success, err = coroutine.resume(runner)
|
||||
if not success then
|
||||
|
@ -346,6 +346,10 @@ class RootBlock extends Block
|
||||
|
||||
__tostring: => "RootBlock<>"
|
||||
|
||||
root_stms: (stms) =>
|
||||
stms = transform.Statement.transformers.root_stms self, stms
|
||||
@stm s for s in *stms
|
||||
|
||||
render: =>
|
||||
-- print @_lines
|
||||
buffer = @_lines\flatten!
|
||||
@ -372,7 +376,7 @@ tree = (tree, scope=RootBlock!) ->
|
||||
assert tree, "missing tree"
|
||||
|
||||
runner = coroutine.create ->
|
||||
scope\stm line for line in *tree
|
||||
scope\root_stms tree
|
||||
|
||||
success, err = coroutine.resume runner
|
||||
if not success
|
||||
|
@ -5,6 +5,7 @@ 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 implicitly_return
|
||||
LocalName = (function()
|
||||
local _parent_0 = nil
|
||||
local _base_0 = {
|
||||
@ -443,6 +444,9 @@ construct_comprehension = function(inner, clauses)
|
||||
return current_stms[1]
|
||||
end
|
||||
Statement = Transformer({
|
||||
root_stms = function(self, body)
|
||||
return apply_to_last(body, implicitly_return(self))
|
||||
end,
|
||||
assign = function(self, node)
|
||||
local names, values = unpack(node, 2)
|
||||
local transformed
|
||||
@ -1329,7 +1333,6 @@ local default_accumulator
|
||||
default_accumulator = function(self, node)
|
||||
return Accumulator():convert(node)
|
||||
end
|
||||
local implicitly_return
|
||||
implicitly_return = function(scope)
|
||||
local is_top = true
|
||||
local fn
|
||||
|
@ -11,6 +11,8 @@ import insert from table
|
||||
|
||||
export Statement, Value, NameProxy, LocalName, Run
|
||||
|
||||
local implicitly_return
|
||||
|
||||
-- always declares as local
|
||||
class LocalName
|
||||
new: (@name) => self[1] = "temp_name"
|
||||
@ -186,6 +188,9 @@ construct_comprehension = (inner, clauses) ->
|
||||
current_stms[1]
|
||||
|
||||
Statement = Transformer {
|
||||
root_stms: (body) =>
|
||||
apply_to_last body, implicitly_return @
|
||||
|
||||
assign: (node) =>
|
||||
names, values = unpack node, 2
|
||||
-- bubble cascading assigns
|
||||
@ -679,7 +684,6 @@ class Accumulator
|
||||
default_accumulator = (node) =>
|
||||
Accumulator!\convert node
|
||||
|
||||
|
||||
implicitly_return = (scope) ->
|
||||
is_top = true
|
||||
fn = (stm) ->
|
||||
|
@ -589,4 +589,4 @@ Whacko = (function()
|
||||
end
|
||||
return _class_0
|
||||
end)()
|
||||
print("hello")
|
||||
return print("hello")
|
@ -52,7 +52,7 @@ _ = (function()
|
||||
end
|
||||
return _tbl_0
|
||||
end)()
|
||||
_ = (function()
|
||||
return (function()
|
||||
local _tbl_0 = { }
|
||||
local _list_0 = {
|
||||
{
|
||||
|
@ -69,4 +69,5 @@ end
|
||||
do
|
||||
local _with_0 = tmp
|
||||
local j = 2000
|
||||
return _with_0
|
||||
end
|
@ -108,7 +108,7 @@ k(function()
|
||||
return
|
||||
end
|
||||
end)
|
||||
_ = function()
|
||||
return function()
|
||||
if something then
|
||||
return real_name
|
||||
end
|
||||
|
@ -286,7 +286,7 @@ _ = function()
|
||||
_ = x
|
||||
end
|
||||
end
|
||||
_ = function()
|
||||
return function()
|
||||
return (function()
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 0
|
||||
|
@ -11,4 +11,4 @@ _ = [[ hello world ]]
|
||||
_ = [=[ hello world ]=]
|
||||
_ = [====[ hello world ]====]
|
||||
_ = "another world"
|
||||
_ = 'what world'
|
||||
return 'what world'
|
@ -34,4 +34,4 @@ local _ = "hello"
|
||||
("hello"):format().hello(1, 2, 3);
|
||||
("hello"):format(1, 2, 3)
|
||||
something("hello"):world()
|
||||
something(("hello"):world())
|
||||
return something(("hello"):world())
|
@ -43,7 +43,7 @@ do
|
||||
end
|
||||
end
|
||||
fix(this)
|
||||
call_func((function()
|
||||
return call_func((function()
|
||||
local _exp_5 = something
|
||||
if 1 == _exp_5 then
|
||||
return "yes"
|
||||
|
@ -12,7 +12,7 @@ _ = function(a, b, c)
|
||||
a, b, c = 1, 2, 3
|
||||
local world = 12321
|
||||
end
|
||||
_ = function(a, e, f)
|
||||
return function(a, e, f)
|
||||
local b, c
|
||||
a, b, c = 1, 2, 3
|
||||
hello = 12321
|
||||
|
@ -72,5 +72,5 @@ if hello(1, 2, 3, world, world) then
|
||||
print("hello")
|
||||
end
|
||||
if hello(1, 2, 3, world, world) then
|
||||
print("hello")
|
||||
return print("hello")
|
||||
end
|
@ -45,4 +45,5 @@ do
|
||||
local _ = _with_0:prop("something").hello
|
||||
_with_0.prop:send(one)
|
||||
_with_0.prop:send(one)
|
||||
return _with_0
|
||||
end
|
Loading…
Reference in New Issue
Block a user