mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
fixed super dot access, made super available as a value
This commit is contained in:
parent
68e209cd1f
commit
6a07d50277
@ -309,6 +309,9 @@ value_compile = {
|
||||
return "self:" .. self:value(node[2])
|
||||
end,
|
||||
raw_value = function(self, value)
|
||||
if value == "super" then
|
||||
return self:value(self:get("super")(self))
|
||||
end
|
||||
if value == "..." then
|
||||
self.has_varargs = true
|
||||
end
|
||||
|
@ -181,6 +181,10 @@ value_compile =
|
||||
|
||||
-- catch all pure string values
|
||||
raw_value: (value) =>
|
||||
if value == "super"
|
||||
return @value @get"super" self
|
||||
|
||||
if value == "..."
|
||||
@has_varargs = true
|
||||
|
||||
tostring value
|
||||
|
@ -656,40 +656,51 @@ Statement = Transformer({
|
||||
value = _with_0.block_exp({
|
||||
Run(function(self)
|
||||
return self:set("super", function(block, chain)
|
||||
local calling_name = block:get("current_block")
|
||||
local slice = (function()
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 0
|
||||
local _list_0 = chain
|
||||
for _index_0 = 3, #_list_0 do
|
||||
local item = _list_0[_index_0]
|
||||
_len_0 = _len_0 + 1
|
||||
_accum_0[_len_0] = item
|
||||
end
|
||||
return _accum_0
|
||||
end)()
|
||||
slice[1] = {
|
||||
"call",
|
||||
{
|
||||
"self",
|
||||
unpack(slice[1][2])
|
||||
if chain then
|
||||
local slice = (function()
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 0
|
||||
local _list_0 = chain
|
||||
for _index_0 = 3, #_list_0 do
|
||||
local item = _list_0[_index_0]
|
||||
_len_0 = _len_0 + 1
|
||||
_accum_0[_len_0] = item
|
||||
end
|
||||
return _accum_0
|
||||
end)()
|
||||
local new_chain = {
|
||||
"chain",
|
||||
parent_cls_name
|
||||
}
|
||||
}
|
||||
local act
|
||||
if ntype(calling_name) ~= "value" then
|
||||
act = "index"
|
||||
if slice[1][1] == "call" then
|
||||
local calling_name = block:get("current_block")
|
||||
slice[1] = {
|
||||
"call",
|
||||
{
|
||||
"self",
|
||||
unpack(slice[1][2])
|
||||
}
|
||||
}
|
||||
local act
|
||||
if ntype(calling_name) ~= "value" then
|
||||
act = "index"
|
||||
else
|
||||
act = "dot"
|
||||
end
|
||||
insert(new_chain, {
|
||||
act,
|
||||
calling_name
|
||||
})
|
||||
end
|
||||
local _list_0 = slice
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local item = _list_0[_index_0]
|
||||
insert(new_chain, item)
|
||||
end
|
||||
return new_chain
|
||||
else
|
||||
act = "dot"
|
||||
return parent_cls_name
|
||||
end
|
||||
return {
|
||||
"chain",
|
||||
parent_cls_name,
|
||||
{
|
||||
act,
|
||||
calling_name
|
||||
},
|
||||
unpack(slice)
|
||||
}
|
||||
end)
|
||||
end),
|
||||
_with_0.assign_one(parent_cls_name, parent_val == "" and "nil" or parent_val),
|
||||
|
@ -368,13 +368,22 @@ Statement = Transformer {
|
||||
value = .block_exp {
|
||||
Run =>
|
||||
@set "super", (block, chain) ->
|
||||
calling_name = block\get"current_block"
|
||||
slice = [item for item in *chain[3,]]
|
||||
-- inject self
|
||||
slice[1] = {"call", {"self", unpack slice[1][2]}}
|
||||
if chain
|
||||
slice = [item for item in *chain[3,]]
|
||||
new_chain = {"chain", parent_cls_name}
|
||||
|
||||
act = if ntype(calling_name) != "value" then "index" else "dot"
|
||||
{"chain", parent_cls_name, {act, calling_name}, unpack slice}
|
||||
-- calling super, inject calling name and self into chain
|
||||
if slice[1][1] == "call"
|
||||
calling_name = block\get"current_block"
|
||||
slice[1] = {"call", {"self", unpack slice[1][2]}}
|
||||
act = if ntype(calling_name) != "value" then "index" else "dot"
|
||||
insert new_chain, {act, calling_name}
|
||||
|
||||
insert new_chain, item for item in *slice
|
||||
|
||||
new_chain
|
||||
else
|
||||
parent_cls_name
|
||||
|
||||
.assign_one parent_cls_name, parent_val == "" and "nil" or parent_val
|
||||
.assign_one base_name, tbl
|
||||
|
@ -44,3 +44,10 @@ class Okay
|
||||
something: 20323
|
||||
-- yeaha
|
||||
|
||||
|
||||
class Biggie extends Okay
|
||||
something: =>
|
||||
super 1,2,3,4
|
||||
super.something another_self, 1,2,3,4
|
||||
assert super == Okay
|
||||
|
||||
|
@ -168,4 +168,35 @@ Okay = (function()
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
return _class_0
|
||||
end)()
|
||||
local Biggie
|
||||
Biggie = (function()
|
||||
local _parent_0 = Okay
|
||||
local _base_0 = {
|
||||
something = function(self)
|
||||
_parent_0.something(self, 1, 2, 3, 4)
|
||||
_parent_0.something(another_self, 1, 2, 3, 4)
|
||||
return assert(_parent_0 == Okay)
|
||||
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