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