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])
|
return "self:" .. self:value(node[2])
|
||||||
end,
|
end,
|
||||||
raw_value = function(self, value)
|
raw_value = function(self, value)
|
||||||
|
if value == "super" then
|
||||||
|
return self:value(self:get("super")(self))
|
||||||
|
end
|
||||||
if value == "..." then
|
if value == "..." then
|
||||||
self.has_varargs = true
|
self.has_varargs = true
|
||||||
end
|
end
|
||||||
|
@ -181,6 +181,10 @@ value_compile =
|
|||||||
|
|
||||||
-- catch all pure string values
|
-- catch all pure string values
|
||||||
raw_value: (value) =>
|
raw_value: (value) =>
|
||||||
|
if value == "super"
|
||||||
|
return @value @get"super" self
|
||||||
|
|
||||||
if value == "..."
|
if value == "..."
|
||||||
@has_varargs = true
|
@has_varargs = true
|
||||||
|
|
||||||
tostring value
|
tostring value
|
||||||
|
@ -656,40 +656,51 @@ Statement = Transformer({
|
|||||||
value = _with_0.block_exp({
|
value = _with_0.block_exp({
|
||||||
Run(function(self)
|
Run(function(self)
|
||||||
return self:set("super", function(block, chain)
|
return self:set("super", function(block, chain)
|
||||||
local calling_name = block:get("current_block")
|
if chain then
|
||||||
local slice = (function()
|
local slice = (function()
|
||||||
local _accum_0 = { }
|
local _accum_0 = { }
|
||||||
local _len_0 = 0
|
local _len_0 = 0
|
||||||
local _list_0 = chain
|
local _list_0 = chain
|
||||||
for _index_0 = 3, #_list_0 do
|
for _index_0 = 3, #_list_0 do
|
||||||
local item = _list_0[_index_0]
|
local item = _list_0[_index_0]
|
||||||
_len_0 = _len_0 + 1
|
_len_0 = _len_0 + 1
|
||||||
_accum_0[_len_0] = item
|
_accum_0[_len_0] = item
|
||||||
end
|
end
|
||||||
return _accum_0
|
return _accum_0
|
||||||
end)()
|
end)()
|
||||||
slice[1] = {
|
local new_chain = {
|
||||||
"call",
|
"chain",
|
||||||
{
|
parent_cls_name
|
||||||
"self",
|
|
||||||
unpack(slice[1][2])
|
|
||||||
}
|
}
|
||||||
}
|
if slice[1][1] == "call" then
|
||||||
local act
|
local calling_name = block:get("current_block")
|
||||||
if ntype(calling_name) ~= "value" then
|
slice[1] = {
|
||||||
act = "index"
|
"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
|
else
|
||||||
act = "dot"
|
return parent_cls_name
|
||||||
end
|
end
|
||||||
return {
|
|
||||||
"chain",
|
|
||||||
parent_cls_name,
|
|
||||||
{
|
|
||||||
act,
|
|
||||||
calling_name
|
|
||||||
},
|
|
||||||
unpack(slice)
|
|
||||||
}
|
|
||||||
end)
|
end)
|
||||||
end),
|
end),
|
||||||
_with_0.assign_one(parent_cls_name, parent_val == "" and "nil" or parent_val),
|
_with_0.assign_one(parent_cls_name, parent_val == "" and "nil" or parent_val),
|
||||||
|
@ -368,13 +368,22 @@ Statement = Transformer {
|
|||||||
value = .block_exp {
|
value = .block_exp {
|
||||||
Run =>
|
Run =>
|
||||||
@set "super", (block, chain) ->
|
@set "super", (block, chain) ->
|
||||||
calling_name = block\get"current_block"
|
if chain
|
||||||
slice = [item for item in *chain[3,]]
|
slice = [item for item in *chain[3,]]
|
||||||
-- inject self
|
new_chain = {"chain", parent_cls_name}
|
||||||
slice[1] = {"call", {"self", unpack slice[1][2]}}
|
|
||||||
|
|
||||||
act = if ntype(calling_name) != "value" then "index" else "dot"
|
-- calling super, inject calling name and self into chain
|
||||||
{"chain", parent_cls_name, {act, calling_name}, unpack slice}
|
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 parent_cls_name, parent_val == "" and "nil" or parent_val
|
||||||
.assign_one base_name, tbl
|
.assign_one base_name, tbl
|
||||||
|
@ -44,3 +44,10 @@ class Okay
|
|||||||
something: 20323
|
something: 20323
|
||||||
-- yeaha
|
-- 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
|
_base_0.__class = _class_0
|
||||||
return _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)()
|
end)()
|
Loading…
Reference in New Issue
Block a user