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
|
||||
return "[", self:value(arg), "]"
|
||||
elseif t == "dot" then
|
||||
return ".", arg
|
||||
return ".", self:value(arg)
|
||||
elseif t == "colon" then
|
||||
return ":", arg, chain_item(node[3])
|
||||
elseif t == "colon_stub" then
|
||||
|
@ -66,7 +66,7 @@ value_compile =
|
||||
elseif t == "index"
|
||||
"[", @value(arg), "]"
|
||||
elseif t == "dot"
|
||||
".", arg
|
||||
".", @value arg
|
||||
elseif t == "colon"
|
||||
":", arg, chain_item(node[3])
|
||||
elseif t == "colon_stub"
|
||||
|
@ -672,13 +672,15 @@ Statement = Transformer({
|
||||
"chain",
|
||||
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")
|
||||
slice[1] = {
|
||||
"call",
|
||||
{
|
||||
"self",
|
||||
unpack(slice[1][2])
|
||||
unpack(head[2])
|
||||
}
|
||||
}
|
||||
local act
|
||||
@ -691,6 +693,19 @@ Statement = Transformer({
|
||||
act,
|
||||
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
|
||||
local _list_0 = slice
|
||||
for _index_0 = 1, #_list_0 do
|
||||
|
@ -372,13 +372,21 @@ Statement = Transformer {
|
||||
slice = [item for item in *chain[3,]]
|
||||
new_chain = {"chain", parent_cls_name}
|
||||
|
||||
head = slice[1]
|
||||
switch head[1]
|
||||
-- calling super, inject calling name and self into chain
|
||||
if slice[1][1] == "call"
|
||||
when "call"
|
||||
calling_name = block\get"current_block"
|
||||
slice[1] = {"call", {"self", unpack slice[1][2]}}
|
||||
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
|
||||
|
||||
new_chain
|
||||
|
@ -51,3 +51,8 @@ class Biggie extends Okay
|
||||
super.something another_self, 1,2,3,4
|
||||
assert super == Okay
|
||||
|
||||
|
||||
class Yeah
|
||||
okay: =>
|
||||
super\something 1,2,3,4
|
||||
|
||||
|
@ -200,3 +200,32 @@ Biggie = (function()
|
||||
_base_0.__class = _class_0
|
||||
return _class_0
|
||||
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