File tree Expand file tree Collapse file tree 8 files changed +88
-18
lines changed
Expand file tree Collapse file tree 8 files changed +88
-18
lines changed Original file line number Diff line number Diff line change @@ -586,6 +586,9 @@ variables directly:
586586
587587 export some_number, message_str = 100, "hello world"
588588
589+ Additionally, a class declaration can be prefixed with the export keyword in
590+ order to export it.
591+
589592### Export All & Export Proper
590593
591594The ` export ` statement can also take special symbols ` * ` and ` ^ ` .
Original file line number Diff line number Diff line change @@ -410,7 +410,10 @@ 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 ) * (sym " =" * Ct (ExpListLow ))^- 1 + op " *" + op " ^" ) / mark " export" ,
413+ Export = key " export" * (
414+ Cc " class" * ClassDecl +
415+ op " *" + op " ^" +
416+ Ct (NameList ) * (sym " =" * Ct (ExpListLow ))^- 1 ) / mark " export" ,
414417
415418 KeyValue = (sym " :" * Name ) / self_assign + Ct ((SimpleName + sym " [" * Exp * sym " ]" ) * symx " :" * (Exp + TableBlock )),
416419 KeyValueList = KeyValue * (sym " ," * KeyValue )^ 0 ,
Original file line number Diff line number Diff line change @@ -217,13 +217,26 @@ Statement = Transformer({
217217 end ,
218218 export = function (node )
219219 if # node > 2 then
220- return build .group ({
221- node ,
222- build .assign ({
223- names = node [2 ],
224- values = node [3 ]
220+ if node [2 ] == " class" then
221+ local cls = smart_node (node [3 ])
222+ return build .group ({
223+ {
224+ " export" ,
225+ {
226+ cls .name
227+ }
228+ },
229+ cls
225230 })
226- })
231+ else
232+ return build .group ({
233+ node ,
234+ build .assign ({
235+ names = node [2 ],
236+ values = node [3 ]
237+ })
238+ })
239+ end
227240 else
228241 return nil
229242 end
Original file line number Diff line number Diff line change @@ -127,13 +127,20 @@ Statement = Transformer {
127127 export : ( node) ->
128128 -- assign values if they are included
129129 if # node > 2
130- build. group {
131- node
132- build. assign {
133- names : node[ 2 ]
134- values : node[ 3 ]
130+ if node[ 2 ] == " class"
131+ cls = smart_node node[ 3 ]
132+ build. group {
133+ { " export" , { cls. name}}
134+ cls
135+ }
136+ else
137+ build. group {
138+ node
139+ build. assign {
140+ names : node[ 2 ]
141+ values : node[ 3 ]
142+ }
135143 }
136- }
137144 else
138145 nil
139146
Original file line number Diff line number Diff line change @@ -24,6 +24,16 @@ is_slice = function(node)
2424end
2525local t = { }
2626local node_types = {
27+ class = {
28+ {
29+ " name" ,
30+ " Tmp"
31+ },
32+ {
33+ " body" ,
34+ t
35+ }
36+ },
2737 fndef = {
2838 {
2939 " args" ,
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ is_slice = (node) ->
2525
2626t = {}
2727node_types = {
28+ class : {
29+ { " name" , " Tmp" }
30+ { " body" , t}
31+ }
2832 fndef : {
2933 { " args" , t}
3034 { " whitelist" , t}
Original file line number Diff line number Diff line change 11
2+ export a, b, c = 223 , 343
3+ export cool = " dad"
4+
5+ export class Something
6+ umm : " cool"
7+
28What = if this
39 232
410else
@@ -36,5 +42,3 @@ with tmp
3642 j = 2000
3743
3844
39- export a, b, c = 223 , 343
40- export cool = " dad"
Original file line number Diff line number Diff line change 1+ a , b , c = 223 , 343
2+ cool = " dad"
3+ Something = (function ()
4+ local _parent_0 = nil
5+ local _base_0 = {
6+ umm = " cool"
7+ }
8+ _base_0 .__index = _base_0
9+ if _parent_0 then
10+ setmetatable (_base_0 , getmetatable (_parent_0 ).__index )
11+ end
12+ local _class_0 = setmetatable ({
13+ __init = function (self , ...)
14+ if _parent_0 then
15+ return _parent_0 .__init (self , ... )
16+ end
17+ end
18+ }, {
19+ __index = _base_0 ,
20+ __call = function (cls , ...)
21+ local _self_0 = setmetatable ({}, _base_0 )
22+ cls .__init (_self_0 , ... )
23+ return _self_0
24+ end
25+ })
26+ _base_0 .__class = _class_0
27+ return _class_0
28+ end )()
129local What
230if this then
331 What = 232
2856do
2957 local _with_0 = tmp
3058 local j = 2000
31- end
32- a , b , c = 223 , 343
33- cool = " dad"
59+ end
You can’t perform that action at this time.
0 commit comments