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,12 +463,8 @@ Statement = Transformer({
|
||||
t = ntype(value)
|
||||
end
|
||||
if types.cascading[t] then
|
||||
transformed = build.group({
|
||||
{
|
||||
"declare",
|
||||
names
|
||||
},
|
||||
self.transform.statement(value, function(stm)
|
||||
local ret
|
||||
ret = function(stm)
|
||||
if types.is_value(stm) then
|
||||
return {
|
||||
"assign",
|
||||
@ -480,7 +476,13 @@ Statement = Transformer({
|
||||
else
|
||||
return stm
|
||||
end
|
||||
end)
|
||||
end
|
||||
transformed = build.group({
|
||||
{
|
||||
"declare",
|
||||
names
|
||||
},
|
||||
self.transform.statement(value, ret, node)
|
||||
})
|
||||
end
|
||||
end
|
||||
@ -897,7 +899,7 @@ Statement = Transformer({
|
||||
if_stm
|
||||
})
|
||||
end,
|
||||
class = function(self, node, ret)
|
||||
class = function(self, node, ret, parent_assign)
|
||||
local _, name, parent_val, body = unpack(node)
|
||||
local statements = { }
|
||||
local properties = { }
|
||||
@ -974,10 +976,10 @@ Statement = Transformer({
|
||||
smart_node(constructor)
|
||||
constructor.arrow = "fat"
|
||||
end
|
||||
local real_name
|
||||
local _exp_0 = ntype(name)
|
||||
local real_name = name or parent_assign and parent_assign[2][1]
|
||||
local _exp_0 = ntype(real_name)
|
||||
if "chain" == _exp_0 then
|
||||
local last = name[#name]
|
||||
local last = real_name[#real_name]
|
||||
local _exp_1 = ntype(last)
|
||||
if "dot" == _exp_1 then
|
||||
real_name = {
|
||||
@ -996,7 +998,7 @@ Statement = Transformer({
|
||||
real_name = {
|
||||
"string",
|
||||
'"',
|
||||
name
|
||||
real_name
|
||||
}
|
||||
end
|
||||
local cls = build.table({
|
||||
|
@ -209,13 +209,15 @@ Statement = Transformer {
|
||||
t = ntype value
|
||||
|
||||
if types.cascading[t]
|
||||
build.group {
|
||||
{"declare", names}
|
||||
@transform.statement value, (stm) ->
|
||||
ret = (stm) ->
|
||||
if types.is_value stm
|
||||
{"assign", names, {stm}}
|
||||
else
|
||||
stm
|
||||
|
||||
build.group {
|
||||
{"declare", names}
|
||||
@transform.statement value, ret, node
|
||||
}
|
||||
|
||||
transformed or node
|
||||
@ -456,7 +458,7 @@ Statement = Transformer {
|
||||
if_stm
|
||||
}
|
||||
|
||||
class: (node, ret) =>
|
||||
class: (node, ret, parent_assign) =>
|
||||
_, name, parent_val, body = unpack node
|
||||
|
||||
-- split apart properties and statements
|
||||
@ -505,9 +507,10 @@ Statement = Transformer {
|
||||
smart_node constructor
|
||||
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"
|
||||
last = name[#name]
|
||||
last = real_name[#real_name]
|
||||
switch ntype last
|
||||
when "dot"
|
||||
{"string", '"', last[2]}
|
||||
@ -518,7 +521,7 @@ Statement = Transformer {
|
||||
when "nil"
|
||||
"nil"
|
||||
else
|
||||
{"string", '"', name}
|
||||
{"string", '"', real_name}
|
||||
|
||||
cls = build.table {
|
||||
{"__init", constructor}
|
||||
|
@ -768,7 +768,7 @@ do
|
||||
end
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = nil,
|
||||
__name = "a",
|
||||
__parent = _parent_0
|
||||
}, {
|
||||
__index = function(cls, name)
|
||||
@ -885,7 +885,7 @@ do
|
||||
end
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = nil,
|
||||
__name = "d",
|
||||
__parent = _parent_0
|
||||
}, {
|
||||
__index = function(cls, name)
|
||||
|
Loading…
Reference in New Issue
Block a user