mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
colon_stub
on super will pass self as receiver
This commit is contained in:
parent
cd5087b08b
commit
5c999fb680
@ -96,6 +96,9 @@ Block = (function()
|
||||
footer = "end",
|
||||
export_all = false,
|
||||
export_proper = false,
|
||||
__tostring = function(self)
|
||||
return "Block<> <- " .. tostring(self.parent)
|
||||
end,
|
||||
bubble = function(self, other)
|
||||
if other == nil then
|
||||
other = self.parent
|
||||
|
@ -55,6 +55,8 @@ class Block
|
||||
export_all: false
|
||||
export_proper: false
|
||||
|
||||
__tostring: => "Block<> <- " .. tostring @parent
|
||||
|
||||
new: (@parent, @header, @footer) =>
|
||||
@current_line = 1
|
||||
|
||||
|
@ -673,6 +673,9 @@ Statement = Transformer({
|
||||
parent_cls_name
|
||||
}
|
||||
local head = slice[1]
|
||||
if head == nil then
|
||||
return parent_cls_name
|
||||
end
|
||||
local _exp_0 = head[1]
|
||||
if "call" == _exp_0 then
|
||||
local calling_name = block:get("current_block")
|
||||
@ -940,6 +943,7 @@ Value = Transformer({
|
||||
table.remove(node, #node)
|
||||
local base_name = NameProxy("base")
|
||||
local fn_name = NameProxy("fn")
|
||||
local is_super = node[2] == "super"
|
||||
return self.transform.value(build.block_exp({
|
||||
build.assign({
|
||||
names = {
|
||||
@ -975,7 +979,7 @@ Value = Transformer({
|
||||
{
|
||||
"call",
|
||||
{
|
||||
base_name,
|
||||
is_super and "self" or base_name,
|
||||
"..."
|
||||
}
|
||||
}
|
||||
|
@ -373,6 +373,10 @@ Statement = Transformer {
|
||||
new_chain = {"chain", parent_cls_name}
|
||||
|
||||
head = slice[1]
|
||||
|
||||
if head == nil
|
||||
return parent_cls_name
|
||||
|
||||
switch head[1]
|
||||
-- calling super, inject calling name and self into chain
|
||||
when "call"
|
||||
@ -539,6 +543,7 @@ Value = Transformer {
|
||||
base_name = NameProxy "base"
|
||||
fn_name = NameProxy "fn"
|
||||
|
||||
is_super = node[2] == "super"
|
||||
@transform.value build.block_exp {
|
||||
build.assign {
|
||||
names: {base_name}
|
||||
@ -556,7 +561,7 @@ Value = Transformer {
|
||||
args: {{"..."}}
|
||||
body: {
|
||||
build.chain {
|
||||
base: fn_name, {"call", {base_name, "..."}}
|
||||
base: fn_name, {"call", {is_super and "self" or base_name, "..."}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,3 +56,16 @@ class Yeah
|
||||
okay: =>
|
||||
super\something 1,2,3,4
|
||||
|
||||
|
||||
class What
|
||||
something: => print "val:", @val
|
||||
|
||||
class Hello extends What
|
||||
val: 2323
|
||||
something: => super\something
|
||||
|
||||
with Hello!
|
||||
x = \something!
|
||||
print x
|
||||
x!
|
||||
|
||||
|
@ -228,4 +228,74 @@ Yeah = (function()
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
return _class_0
|
||||
end)()
|
||||
end)()
|
||||
local What
|
||||
What = (function()
|
||||
local _parent_0 = nil
|
||||
local _base_0 = {
|
||||
something = function(self)
|
||||
return print("val:", self.val)
|
||||
end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
if _parent_0 then
|
||||
setmetatable(_base_0, getmetatable(_parent_0).__index)
|
||||
end
|
||||
local _class_0 = setmetatable({
|
||||
__init = function(self, ...)
|
||||
if _parent_0 then
|
||||
return _parent_0.__init(self, ...)
|
||||
end
|
||||
end
|
||||
}, {
|
||||
__index = _base_0,
|
||||
__call = function(cls, ...)
|
||||
local _self_0 = setmetatable({}, _base_0)
|
||||
cls.__init(_self_0, ...)
|
||||
return _self_0
|
||||
end
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
return _class_0
|
||||
end)()
|
||||
Hello = (function()
|
||||
local _parent_0 = What
|
||||
local _base_0 = {
|
||||
val = 2323,
|
||||
something = function(self)
|
||||
return (function()
|
||||
local _base_1 = _parent_0
|
||||
local _fn_0 = _base_1.something
|
||||
return function(...)
|
||||
return _fn_0(self, ...)
|
||||
end
|
||||
end)()
|
||||
end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
if _parent_0 then
|
||||
setmetatable(_base_0, getmetatable(_parent_0).__index)
|
||||
end
|
||||
local _class_0 = setmetatable({
|
||||
__init = function(self, ...)
|
||||
if _parent_0 then
|
||||
return _parent_0.__init(self, ...)
|
||||
end
|
||||
end
|
||||
}, {
|
||||
__index = _base_0,
|
||||
__call = function(cls, ...)
|
||||
local _self_0 = setmetatable({}, _base_0)
|
||||
cls.__init(_self_0, ...)
|
||||
return _self_0
|
||||
end
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
return _class_0
|
||||
end)()
|
||||
do
|
||||
local _with_0 = Hello()
|
||||
x = _with_0:something()
|
||||
print(x)
|
||||
x()
|
||||
end
|
Loading…
Reference in New Issue
Block a user