Skip to content

Commit 0759cd6

Browse files
committed
local glob tests and local ^
1 parent 1903221 commit 0759cd6

File tree

6 files changed

+89
-9
lines changed

6 files changed

+89
-9
lines changed

moonscript/compile.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ do
404404
if self.export_all then
405405
return true
406406
end
407-
if self.export_proper and name:match("^[A-Z]") then
407+
if self.export_proper and name:match("^%u") then
408408
return true
409409
end
410410
end

moonscript/compile.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class Block
234234
has_name: (name, skip_exports) =>
235235
if not skip_exports
236236
return true if @export_all
237-
return true if @export_proper and name\match"^[A-Z]"
237+
return true if @export_proper and name\match"^%u"
238238

239239
yes = @_names[name]
240240
if yes == nil and @parent

moonscript/compile/statement.lua

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,28 @@ local statement_compilers = {
4040
end
4141
end,
4242
declare_glob = function(self, node)
43+
local kind = node[2]
4344
local names = { }
44-
self:set("name_glob", function(name)
45-
insert(names, name)
46-
return true
47-
end)
45+
local fn
46+
local _exp_0 = node[2]
47+
if "*" == _exp_0 then
48+
fn = function(name)
49+
if type(name) == "string" then
50+
insert(names, name)
51+
return true
52+
end
53+
end
54+
elseif "^" == _exp_0 then
55+
fn = function(name)
56+
if type(name) == "string" and name:match("^%u") then
57+
insert(names, name)
58+
return true
59+
end
60+
end
61+
else
62+
fn = error("unknown glob")
63+
end
64+
self:set("name_glob", fn)
4865
return data.DelayedLine(function(buff)
4966
insert(buff, "local ")
5067
local _list_0 = names

moonscript/compile/statement.moon

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,24 @@ statement_compilers =
2121
\append_list [@name name for name in *undeclared], ", "
2222

2323
declare_glob: (node) =>
24+
kind = node[2]
25+
2426
names = {}
25-
@set "name_glob", (name) ->
26-
insert names, name
27-
true
27+
fn = switch node[2]
28+
when "*"
29+
(name) ->
30+
if type(name) == "string"
31+
insert names, name
32+
true
33+
when "^"
34+
(name) ->
35+
if type(name) == "string" and name\match "^%u"
36+
insert names, name
37+
true
38+
else
39+
error "unknown glob"
40+
41+
@set "name_glob", fn
2842

2943
data.DelayedLine (buff) ->
3044
insert buff, "local "

tests/inputs/local.moon

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,27 @@ something = ->
99
x = 1212
1010

1111

12+
do
13+
local *
14+
y = 2323
15+
z = 2323
16+
17+
do
18+
local *
19+
print "Nothing Here!"
20+
21+
do
22+
local ^
23+
x = 3434
24+
y = 3434
25+
X = 3434
26+
Y = "yeah"
27+
28+
do
29+
local ^
30+
x,y = "a", "b"
31+
32+
do
33+
local *
34+
x,y = "a", "b"
35+

tests/outputs/local.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,29 @@ local something
55
something = function()
66
local x
77
x = 1212
8+
end
9+
do
10+
local y, z
11+
y = 2323
12+
z = 2323
13+
end
14+
do
15+
16+
print("Nothing Here!")
17+
end
18+
do
19+
local X, Y
20+
x = 3434
21+
local y = 3434
22+
X = 3434
23+
Y = "yeah"
24+
end
25+
do
26+
27+
local y
28+
x, y = "a", "b"
29+
end
30+
do
31+
local x, y
32+
x, y = "a", "b"
833
end

0 commit comments

Comments
 (0)