mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
extract class name from assign statement if anonymous class is being assigned
This commit is contained in:
parent
97394fbbc9
commit
f98f822891
@ -463,24 +463,26 @@ Statement = Transformer({
|
|||||||
t = ntype(value)
|
t = ntype(value)
|
||||||
end
|
end
|
||||||
if types.cascading[t] then
|
if types.cascading[t] then
|
||||||
|
local ret
|
||||||
|
ret = function(stm)
|
||||||
|
if types.is_value(stm) then
|
||||||
|
return {
|
||||||
|
"assign",
|
||||||
|
names,
|
||||||
|
{
|
||||||
|
stm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return stm
|
||||||
|
end
|
||||||
|
end
|
||||||
transformed = build.group({
|
transformed = build.group({
|
||||||
{
|
{
|
||||||
"declare",
|
"declare",
|
||||||
names
|
names
|
||||||
},
|
},
|
||||||
self.transform.statement(value, function(stm)
|
self.transform.statement(value, ret, node)
|
||||||
if types.is_value(stm) then
|
|
||||||
return {
|
|
||||||
"assign",
|
|
||||||
names,
|
|
||||||
{
|
|
||||||
stm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return stm
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -897,7 +899,7 @@ Statement = Transformer({
|
|||||||
if_stm
|
if_stm
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
class = function(self, node, ret)
|
class = function(self, node, ret, parent_assign)
|
||||||
local _, name, parent_val, body = unpack(node)
|
local _, name, parent_val, body = unpack(node)
|
||||||
local statements = { }
|
local statements = { }
|
||||||
local properties = { }
|
local properties = { }
|
||||||
@ -974,10 +976,10 @@ Statement = Transformer({
|
|||||||
smart_node(constructor)
|
smart_node(constructor)
|
||||||
constructor.arrow = "fat"
|
constructor.arrow = "fat"
|
||||||
end
|
end
|
||||||
local real_name
|
local real_name = name or parent_assign and parent_assign[2][1]
|
||||||
local _exp_0 = ntype(name)
|
local _exp_0 = ntype(real_name)
|
||||||
if "chain" == _exp_0 then
|
if "chain" == _exp_0 then
|
||||||
local last = name[#name]
|
local last = real_name[#real_name]
|
||||||
local _exp_1 = ntype(last)
|
local _exp_1 = ntype(last)
|
||||||
if "dot" == _exp_1 then
|
if "dot" == _exp_1 then
|
||||||
real_name = {
|
real_name = {
|
||||||
@ -996,7 +998,7 @@ Statement = Transformer({
|
|||||||
real_name = {
|
real_name = {
|
||||||
"string",
|
"string",
|
||||||
'"',
|
'"',
|
||||||
name
|
real_name
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
local cls = build.table({
|
local cls = build.table({
|
||||||
|
@ -209,13 +209,15 @@ Statement = Transformer {
|
|||||||
t = ntype value
|
t = ntype value
|
||||||
|
|
||||||
if types.cascading[t]
|
if types.cascading[t]
|
||||||
|
ret = (stm) ->
|
||||||
|
if types.is_value stm
|
||||||
|
{"assign", names, {stm}}
|
||||||
|
else
|
||||||
|
stm
|
||||||
|
|
||||||
build.group {
|
build.group {
|
||||||
{"declare", names}
|
{"declare", names}
|
||||||
@transform.statement value, (stm) ->
|
@transform.statement value, ret, node
|
||||||
if types.is_value stm
|
|
||||||
{"assign", names, {stm}}
|
|
||||||
else
|
|
||||||
stm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transformed or node
|
transformed or node
|
||||||
@ -456,7 +458,7 @@ Statement = Transformer {
|
|||||||
if_stm
|
if_stm
|
||||||
}
|
}
|
||||||
|
|
||||||
class: (node, ret) =>
|
class: (node, ret, parent_assign) =>
|
||||||
_, name, parent_val, body = unpack node
|
_, name, parent_val, body = unpack node
|
||||||
|
|
||||||
-- split apart properties and statements
|
-- split apart properties and statements
|
||||||
@ -505,9 +507,10 @@ Statement = Transformer {
|
|||||||
smart_node constructor
|
smart_node constructor
|
||||||
constructor.arrow = "fat"
|
constructor.arrow = "fat"
|
||||||
|
|
||||||
real_name = switch ntype(name)
|
real_name = name or parent_assign and parent_assign[2][1]
|
||||||
|
real_name = switch ntype real_name
|
||||||
when "chain"
|
when "chain"
|
||||||
last = name[#name]
|
last = real_name[#real_name]
|
||||||
switch ntype last
|
switch ntype last
|
||||||
when "dot"
|
when "dot"
|
||||||
{"string", '"', last[2]}
|
{"string", '"', last[2]}
|
||||||
@ -518,7 +521,7 @@ Statement = Transformer {
|
|||||||
when "nil"
|
when "nil"
|
||||||
"nil"
|
"nil"
|
||||||
else
|
else
|
||||||
{"string", '"', name}
|
{"string", '"', real_name}
|
||||||
|
|
||||||
cls = build.table {
|
cls = build.table {
|
||||||
{"__init", constructor}
|
{"__init", constructor}
|
||||||
|
@ -768,7 +768,7 @@ do
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
__base = _base_0,
|
__base = _base_0,
|
||||||
__name = nil,
|
__name = "a",
|
||||||
__parent = _parent_0
|
__parent = _parent_0
|
||||||
}, {
|
}, {
|
||||||
__index = function(cls, name)
|
__index = function(cls, name)
|
||||||
@ -885,7 +885,7 @@ do
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
__base = _base_0,
|
__base = _base_0,
|
||||||
__name = nil,
|
__name = "d",
|
||||||
__parent = _parent_0
|
__parent = _parent_0
|
||||||
}, {
|
}, {
|
||||||
__index = function(cls, name)
|
__index = function(cls, name)
|
||||||
|
Loading…
Reference in New Issue
Block a user