mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
calling function of super with \ uses self instead of class as first arg
This commit is contained in:
parent
6a07d50277
commit
fc72baf423
@ -109,7 +109,7 @@ value_compile = {
|
|||||||
elseif t == "index" then
|
elseif t == "index" then
|
||||||
return "[", self:value(arg), "]"
|
return "[", self:value(arg), "]"
|
||||||
elseif t == "dot" then
|
elseif t == "dot" then
|
||||||
return ".", arg
|
return ".", self:value(arg)
|
||||||
elseif t == "colon" then
|
elseif t == "colon" then
|
||||||
return ":", arg, chain_item(node[3])
|
return ":", arg, chain_item(node[3])
|
||||||
elseif t == "colon_stub" then
|
elseif t == "colon_stub" then
|
||||||
|
@ -66,7 +66,7 @@ value_compile =
|
|||||||
elseif t == "index"
|
elseif t == "index"
|
||||||
"[", @value(arg), "]"
|
"[", @value(arg), "]"
|
||||||
elseif t == "dot"
|
elseif t == "dot"
|
||||||
".", arg
|
".", @value arg
|
||||||
elseif t == "colon"
|
elseif t == "colon"
|
||||||
":", arg, chain_item(node[3])
|
":", arg, chain_item(node[3])
|
||||||
elseif t == "colon_stub"
|
elseif t == "colon_stub"
|
||||||
|
@ -672,13 +672,15 @@ Statement = Transformer({
|
|||||||
"chain",
|
"chain",
|
||||||
parent_cls_name
|
parent_cls_name
|
||||||
}
|
}
|
||||||
if slice[1][1] == "call" then
|
local head = slice[1]
|
||||||
|
local _exp_0 = head[1]
|
||||||
|
if "call" == _exp_0 then
|
||||||
local calling_name = block:get("current_block")
|
local calling_name = block:get("current_block")
|
||||||
slice[1] = {
|
slice[1] = {
|
||||||
"call",
|
"call",
|
||||||
{
|
{
|
||||||
"self",
|
"self",
|
||||||
unpack(slice[1][2])
|
unpack(head[2])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local act
|
local act
|
||||||
@ -691,6 +693,19 @@ Statement = Transformer({
|
|||||||
act,
|
act,
|
||||||
calling_name
|
calling_name
|
||||||
})
|
})
|
||||||
|
elseif "colon" == _exp_0 then
|
||||||
|
local call = head[3]
|
||||||
|
insert(new_chain, {
|
||||||
|
"dot",
|
||||||
|
head[2]
|
||||||
|
})
|
||||||
|
slice[1] = {
|
||||||
|
"call",
|
||||||
|
{
|
||||||
|
"self",
|
||||||
|
unpack(call[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
local _list_0 = slice
|
local _list_0 = slice
|
||||||
for _index_0 = 1, #_list_0 do
|
for _index_0 = 1, #_list_0 do
|
||||||
|
@ -372,12 +372,20 @@ Statement = Transformer {
|
|||||||
slice = [item for item in *chain[3,]]
|
slice = [item for item in *chain[3,]]
|
||||||
new_chain = {"chain", parent_cls_name}
|
new_chain = {"chain", parent_cls_name}
|
||||||
|
|
||||||
-- calling super, inject calling name and self into chain
|
head = slice[1]
|
||||||
if slice[1][1] == "call"
|
switch head[1]
|
||||||
calling_name = block\get"current_block"
|
-- calling super, inject calling name and self into chain
|
||||||
slice[1] = {"call", {"self", unpack slice[1][2]}}
|
when "call"
|
||||||
act = if ntype(calling_name) != "value" then "index" else "dot"
|
calling_name = block\get"current_block"
|
||||||
insert new_chain, {act, calling_name}
|
slice[1] = {"call", {"self", unpack head[2]}}
|
||||||
|
act = if ntype(calling_name) != "value" then "index" else "dot"
|
||||||
|
insert new_chain, {act, calling_name}
|
||||||
|
|
||||||
|
-- colon call on super, replace class with self as first arg
|
||||||
|
when "colon"
|
||||||
|
call = head[3]
|
||||||
|
insert new_chain, {"dot", head[2]}
|
||||||
|
slice[1] = { "call", { "self", unpack call[2] } }
|
||||||
|
|
||||||
insert new_chain, item for item in *slice
|
insert new_chain, item for item in *slice
|
||||||
|
|
||||||
|
@ -51,3 +51,8 @@ class Biggie extends Okay
|
|||||||
super.something another_self, 1,2,3,4
|
super.something another_self, 1,2,3,4
|
||||||
assert super == Okay
|
assert super == Okay
|
||||||
|
|
||||||
|
|
||||||
|
class Yeah
|
||||||
|
okay: =>
|
||||||
|
super\something 1,2,3,4
|
||||||
|
|
||||||
|
@ -200,3 +200,32 @@ Biggie = (function()
|
|||||||
_base_0.__class = _class_0
|
_base_0.__class = _class_0
|
||||||
return _class_0
|
return _class_0
|
||||||
end)()
|
end)()
|
||||||
|
local Yeah
|
||||||
|
Yeah = (function()
|
||||||
|
local _parent_0 = nil
|
||||||
|
local _base_0 = {
|
||||||
|
okay = function(self)
|
||||||
|
return _parent_0.something(self, 1, 2, 3, 4)
|
||||||
|
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)()
|
Loading…
Reference in New Issue
Block a user