Skip to content

Commit 374a7c5

Browse files
committed
can export assignment statements
1 parent de3372d commit 374a7c5

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

moonscript/parse.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ local build_grammar = wrap(function()
410410
TableBlock = SpaceBreak^1 * Advance * TableBlockInner * PopIndent / mark"table",
411411

412412
ClassDecl = key"class" * Name * (key"extends" * Exp + C"")^-1 * TableBlock / mark"class",
413-
Export = key"export" * (Ct(NameList) + op"*" + op"^") / mark"export",
413+
Export = key"export" * (Ct(NameList) * (sym"=" * Ct(ExpListLow))^-1 + op"*" + op"^") / mark"export",
414414

415415
KeyValue = (sym":" * Name) / self_assign + Ct((SimpleName + sym"[" * Exp * sym"]") * symx":" * (Exp + TableBlock)),
416416
KeyValueList = KeyValue * (sym"," * KeyValue)^0,

moonscript/transform.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ Statement = Transformer({
215215
return node
216216
end
217217
end,
218+
export = function(node)
219+
if #node > 2 then
220+
return build.group({
221+
node,
222+
build.assign({
223+
names = node[2],
224+
values = node[3]
225+
})
226+
})
227+
else
228+
return nil
229+
end
230+
end,
218231
update = function(node)
219232
local _, name, op, exp = unpack(node)
220233
local op_final = op:match("^(.+)=$")

moonscript/transform.moon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ Statement = Transformer {
124124
else
125125
node
126126

127+
export: (node) ->
128+
-- assign values if they are included
129+
if #node > 2
130+
build.group {
131+
node
132+
build.assign {
133+
names: node[2]
134+
values: node[3]
135+
}
136+
}
137+
else
138+
nil
139+
127140
update: (node) ->
128141
_, name, op, exp = unpack node
129142
op_final = op\match "^(.+)=$"

tests/inputs/export.moon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ y = ->
3535
with tmp
3636
j = 2000
3737

38+
39+
export a,b,c = 223, 343
40+
export cool = "dad"

tests/outputs/export.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ end
2828
do
2929
local _with_0 = tmp
3030
local j = 2000
31-
end
31+
end
32+
a, b, c = 223, 343
33+
cool = "dad"

0 commit comments

Comments
 (0)