Skip to content

Commit

Permalink
class names aren't refs, fixes #287
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Sep 25, 2016
1 parent 92b269c commit bf437b2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
8 changes: 7 additions & 1 deletion moonscript/transform/statement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ return Transformer({
local _continue_0 = false
repeat
local name = names[_index_0]
if not (name[2]:match("^%u")) then
local str_name
if ntype(name) == "ref" then
str_name = name[2]
else
str_name = name
end
if not (str_name:match("^%u")) then
_continue_0 = true
break
end
Expand Down
7 changes: 6 additions & 1 deletion moonscript/transform/statement.moon
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ Transformer {

if node[2] == "^"
names = for name in *names
continue unless name[2]\match "^%u"
str_name = if ntype(name) == "ref"
name[2]
else
name

continue unless str_name\match "^%u"
name

{"declare", names}
Expand Down
11 changes: 11 additions & 0 deletions spec/inputs/local.moon
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ do
d = 2323


do
local ^
lowercase = 5
Uppercase = 3

class One
Five = 6

class Two
class No

do
local *
-- this generates a nil value in the body
Expand Down
67 changes: 67 additions & 0 deletions spec/outputs/local.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,73 @@ do
d = 200
d = 2323
end
do
local Uppercase, One, Two
local lowercase = 5
Uppercase = 3
do
local _class_0
local Five
local _base_0 = { }
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function() end,
__base = _base_0,
__name = "One"
}, {
__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
local self = _class_0
Five = 6
One = _class_0
end
do
local _class_0
local No
local _base_0 = { }
_base_0.__index = _base_0
_class_0 = setmetatable({
__init = function() end,
__base = _base_0,
__name = "Two"
}, {
__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
local self = _class_0
do
local _class_1
local _base_1 = { }
_base_1.__index = _base_1
_class_1 = setmetatable({
__init = function() end,
__base = _base_1,
__name = "No"
}, {
__index = _base_1,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_1)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_1.__class = _class_1
No = _class_1
end
Two = _class_0
end
end
do
local _list_0 = { }
for _index_0 = 1, #_list_0 do
Expand Down

0 comments on commit bf437b2

Please sign in to comment.