aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-10-12 10:04:44 +0800
committerLi Jin <dragon-fly@qq.com>2021-10-12 10:04:44 +0800
commit60a979e224f26117f5be82bfca757a2483cef0fd (patch)
tree7c6af44f6dcada1f23979b820ba830251997b161
parenta19b242cbaf53721b20a3163dd06f43e9ef2b487 (diff)
downloadyuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.gz
yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.bz2
yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.zip
fix test.
-rw-r--r--.gitignore1
-rw-r--r--makefile25
-rw-r--r--spec/outputs/ambiguous.lua30
-rw-r--r--spec/outputs/assign.lua44
-rw-r--r--spec/outputs/attrib.lua63
-rw-r--r--spec/outputs/backcall.lua130
-rw-r--r--spec/outputs/bubbling.lua123
-rw-r--r--spec/outputs/class.lua1057
-rw-r--r--spec/outputs/comprehension.lua277
-rw-r--r--spec/outputs/cond.lua272
-rw-r--r--spec/outputs/destructure.lua357
-rw-r--r--spec/outputs/do.lua48
-rw-r--r--spec/outputs/existential.lua156
-rw-r--r--spec/outputs/export.lua307
-rw-r--r--spec/outputs/export_default.lua19
-rw-r--r--spec/outputs/funcs.lua222
-rw-r--r--spec/outputs/global.lua89
-rw-r--r--spec/outputs/goto.lua67
-rw-r--r--spec/outputs/import.lua92
-rw-r--r--spec/outputs/lists.lua282
-rw-r--r--spec/outputs/literals.lua28
-rw-r--r--spec/outputs/local.lua151
-rw-r--r--spec/outputs/loops.lua352
-rw-r--r--spec/outputs/macro-export.lua2
-rw-r--r--spec/outputs/macro-teal.tl2
-rw-r--r--spec/outputs/macro.lua233
-rw-r--r--spec/outputs/metatable.lua113
-rw-r--r--spec/outputs/multiline_chain.lua91
-rw-r--r--spec/outputs/operators.lua29
-rw-r--r--spec/outputs/pipe.lua116
-rw-r--r--spec/outputs/plus.lua69
-rw-r--r--spec/outputs/return.lua102
-rw-r--r--spec/outputs/string.lua42
-rw-r--r--spec/outputs/stub.lua26
-rw-r--r--spec/outputs/switch.lua71
-rw-r--r--spec/outputs/syntax.lua360
-rw-r--r--spec/outputs/tables.lua351
-rw-r--r--spec/outputs/teal-lang.lua49
-rw-r--r--spec/outputs/teal-lang.tl60
-rw-r--r--spec/outputs/unless_else.lua7
-rw-r--r--spec/outputs/using.lua23
-rw-r--r--spec/outputs/vararg.lua218
-rw-r--r--spec/outputs/whitespace.lua98
-rw-r--r--spec/outputs/with.lua164
44 files changed, 6413 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 224cfe3..27d6eb3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,6 @@ yue
2!src/yuescript/ 2!src/yuescript/
3build 3build
4build.luarocks 4build.luarocks
5spec/outputs
6yuescript-*.rock* 5yuescript-*.rock*
7!yuescript-dev-1.rockspec 6!yuescript-dev-1.rockspec
8.vs 7.vs
diff --git a/makefile b/makefile
index 5c20f07..faca033 100644
--- a/makefile
+++ b/makefile
@@ -29,7 +29,11 @@ DESTDIR = /
29INSTALL_PREFIX = usr/local 29INSTALL_PREFIX = usr/local
30# Test 30# Test
31TEST_INPUT = ./spec/inputs 31TEST_INPUT = ./spec/inputs
32TEST_OUTPUT = ./spec/outputs 32TEST_OUTPUT = ./spec/generated
33GEN_OUTPUT = ./spec/outputs
34
35PLAT = macos
36
33#### END PROJECT SETTINGS #### 37#### END PROJECT SETTINGS ####
34 38
35# Optionally you may move the section above to a separate config.mk file, and 39# Optionally you may move the section above to a separate config.mk file, and
@@ -54,6 +58,7 @@ endif
54# Add platform related linker flag 58# Add platform related linker flag
55ifneq ($(UNAME_S),Darwin) 59ifneq ($(UNAME_S),Darwin)
56 LINK_FLAGS += -lstdc++fs -Wl,-E 60 LINK_FLAGS += -lstdc++fs -Wl,-E
61 PLAT = linux
57endif 62endif
58 63
59# Function used to check variables. Use on the command line: 64# Function used to check variables. Use on the command line:
@@ -179,7 +184,7 @@ else
179 @echo "Beginning release build" 184 @echo "Beginning release build"
180endif 185endif
181ifneq ($(NO_LUA),true) 186ifneq ($(NO_LUA),true)
182 @$(MAKE) generic -C $(SRC_PATH)/3rdParty/lua 187 @$(MAKE) $(PLAT) -C $(SRC_PATH)/3rdParty/lua
183endif 188endif
184 @$(START_TIME) 189 @$(START_TIME)
185 @$(MAKE) all --no-print-directory 190 @$(MAKE) all --no-print-directory
@@ -231,7 +236,6 @@ dirs:
231 @echo "Creating directories" 236 @echo "Creating directories"
232 @mkdir -p $(dir $(OBJECTS)) 237 @mkdir -p $(dir $(OBJECTS))
233 @mkdir -p $(BIN_PATH) 238 @mkdir -p $(BIN_PATH)
234 @mkdir -p $(TEST_OUTPUT)
235 239
236# Installs to the set path 240# Installs to the set path
237.PHONY: install 241.PHONY: install
@@ -254,18 +258,31 @@ clean:
254 @echo "Deleting directories" 258 @echo "Deleting directories"
255 @$(RM) -r build 259 @$(RM) -r build
256 @$(RM) -r bin 260 @$(RM) -r bin
257 @echo "Deleting generated Lua codes"
258 @$(RM) -r $(TEST_OUTPUT) 261 @$(RM) -r $(TEST_OUTPUT)
259 262
260# Test Yuescript compiler 263# Test Yuescript compiler
261.PHONY: test 264.PHONY: test
262test: release 265test: release
266 @mkdir -p $(TEST_OUTPUT)
263 @echo "Compiling Yuescript codes..." 267 @echo "Compiling Yuescript codes..."
264 @$(START_TIME) 268 @$(START_TIME)
265 @./$(BIN_NAME) $(TEST_INPUT) -t $(TEST_OUTPUT) -tl_enabled=true 269 @./$(BIN_NAME) $(TEST_INPUT) -t $(TEST_OUTPUT) -tl_enabled=true
266 @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.yue -o $(TEST_OUTPUT)/teal-lang.lua 270 @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.yue -o $(TEST_OUTPUT)/teal-lang.lua
267 @echo -en "Compile time: " 271 @echo -en "Compile time: "
268 @$(END_TIME) 272 @$(END_TIME)
273 @./$(BIN_NAME) -e "$$(printf "r = io.popen('git diff --no-index $(TEST_OUTPUT) $(GEN_OUTPUT) | head -5')\\\\read '*a'\nif r ~= ''\n print r\n os.exit 1")"
274 @$(RM) -r $(TEST_OUTPUT)
275 @echo "Done!"
276
277# Test Yuescript compiler
278.PHONY: gen
279gen: release
280 @echo "Compiling Yuescript codes..."
281 @$(START_TIME)
282 @./$(BIN_NAME) $(TEST_INPUT) -t $(GEN_OUTPUT) -tl_enabled=true
283 @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.yue -o $(GEN_OUTPUT)/teal-lang.lua
284 @echo -en "Compile time: "
285 @$(END_TIME)
269 286
270# Main rule, checks the executable and symlinks to the output 287# Main rule, checks the executable and symlinks to the output
271all: $(BIN_PATH)/$(BIN_NAME) 288all: $(BIN_PATH)/$(BIN_NAME)
diff --git a/spec/outputs/ambiguous.lua b/spec/outputs/ambiguous.lua
new file mode 100644
index 0000000..6039d73
--- /dev/null
+++ b/spec/outputs/ambiguous.lua
@@ -0,0 +1,30 @@
1local bind = grasp.bind;
2(bind(stmt))({
3 color = "Red"
4})
5local a = 'b'
6local c = d;
7(a(b))(c(d))
8c = d.c;
9(a(b))(c(d));
10(c(d))(a(b))
11local b
12a, b = c, d;
13(d(a))(c)
14for i = 1, 10 do
15 a = function() end
16 (print)(1)
17 a = f;
18 (print)(2)
19 if cond then
20 (print)(3)
21 end
22 ::abc::;
23 (print)(4)
24 goto abc;
25 (print)(5)
26end
27do
28 print(123)
29end
30return nil
diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua
new file mode 100644
index 0000000..628f763
--- /dev/null
+++ b/spec/outputs/assign.lua
@@ -0,0 +1,44 @@
1local _
2_ = function()
3 local joop = 2302
4 return function(hi)
5 local d = 100
6 hi = 1021
7 local a, b, c
8 a, b, c, d = 1, 2, 3, 4
9 local hello
10 hello[232], (5 + 5)[121], hello, x[99] = 100, 200, 300
11 joop = 12
12 end
13end
14local joop = 2345
15local a, b
16if hello then
17 a, b = "hello"
18else
19 a, b = "nothing", "yeah"
20end
21if hello then
22 if yeah then
23 a, b = "one", "two"
24 else
25 a, b = "mmhh"
26 end
27else
28 print("the other")
29 a, b = "nothing", "yeah"
30end
31local c, d
32if true then
33 c, d = 1, 2
34end
35local x
36do
37 local f = getHandler()
38 if f then
39 x = ((function()
40 f()
41 return 123
42 end)())
43 end
44end
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua
new file mode 100644
index 0000000..d9ac3f2
--- /dev/null
+++ b/spec/outputs/attrib.lua
@@ -0,0 +1,63 @@
1do
2 local a <close>, b <close> = setmetatable({ }, {
3 __close = function(self)
4 return print("closed")
5 end
6 })
7 local c <const>, d <const> = 123, 'abc'
8 close(a, b)
9 const(c, d)
10end
11do
12 local v <close> = (function()
13 if flag then
14 return func()
15 else
16 return setmetatable({ }, {
17 __close = function(self) end
18 })
19 end
20 end)()
21 local f <close> = (function()
22 local _with_0 = io.open("file.txt")
23 _with_0:write("Hello")
24 return _with_0
25 end)()
26end
27do
28 local _ <close> = (function()
29 local _with_0 = io.open("file.txt")
30 _with_0:write("Hello")
31 return _with_0
32 end)();
33 local _ <close> = setmetatable({ }, {
34 __close = function(self)
35 return print("second")
36 end
37 });
38 local _ <close> = setmetatable({ }, {
39 __close = function()
40 return print("first")
41 end
42 })
43end
44local _defers = setmetatable({ }, {
45 __close = function(self)
46 self[#self]()
47 self[#self] = nil
48 end
49})
50do
51 _defers[#_defers + 1] = function()
52 return print(3)
53 end
54 local _ <close> = _defers;
55 _defers[#_defers + 1] = function()
56 return print(2)
57 end
58 local _ <close> = _defers;
59 _defers[#_defers + 1] = function()
60 return print(1)
61 end
62 local _ <close> = _defers
63end
diff --git a/spec/outputs/backcall.lua b/spec/outputs/backcall.lua
new file mode 100644
index 0000000..9f7ec29
--- /dev/null
+++ b/spec/outputs/backcall.lua
@@ -0,0 +1,130 @@
1do
2 map({
3 1,
4 2,
5 3
6 }, function(x)
7 return x * 2
8 end)
9end
10do
11 map(function(x)
12 return x * 2
13 end, {
14 1,
15 2,
16 3
17 })
18end
19do
20 filter(function(x)
21 return x > 2
22 end, (function()
23 return map(function(x)
24 return x * 2
25 end, {
26 1,
27 2,
28 3,
29 4
30 })
31 end)())
32end
33do
34 if http ~= nil then
35 http.get("ajaxtest", function(data)
36 body[".result"]:html(data)
37 return http.post("ajaxprocess", data, function(processed)
38 body[".result"]:append(processed)
39 return setTimeout(1000, function()
40 return print("done")
41 end)
42 end)
43 end)
44 end
45end
46do
47 syncStatus(function()
48 return loadAsync("file.yue", function(err, data)
49 if data == nil then
50 data = "nil"
51 end
52 if err then
53 print(err)
54 return
55 end
56 return compileAsync(data, function(codes)
57 local func = loadstring(codes)
58 return func()
59 end)
60 end)
61 end)
62end
63do
64 f1(function()
65 return f2(function()
66 do
67 f3(function()
68 return f4(function() end)
69 end)
70 end
71 return f5(function()
72 return f6(function()
73 return f7()
74 end)
75 end)
76 end)
77 end)
78end
79do
80 local result, msg
81 do
82 do
83 local _obj_0 = receiveAsync("filename.txt", function(data)
84 print(data)
85 return processAsync(data, function(info)
86 return check(info)
87 end)
88 end)
89 result, msg = _obj_0.result, _obj_0.msg
90 end
91 end
92 print(result, msg)
93 local totalSize = reduce(((function()
94 local _accum_0 = { }
95 local _len_0 = 1
96 local _list_0 = files
97 for _index_0 = 1, #_list_0 do
98 local file = _list_0[_index_0]
99 _accum_0[_len_0] = loadAsync(file, function(data)
100 return addToCache(file, data)
101 end)
102 _len_0 = _len_0 + 1
103 end
104 return _accum_0
105 end)()), 0, function(a, b)
106 return a + b
107 end)
108end
109local propA
110do
111 propA = property(function(self)
112 return self._value
113 end, function(self, value)
114 print("old value: " .. tostring(self._value))
115 print("new value: " .. tostring(value))
116 self._value = value
117 end)
118end
119local propB
120do
121 propB = property(function(self)
122 return self._value
123 end, function(self, value)
124 print("old value: " .. tostring(self._value))
125 print("new value: " .. tostring(value))
126 self._value = value
127 end)
128end
129alert("hi")
130return nil
diff --git a/spec/outputs/bubbling.lua b/spec/outputs/bubbling.lua
new file mode 100644
index 0000000..7cb93c7
--- /dev/null
+++ b/spec/outputs/bubbling.lua
@@ -0,0 +1,123 @@
1local f
2f = function(...)
3 return #{
4 ...
5 }
6end
7local dont_bubble
8dont_bubble = function()
9 local _accum_0 = { }
10 local _len_0 = 1
11 for x in (function(...)
12 return print(...)
13 end)("hello") do
14 _accum_0[_len_0] = x
15 _len_0 = _len_0 + 1
16 end
17 return _accum_0
18end
19local k
20do
21 local _accum_0 = { }
22 local _len_0 = 1
23 for x in (function(...)
24 return print(...)
25 end)("hello") do
26 _accum_0[_len_0] = x
27 _len_0 = _len_0 + 1
28 end
29 k = _accum_0
30end
31local j
32do
33 local _accum_0 = { }
34 local _len_0 = 1
35 for i = 1, 10 do
36 _accum_0[_len_0] = function(...)
37 return print(...)
38 end
39 _len_0 = _len_0 + 1
40 end
41 j = _accum_0
42end
43local m
44m = function(...)
45 local _accum_0 = { }
46 local _len_0 = 1
47 local _list_0 = {
48 ...
49 }
50 for _index_0 = 1, #_list_0 do
51 local x = _list_0[_index_0]
52 if f(...) > 4 then
53 _accum_0[_len_0] = x
54 _len_0 = _len_0 + 1
55 end
56 end
57 return _accum_0
58end
59local _
60_ = function(...)
61 local x
62 do
63 local _accum_0 = { }
64 local _len_0 = 1
65 local _list_0 = {
66 ...
67 }
68 for _index_0 = 1, #_list_0 do
69 local i = _list_0[_index_0]
70 _accum_0[_len_0] = i
71 _len_0 = _len_0 + 1
72 end
73 x = _accum_0
74 end
75 local y
76 do
77 local _accum_0 = { }
78 local _len_0 = 1
79 local _list_0 = {
80 ...
81 }
82 for _index_0 = 1, #_list_0 do
83 local x = _list_0[_index_0]
84 _accum_0[_len_0] = x
85 _len_0 = _len_0 + 1
86 end
87 y = _accum_0
88 end
89 local z
90 do
91 local _accum_0 = { }
92 local _len_0 = 1
93 for x in hallo do
94 if f(...) > 4 then
95 _accum_0[_len_0] = x
96 _len_0 = _len_0 + 1
97 end
98 end
99 z = _accum_0
100 end
101 local a
102 do
103 local _accum_0 = { }
104 local _len_0 = 1
105 for i = 1, 10 do
106 _accum_0[_len_0] = ...
107 _len_0 = _len_0 + 1
108 end
109 a = _accum_0
110 end
111 local b
112 do
113 local _accum_0 = { }
114 local _len_0 = 1
115 for i = 1, 10 do
116 _accum_0[_len_0] = function(...)
117 return print(...)
118 end
119 _len_0 = _len_0 + 1
120 end
121 b = _accum_0
122 end
123end
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua
new file mode 100644
index 0000000..20b18ea
--- /dev/null
+++ b/spec/outputs/class.lua
@@ -0,0 +1,1057 @@
1local Hello
2do
3 local _class_0
4 local _base_0 = {
5 hello = function(self)
6 return print(self.test, self.world)
7 end,
8 __tostring = function(self)
9 return "hello world"
10 end
11 }
12 _base_0.__index = _base_0
13 _class_0 = setmetatable({
14 __init = function(self, test, world)
15 self.test = test
16 self.world = world
17 return print("creating object..")
18 end,
19 __base = _base_0,
20 __name = "Hello"
21 }, {
22 __index = _base_0,
23 __call = function(cls, ...)
24 local _self_0 = setmetatable({ }, _base_0)
25 cls.__init(_self_0, ...)
26 return _self_0
27 end
28 })
29 _base_0.__class = _class_0
30 Hello = _class_0
31end
32local x = Hello(1, 2)
33x:hello()
34print(x)
35local Simple
36do
37 local _class_0
38 local _base_0 = {
39 cool = function(self)
40 return print("cool")
41 end
42 }
43 _base_0.__index = _base_0
44 _class_0 = setmetatable({
45 __init = function() end,
46 __base = _base_0,
47 __name = "Simple"
48 }, {
49 __index = _base_0,
50 __call = function(cls, ...)
51 local _self_0 = setmetatable({ }, _base_0)
52 cls.__init(_self_0, ...)
53 return _self_0
54 end
55 })
56 _base_0.__class = _class_0
57 Simple = _class_0
58end
59local Yikes
60do
61 local _class_0
62 local _parent_0 = Simple
63 local _base_0 = { }
64 _base_0.__index = _base_0
65 setmetatable(_base_0, _parent_0.__base)
66 _class_0 = setmetatable({
67 __init = function(self)
68 return print("created hello")
69 end,
70 __base = _base_0,
71 __name = "Yikes",
72 __parent = _parent_0
73 }, {
74 __index = function(cls, name)
75 local val = rawget(_base_0, name)
76 if val == nil then
77 local parent = rawget(cls, "__parent")
78 if parent then
79 return parent[name]
80 end
81 else
82 return val
83 end
84 end,
85 __call = function(cls, ...)
86 local _self_0 = setmetatable({ }, _base_0)
87 cls.__init(_self_0, ...)
88 return _self_0
89 end
90 })
91 _base_0.__class = _class_0
92 if _parent_0.__inherited then
93 _parent_0.__inherited(_parent_0, _class_0)
94 end
95 Yikes = _class_0
96end
97x = Yikes()
98x:cool()
99local Hi
100do
101 local _class_0
102 local _base_0 = {
103 cool = function(self, num)
104 return print("num", num)
105 end
106 }
107 _base_0.__index = _base_0
108 _class_0 = setmetatable({
109 __init = function(self, arg)
110 return print("init arg", arg)
111 end,
112 __base = _base_0,
113 __name = "Hi"
114 }, {
115 __index = _base_0,
116 __call = function(cls, ...)
117 local _self_0 = setmetatable({ }, _base_0)
118 cls.__init(_self_0, ...)
119 return _self_0
120 end
121 })
122 _base_0.__class = _class_0
123 Hi = _class_0
124end
125do
126 local _class_0
127 local _parent_0 = Hi
128 local _base_0 = {
129 cool = function(self)
130 return _class_0.__parent.__base.cool(self, 120302)
131 end
132 }
133 _base_0.__index = _base_0
134 setmetatable(_base_0, _parent_0.__base)
135 _class_0 = setmetatable({
136 __init = function(self)
137 return _class_0.__parent.__init(self, "man")
138 end,
139 __base = _base_0,
140 __name = "Simple",
141 __parent = _parent_0
142 }, {
143 __index = function(cls, name)
144 local val = rawget(_base_0, name)
145 if val == nil then
146 local parent = rawget(cls, "__parent")
147 if parent then
148 return parent[name]
149 end
150 else
151 return val
152 end
153 end,
154 __call = function(cls, ...)
155 local _self_0 = setmetatable({ }, _base_0)
156 cls.__init(_self_0, ...)
157 return _self_0
158 end
159 })
160 _base_0.__class = _class_0
161 if _parent_0.__inherited then
162 _parent_0.__inherited(_parent_0, _class_0)
163 end
164 Simple = _class_0
165end
166x = Simple()
167x:cool()
168print(x.__class == Simple)
169local Okay
170do
171 local _class_0
172 local _base_0 = {
173 something = 20323
174 }
175 _base_0.__index = _base_0
176 _class_0 = setmetatable({
177 __init = function() end,
178 __base = _base_0,
179 __name = "Okay"
180 }, {
181 __index = _base_0,
182 __call = function(cls, ...)
183 local _self_0 = setmetatable({ }, _base_0)
184 cls.__init(_self_0, ...)
185 return _self_0
186 end
187 })
188 _base_0.__class = _class_0
189 Okay = _class_0
190end
191local Biggie
192do
193 local _class_0
194 local _parent_0 = Okay
195 local _base_0 = {
196 something = function(self)
197 _class_0.__parent.__base.something(self, 1, 2, 3, 4)
198 _class_0.__parent.something(another_self, 1, 2, 3, 4)
199 return assert(_class_0.__parent == Okay)
200 end
201 }
202 _base_0.__index = _base_0
203 setmetatable(_base_0, _parent_0.__base)
204 _class_0 = setmetatable({
205 __init = function(self, ...)
206 return _class_0.__parent.__init(self, ...)
207 end,
208 __base = _base_0,
209 __name = "Biggie",
210 __parent = _parent_0
211 }, {
212 __index = function(cls, name)
213 local val = rawget(_base_0, name)
214 if val == nil then
215 local parent = rawget(cls, "__parent")
216 if parent then
217 return parent[name]
218 end
219 else
220 return val
221 end
222 end,
223 __call = function(cls, ...)
224 local _self_0 = setmetatable({ }, _base_0)
225 cls.__init(_self_0, ...)
226 return _self_0
227 end
228 })
229 _base_0.__class = _class_0
230 if _parent_0.__inherited then
231 _parent_0.__inherited(_parent_0, _class_0)
232 end
233 Biggie = _class_0
234end
235local Yeah
236do
237 local _class_0
238 local _base_0 = {
239 okay = function(self)
240 return _class_0.__parent.something(self, 1, 2, 3, 4)
241 end
242 }
243 _base_0.__index = _base_0
244 _class_0 = setmetatable({
245 __init = function() end,
246 __base = _base_0,
247 __name = "Yeah"
248 }, {
249 __index = _base_0,
250 __call = function(cls, ...)
251 local _self_0 = setmetatable({ }, _base_0)
252 cls.__init(_self_0, ...)
253 return _self_0
254 end
255 })
256 _base_0.__class = _class_0
257 Yeah = _class_0
258end
259local What
260do
261 local _class_0
262 local _base_0 = {
263 something = function(self)
264 return print("val:", self.val)
265 end
266 }
267 _base_0.__index = _base_0
268 _class_0 = setmetatable({
269 __init = function() end,
270 __base = _base_0,
271 __name = "What"
272 }, {
273 __index = _base_0,
274 __call = function(cls, ...)
275 local _self_0 = setmetatable({ }, _base_0)
276 cls.__init(_self_0, ...)
277 return _self_0
278 end
279 })
280 _base_0.__class = _class_0
281 What = _class_0
282end
283do
284 local _class_0
285 local _parent_0 = What
286 local _base_0 = {
287 val = 2323,
288 something = function(self)
289 local _base_1 = _class_0.__parent
290 local _fn_0 = _base_1.something
291 return _fn_0 and function(...)
292 return _fn_0(_base_1, ...)
293 end
294 end
295 }
296 _base_0.__index = _base_0
297 setmetatable(_base_0, _parent_0.__base)
298 _class_0 = setmetatable({
299 __init = function(self, ...)
300 return _class_0.__parent.__init(self, ...)
301 end,
302 __base = _base_0,
303 __name = "Hello",
304 __parent = _parent_0
305 }, {
306 __index = function(cls, name)
307 local val = rawget(_base_0, name)
308 if val == nil then
309 local parent = rawget(cls, "__parent")
310 if parent then
311 return parent[name]
312 end
313 else
314 return val
315 end
316 end,
317 __call = function(cls, ...)
318 local _self_0 = setmetatable({ }, _base_0)
319 cls.__init(_self_0, ...)
320 return _self_0
321 end
322 })
323 _base_0.__class = _class_0
324 if _parent_0.__inherited then
325 _parent_0.__inherited(_parent_0, _class_0)
326 end
327 Hello = _class_0
328end
329do
330 local _with_0 = Hello()
331 x = _with_0:something()
332 print(x)
333 x()
334end
335local CoolSuper
336do
337 local _class_0
338 local _base_0 = {
339 hi = function(self)
340 _class_0.__parent.__base.hi(self, 1, 2, 3, 4)(1, 2, 3, 4)
341 _class_0.__parent.something(1, 2, 3, 4)
342 local _ = _class_0.__parent.something(1, 2, 3, 4).world
343 _class_0.__parent.yeah(self, "world").okay(hi, hi, hi)
344 _ = something.super
345 _ = _class_0.__parent.super.super.super
346 do
347 local _base_1 = _class_0.__parent
348 local _fn_0 = _base_1.hello
349 _ = _fn_0 and function(...)
350 return _fn_0(_base_1, ...)
351 end
352 end
353 return nil
354 end
355 }
356 _base_0.__index = _base_0
357 _class_0 = setmetatable({
358 __init = function() end,
359 __base = _base_0,
360 __name = "CoolSuper"
361 }, {
362 __index = _base_0,
363 __call = function(cls, ...)
364 local _self_0 = setmetatable({ }, _base_0)
365 cls.__init(_self_0, ...)
366 return _self_0
367 end
368 })
369 _base_0.__class = _class_0
370 CoolSuper = _class_0
371end
372x = self.hello
373x = self.__class.hello
374self:hello("world")
375self.__class:hello("world")
376self.__class:one(self.__class:two(4, 5)(self.three, self.four))
377local xx
378xx = function(hello, world, cool)
379 self.hello = hello
380 self.__class.world = world
381end
382local ClassMan
383do
384 local _class_0
385 local _base_0 = {
386 blue = function(self) end,
387 green = function(self) end
388 }
389 _base_0.__index = _base_0
390 _class_0 = setmetatable({
391 __init = function() end,
392 __base = _base_0,
393 __name = "ClassMan"
394 }, {
395 __index = _base_0,
396 __call = function(cls, ...)
397 local _self_0 = setmetatable({ }, _base_0)
398 cls.__init(_self_0, ...)
399 return _self_0
400 end
401 })
402 _base_0.__class = _class_0
403 local self = _class_0;
404 self.yeah = 343
405 self.hello = 3434
406 self.world = 23423
407 self.red = function(self) end
408 ClassMan = _class_0
409end
410x = self
411local y = self.__class
412self(something)
413self.__class(something)
414local self = self + self / self
415self = 343
416self.hello(2, 3, 4)
417local _ = hello[self].world
418local Whacko
419do
420 local _class_0
421 local hello
422 local _base_0 = { }
423 _base_0.__index = _base_0
424 _class_0 = setmetatable({
425 __init = function() end,
426 __base = _base_0,
427 __name = "Whacko"
428 }, {
429 __index = _base_0,
430 __call = function(cls, ...)
431 local _self_0 = setmetatable({ }, _base_0)
432 cls.__init(_self_0, ...)
433 return _self_0
434 end
435 })
436 _base_0.__class = _class_0
437 local self = _class_0;
438 _ = self.hello
439 if something then
440 print("hello world")
441 end
442 hello = "world"
443 self.another = "day"
444 if something then
445 print("yeah")
446 end
447 Whacko = _class_0
448end
449print("hello")
450local yyy
451yyy = function()
452 local Cool
453 do
454 local _class_0
455 local _base_0 = { }
456 _base_0.__index = _base_0
457 _class_0 = setmetatable({
458 __init = function() end,
459 __base = _base_0,
460 __name = "Cool"
461 }, {
462 __index = _base_0,
463 __call = function(cls, ...)
464 local _self_0 = setmetatable({ }, _base_0)
465 cls.__init(_self_0, ...)
466 return _self_0
467 end
468 })
469 _base_0.__class = _class_0
470 local self = _class_0;
471 _ = nil
472 Cool = _class_0
473 return _class_0
474 end
475end
476do
477 local _class_0
478 local _base_0 = { }
479 _base_0.__index = _base_0
480 _class_0 = setmetatable({
481 __init = function() end,
482 __base = _base_0,
483 __name = "D"
484 }, {
485 __index = _base_0,
486 __call = function(cls, ...)
487 local _self_0 = setmetatable({ }, _base_0)
488 cls.__init(_self_0, ...)
489 return _self_0
490 end
491 })
492 _base_0.__class = _class_0
493 local self = _class_0;
494 _ = nil
495 a.b.c.D = _class_0
496end
497do
498 local _class_0
499 local _base_0 = { }
500 _base_0.__index = _base_0
501 _class_0 = setmetatable({
502 __init = function() end,
503 __base = _base_0,
504 __name = "hello"
505 }, {
506 __index = _base_0,
507 __call = function(cls, ...)
508 local _self_0 = setmetatable({ }, _base_0)
509 cls.__init(_self_0, ...)
510 return _self_0
511 end
512 })
513 _base_0.__class = _class_0
514 local self = _class_0;
515 _ = nil
516 a.b["hello"] = _class_0
517end
518do
519 local _class_0
520 local _parent_0 = Hello.World
521 local _base_0 = { }
522 _base_0.__index = _base_0
523 setmetatable(_base_0, _parent_0.__base)
524 _class_0 = setmetatable({
525 __init = function(self, ...)
526 return _class_0.__parent.__init(self, ...)
527 end,
528 __base = _base_0,
529 __name = "Something",
530 __parent = _parent_0
531 }, {
532 __index = function(cls, name)
533 local val = rawget(_base_0, name)
534 if val == nil then
535 local parent = rawget(cls, "__parent")
536 if parent then
537 return parent[name]
538 end
539 else
540 return val
541 end
542 end,
543 __call = function(cls, ...)
544 local _self_0 = setmetatable({ }, _base_0)
545 cls.__init(_self_0, ...)
546 return _self_0
547 end
548 })
549 _base_0.__class = _class_0
550 local self = _class_0;
551 _ = nil
552 if _parent_0.__inherited then
553 _parent_0.__inherited(_parent_0, _class_0)
554 end
555 (function()
556 return require("moon")
557 end)().Something = _class_0
558end
559local a
560do
561 local _class_0
562 local _base_0 = { }
563 _base_0.__index = _base_0
564 _class_0 = setmetatable({
565 __init = function() end,
566 __base = _base_0,
567 __name = "a"
568 }, {
569 __index = _base_0,
570 __call = function(cls, ...)
571 local _self_0 = setmetatable({ }, _base_0)
572 cls.__init(_self_0, ...)
573 return _self_0
574 end
575 })
576 _base_0.__class = _class_0
577 a = _class_0
578end
579local b
580local Something
581do
582 local _class_0
583 local _base_0 = { }
584 _base_0.__index = _base_0
585 _class_0 = setmetatable({
586 __init = function() end,
587 __base = _base_0,
588 __name = "Something"
589 }, {
590 __index = _base_0,
591 __call = function(cls, ...)
592 local _self_0 = setmetatable({ }, _base_0)
593 cls.__init(_self_0, ...)
594 return _self_0
595 end
596 })
597 _base_0.__class = _class_0
598 Something = _class_0
599 b = _class_0
600end
601local c
602do
603 local _class_0
604 local _parent_0 = Hello
605 local _base_0 = { }
606 _base_0.__index = _base_0
607 setmetatable(_base_0, _parent_0.__base)
608 _class_0 = setmetatable({
609 __init = function(self, ...)
610 return _class_0.__parent.__init(self, ...)
611 end,
612 __base = _base_0,
613 __name = "Something",
614 __parent = _parent_0
615 }, {
616 __index = function(cls, name)
617 local val = rawget(_base_0, name)
618 if val == nil then
619 local parent = rawget(cls, "__parent")
620 if parent then
621 return parent[name]
622 end
623 else
624 return val
625 end
626 end,
627 __call = function(cls, ...)
628 local _self_0 = setmetatable({ }, _base_0)
629 cls.__init(_self_0, ...)
630 return _self_0
631 end
632 })
633 _base_0.__class = _class_0
634 if _parent_0.__inherited then
635 _parent_0.__inherited(_parent_0, _class_0)
636 end
637 Something = _class_0
638 c = _class_0
639end
640local d
641do
642 local _class_0
643 local _parent_0 = World
644 local _base_0 = { }
645 _base_0.__index = _base_0
646 setmetatable(_base_0, _parent_0.__base)
647 _class_0 = setmetatable({
648 __init = function(self, ...)
649 return _class_0.__parent.__init(self, ...)
650 end,
651 __base = _base_0,
652 __name = "d",
653 __parent = _parent_0
654 }, {
655 __index = function(cls, name)
656 local val = rawget(_base_0, name)
657 if val == nil then
658 local parent = rawget(cls, "__parent")
659 if parent then
660 return parent[name]
661 end
662 else
663 return val
664 end
665 end,
666 __call = function(cls, ...)
667 local _self_0 = setmetatable({ }, _base_0)
668 cls.__init(_self_0, ...)
669 return _self_0
670 end
671 })
672 _base_0.__class = _class_0
673 if _parent_0.__inherited then
674 _parent_0.__inherited(_parent_0, _class_0)
675 end
676 d = _class_0
677end
678print(((function()
679 local WhatsUp
680 do
681 local _class_0
682 local _base_0 = { }
683 _base_0.__index = _base_0
684 _class_0 = setmetatable({
685 __init = function() end,
686 __base = _base_0,
687 __name = "WhatsUp"
688 }, {
689 __index = _base_0,
690 __call = function(cls, ...)
691 local _self_0 = setmetatable({ }, _base_0)
692 cls.__init(_self_0, ...)
693 return _self_0
694 end
695 })
696 _base_0.__class = _class_0
697 WhatsUp = _class_0
698 return _class_0
699 end
700end)()).__name)
701do
702 local _class_0
703 local _base_0 = { }
704 _base_0.__index = _base_0
705 _class_0 = setmetatable({
706 __init = function() end,
707 __base = _base_0,
708 __name = "Something"
709 }, {
710 __index = _base_0,
711 __call = function(cls, ...)
712 local _self_0 = setmetatable({ }, _base_0)
713 cls.__init(_self_0, ...)
714 return _self_0
715 end
716 })
717 _base_0.__class = _class_0
718 local self = _class_0;
719 _ = nil
720 Something = _class_0
721end
722do
723 local _class_0
724 local val, insert
725 local _base_0 = { }
726 _base_0.__index = _base_0
727 _class_0 = setmetatable({
728 __init = function(self)
729 return print(insert, val)
730 end,
731 __base = _base_0,
732 __name = "Something"
733 }, {
734 __index = _base_0,
735 __call = function(cls, ...)
736 local _self_0 = setmetatable({ }, _base_0)
737 cls.__init(_self_0, ...)
738 return _self_0
739 end
740 })
741 _base_0.__class = _class_0
742 local self = _class_0;
743 val = 23
744 insert = table.insert
745 Something = _class_0
746end
747do
748 local _class_0
749 local _base_0 = { }
750 _base_0.__index = _base_0
751 _class_0 = setmetatable({
752 __init = hi,
753 __base = _base_0,
754 __name = "X"
755 }, {
756 __index = _base_0,
757 __call = function(cls, ...)
758 local _self_0 = setmetatable({ }, _base_0)
759 cls.__init(_self_0, ...)
760 return _self_0
761 end
762 })
763 _base_0.__class = _class_0
764 X = _class_0
765end
766do
767 local _class_0
768 local _parent_0 = Thing
769 local _base_0 = {
770 dang = function(self)
771 return {
772 hello = function()
773 return _class_0.__parent.__base.dang(self)
774 end,
775 world = function()
776 return _class_0.__parent.one
777 end
778 }
779 end
780 }
781 _base_0.__index = _base_0
782 setmetatable(_base_0, _parent_0.__base)
783 _class_0 = setmetatable({
784 __init = function(self, ...)
785 return _class_0.__parent.__init(self, ...)
786 end,
787 __base = _base_0,
788 __name = "Cool",
789 __parent = _parent_0
790 }, {
791 __index = function(cls, name)
792 local val = rawget(_base_0, name)
793 if val == nil then
794 local parent = rawget(cls, "__parent")
795 if parent then
796 return parent[name]
797 end
798 else
799 return val
800 end
801 end,
802 __call = function(cls, ...)
803 local _self_0 = setmetatable({ }, _base_0)
804 cls.__init(_self_0, ...)
805 return _self_0
806 end
807 })
808 _base_0.__class = _class_0
809 if _parent_0.__inherited then
810 _parent_0.__inherited(_parent_0, _class_0)
811 end
812 Cool = _class_0
813end
814do
815 local _class_0
816 local _parent_0 = Thing
817 local _base_0 = {
818 dang = do_something(function(self)
819 return _class_0.__parent.__base.dang(self)
820 end)
821 }
822 _base_0.__index = _base_0
823 setmetatable(_base_0, _parent_0.__base)
824 _class_0 = setmetatable({
825 __init = function(self, ...)
826 return _class_0.__parent.__init(self, ...)
827 end,
828 __base = _base_0,
829 __name = "Whack",
830 __parent = _parent_0
831 }, {
832 __index = function(cls, name)
833 local val = rawget(_base_0, name)
834 if val == nil then
835 local parent = rawget(cls, "__parent")
836 if parent then
837 return parent[name]
838 end
839 else
840 return val
841 end
842 end,
843 __call = function(cls, ...)
844 local _self_0 = setmetatable({ }, _base_0)
845 cls.__init(_self_0, ...)
846 return _self_0
847 end
848 })
849 _base_0.__class = _class_0
850 if _parent_0.__inherited then
851 _parent_0.__inherited(_parent_0, _class_0)
852 end
853 Whack = _class_0
854end
855do
856 local _class_0
857 local _parent_0 = Thing
858 local _base_0 = { }
859 _base_0.__index = _base_0
860 setmetatable(_base_0, _parent_0.__base)
861 _class_0 = setmetatable({
862 __init = function(self, ...)
863 return _class_0.__parent.__init(self, ...)
864 end,
865 __base = _base_0,
866 __name = "Wowha",
867 __parent = _parent_0
868 }, {
869 __index = function(cls, name)
870 local val = rawget(_base_0, name)
871 if val == nil then
872 local parent = rawget(cls, "__parent")
873 if parent then
874 return parent[name]
875 end
876 else
877 return val
878 end
879 end,
880 __call = function(cls, ...)
881 local _self_0 = setmetatable({ }, _base_0)
882 cls.__init(_self_0, ...)
883 return _self_0
884 end
885 })
886 _base_0.__class = _class_0
887 local self = _class_0;
888 self.butt = function()
889 _class_0.__parent.butt(self)
890 _ = _class_0.__parent.hello
891 _class_0.__parent.hello(self)
892 local _base_1 = _class_0.__parent
893 local _fn_0 = _base_1.hello
894 return _fn_0 and function(...)
895 return _fn_0(_base_1, ...)
896 end
897 end
898 self.zone = cool({
899 function()
900 _class_0.__parent.zone(self)
901 _ = _class_0.__parent.hello
902 _class_0.__parent.hello(self)
903 local _base_1 = _class_0.__parent
904 local _fn_0 = _base_1.hello
905 return _fn_0 and function(...)
906 return _fn_0(_base_1, ...)
907 end
908 end
909 })
910 if _parent_0.__inherited then
911 _parent_0.__inherited(_parent_0, _class_0)
912 end
913 Wowha = _class_0
914end
915do
916 local Test
917 do
918 local _class_0
919 local _base_0 = {
920 test = function(self)
921 return self.__class["if"] and self.__class["do"](self.__class)
922 end
923 }
924 _base_0.__index = _base_0
925 _class_0 = setmetatable({
926 __init = function(self)
927 self.__class["if"] = true
928 end,
929 __base = _base_0,
930 __name = "Test"
931 }, {
932 __index = _base_0,
933 __call = function(cls, ...)
934 local _self_0 = setmetatable({ }, _base_0)
935 cls.__init(_self_0, ...)
936 return _self_0
937 end
938 })
939 _base_0.__class = _class_0
940 local self = _class_0;
941 self["do"] = function(self)
942 return 1
943 end
944 Test = _class_0
945 end
946 local test = Test()
947 test:test()
948end
949do
950 local Test
951 do
952 local _class_0
953 local _base_0 = {
954 ["do"] = function(self)
955 return 1
956 end,
957 test = function(self)
958 return self["if"] and self["do"](self)
959 end
960 }
961 _base_0.__index = _base_0
962 _class_0 = setmetatable({
963 __init = function(self)
964 self["if"] = true
965 end,
966 __base = _base_0,
967 __name = "Test"
968 }, {
969 __index = _base_0,
970 __call = function(cls, ...)
971 local _self_0 = setmetatable({ }, _base_0)
972 cls.__init(_self_0, ...)
973 return _self_0
974 end
975 })
976 _base_0.__class = _class_0
977 Test = _class_0
978 end
979 local test = Test()
980 test:test()
981end
982do
983 local _class_0
984 local _parent_0 = lapis.Application
985 local _base_0 = {
986 ["/"] = function(self)
987 return {
988 json = {
989 status = true
990 }
991 }
992 end
993 }
994 _base_0.__index = _base_0
995 setmetatable(_base_0, _parent_0.__base)
996 _class_0 = setmetatable({
997 __init = function(self, ...)
998 return _class_0.__parent.__init(self, ...)
999 end,
1000 __base = _base_0,
1001 __parent = _parent_0
1002 }, {
1003 __index = function(cls, name)
1004 local val = rawget(_base_0, name)
1005 if val == nil then
1006 local parent = rawget(cls, "__parent")
1007 if parent then
1008 return parent[name]
1009 end
1010 else
1011 return val
1012 end
1013 end,
1014 __call = function(cls, ...)
1015 local _self_0 = setmetatable({ }, _base_0)
1016 cls.__init(_self_0, ...)
1017 return _self_0
1018 end
1019 })
1020 _base_0.__class = _class_0
1021 if _parent_0.__inherited then
1022 _parent_0.__inherited(_parent_0, _class_0)
1023 end
1024end
1025do
1026 local _class_0
1027 local _base_0 = { }
1028 local _list_0 = {
1029 B,
1030 C,
1031 D
1032 }
1033 for _index_0 = 1, #_list_0 do
1034 local _mixin_0 = _list_0[_index_0]
1035 for _key_0, _val_0 in pairs(_mixin_0.__base) do
1036 if not _key_0:match("^__") then
1037 _base_0[_key_0] = _val_0
1038 end
1039 end
1040 end
1041 _base_0.__index = _base_0
1042 _class_0 = setmetatable({
1043 __init = function() end,
1044 __base = _base_0,
1045 __name = "A"
1046 }, {
1047 __index = _base_0,
1048 __call = function(cls, ...)
1049 local _self_0 = setmetatable({ }, _base_0)
1050 cls.__init(_self_0, ...)
1051 return _self_0
1052 end
1053 })
1054 _base_0.__class = _class_0
1055 A = _class_0
1056end
1057return nil
diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua
new file mode 100644
index 0000000..9a7c478
--- /dev/null
+++ b/spec/outputs/comprehension.lua
@@ -0,0 +1,277 @@
1local items = {
2 1,
3 2,
4 3,
5 4,
6 5,
7 6
8}
9local out
10do
11 local _tbl_0 = { }
12 for k in items do
13 _tbl_0[k] = k * 2
14 end
15 out = _tbl_0
16end
17local x = {
18 hello = "world",
19 okay = 2323
20}
21local copy
22do
23 local _tbl_0 = { }
24 for k, v in pairs(x) do
25 if k ~= "okay" then
26 _tbl_0[k] = v
27 end
28 end
29 copy = _tbl_0
30end
31local _
32do
33 local _tbl_0 = { }
34 for x in yes do
35 local _key_0, _val_0 = unpack(x)
36 _tbl_0[_key_0] = _val_0
37 end
38 _ = _tbl_0
39end
40do
41 local _tbl_0 = { }
42 local _list_0 = yes
43 for _index_0 = 1, #_list_0 do
44 local x = _list_0[_index_0]
45 local _key_0, _val_0 = unpack(x)
46 _tbl_0[_key_0] = _val_0
47 end
48 _ = _tbl_0
49end
50do
51 local _tbl_0 = { }
52 for x in yes do
53 local _key_0, _val_0 = xxxx
54 _tbl_0[_key_0] = _val_0
55 end
56 _ = _tbl_0
57end
58do
59 local _tbl_0 = { }
60 local _list_0 = {
61 {
62 1,
63 2
64 },
65 {
66 3,
67 4
68 }
69 }
70 for _index_0 = 1, #_list_0 do
71 local x = _list_0[_index_0]
72 local _key_0, _val_0 = unpack((function()
73 local _accum_0 = { }
74 local _len_0 = 1
75 for i, a in ipairs(x) do
76 _accum_0[_len_0] = a * i
77 _len_0 = _len_0 + 1
78 end
79 return _accum_0
80 end)())
81 _tbl_0[_key_0] = _val_0
82 end
83 _ = _tbl_0
84end
85local n1
86do
87 local _accum_0 = { }
88 local _len_0 = 1
89 for i = 1, 10 do
90 _accum_0[_len_0] = i
91 _len_0 = _len_0 + 1
92 end
93 n1 = _accum_0
94end
95local n2
96do
97 local _accum_0 = { }
98 local _len_0 = 1
99 for i = 1, 10 do
100 if i % 2 == 1 then
101 _accum_0[_len_0] = i
102 _len_0 = _len_0 + 1
103 end
104 end
105 n2 = _accum_0
106end
107local aa
108do
109 local _accum_0 = { }
110 local _len_0 = 1
111 for x = 1, 10 do
112 for y = 5, 14 do
113 _accum_0[_len_0] = {
114 x,
115 y
116 }
117 _len_0 = _len_0 + 1
118 end
119 end
120 aa = _accum_0
121end
122local bb
123do
124 local _accum_0 = { }
125 local _len_0 = 1
126 for thing in y do
127 for i = 1, 10 do
128 _accum_0[_len_0] = y
129 _len_0 = _len_0 + 1
130 end
131 end
132 bb = _accum_0
133end
134local cc
135do
136 local _accum_0 = { }
137 local _len_0 = 1
138 for i = 1, 10 do
139 for thing in y do
140 _accum_0[_len_0] = y
141 _len_0 = _len_0 + 1
142 end
143 end
144 cc = _accum_0
145end
146local dd
147do
148 local _accum_0 = { }
149 local _len_0 = 1
150 for i = 1, 10 do
151 if cool then
152 for thing in y do
153 if x > 3 then
154 if c + 3 then
155 _accum_0[_len_0] = y
156 _len_0 = _len_0 + 1
157 end
158 end
159 end
160 end
161 end
162 dd = _accum_0
163end
164do
165 local _tbl_0 = { }
166 for i = 1, 10 do
167 _tbl_0["hello"] = "world"
168 end
169 _ = _tbl_0
170end
171local j
172do
173 local _accum_0 = { }
174 local _len_0 = 1
175 for _des_0 in things do
176 local a, b, c = _des_0[1], _des_0[2], _des_0[3]
177 _accum_0[_len_0] = a
178 _len_0 = _len_0 + 1
179 end
180 j = _accum_0
181end
182local k
183do
184 local _accum_0 = { }
185 local _len_0 = 1
186 local _list_0 = things
187 for _index_0 = 1, #_list_0 do
188 local _des_0 = _list_0[_index_0]
189 local a, b, c = _des_0[1], _des_0[2], _des_0[3]
190 _accum_0[_len_0] = a
191 _len_0 = _len_0 + 1
192 end
193 k = _accum_0
194end
195local i
196do
197 local _accum_0 = { }
198 local _len_0 = 1
199 local _list_0 = things
200 for _index_0 = 1, #_list_0 do
201 local _des_0 = _list_0[_index_0]
202 local hello, world = _des_0.hello, _des_0.world
203 _accum_0[_len_0] = hello
204 _len_0 = _len_0 + 1
205 end
206 i = _accum_0
207end
208local hj
209do
210 local _tbl_0 = { }
211 for _des_0 in things do
212 local a, b, c = _des_0[1], _des_0[2], _des_0[3]
213 _tbl_0[a] = c
214 end
215 hj = _tbl_0
216end
217local hk
218do
219 local _tbl_0 = { }
220 local _list_0 = things
221 for _index_0 = 1, #_list_0 do
222 local _des_0 = _list_0[_index_0]
223 local a, b, c = _des_0[1], _des_0[2], _des_0[3]
224 _tbl_0[a] = c
225 end
226 hk = _tbl_0
227end
228local hi
229do
230 local _tbl_0 = { }
231 local _list_0 = things
232 for _index_0 = 1, #_list_0 do
233 local _des_0 = _list_0[_index_0]
234 local hello, world = _des_0.hello, _des_0.world
235 _tbl_0[hello] = world
236 end
237 hi = _tbl_0
238end
239for _des_0 in things do
240 local a, b, c = _des_0[1], _des_0[2], _des_0[3]
241 ok(a, b, c)
242end
243do
244 local _accum_0 = { }
245 local _len_0 = 1
246 local _max_0 = 3 + 4
247 for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do
248 local item = items[_index_0]
249 _accum_0[_len_0] = item
250 _len_0 = _len_0 + 1
251 end
252 _ = _accum_0
253end
254do
255 local _accum_0 = { }
256 local _len_0 = 1
257 local _max_0 = 2 - thing[4]
258 for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 or _max_0 do
259 local item = items[_index_0]
260 _accum_0[_len_0] = item
261 _len_0 = _len_0 + 1
262 end
263 _ = _accum_0
264end
265local list
266do
267 local _accum_0 = { }
268 local _len_0 = 1
269 for item in items do
270 if item ~= nil then
271 _accum_0[_len_0] = item:invoke(123)
272 end
273 _len_0 = _len_0 + 1
274 end
275 list = _accum_0
276end
277return nil
diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua
new file mode 100644
index 0000000..5efa237
--- /dev/null
+++ b/spec/outputs/cond.lua
@@ -0,0 +1,272 @@
1local you_cool = false
2local _
3if cool then
4 if you_cool then
5 _ = one
6 else
7 if eatdic then
8 _ = yeah
9 else
10 _ = two
11 _ = three
12 end
13 end
14else
15 _ = no
16end
17if cool then
18 _ = no
19end
20if cool then
21 _ = no
22else
23 _ = yes
24end
25if cool then
26 wow(cool)
27else
28 noso(cool)
29end
30if working then
31 if cool then
32 if cool then
33 _ = okay
34 else
35 _ = what
36 end
37 else
38 _ = nah
39 end
40end
41if yeah then
42 no(day)
43elseif cool(me) then
44 okay(ya)
45else
46 u(way)
47end
48if yeah then
49 no(dad)
50else
51 if cool(you) then
52 okay(bah)
53 else
54 p(way)
55 end
56end
57if (function() end)() then
58 what(ever)
59end
60if nil then
61 flip(me)
62else
63 it(be, rad)
64end
65if things(great) then
66 no(way)
67elseif okay(sure) then
68 what(here)
69end
70if things then
71 no(chance)
72elseif okay then
73 what(now)
74end
75if things then
76 yes(man)
77elseif okay(person) then
78 hi(there)
79else
80 hmm(sure)
81end
82if lets(go) then
83 print("greetings")
84elseif "just us" then
85 print("will smith")
86else
87 show(5555555)
88end
89do
90 local something = 10
91 if something then
92 print(something)
93 else
94 print("else")
95 end
96end
97local hello
98do
99 local something = 10
100 if something then
101 hello = print(something)
102 else
103 hello = print("else")
104 end
105end
106hello = 5 + (function()
107 local something = 10
108 if something then
109 return print(something)
110 end
111end)()
112local z = false
113if false then
114 _ = one
115else
116 do
117 local x = true
118 if x then
119 _ = two
120 else
121 z = true
122 if z then
123 _ = three
124 else
125 _ = four
126 end
127 end
128 end
129end
130local out
131if false then
132 out = one
133else
134 do
135 local x = true
136 if x then
137 out = two
138 else
139 z = true
140 if z then
141 out = three
142 else
143 out = four
144 end
145 end
146 end
147end
148local kzy
149kzy = function()
150 do
151 local something = true
152 if something then
153 return 1
154 else
155 do
156 local another = false
157 if another then
158 return 2
159 end
160 end
161 end
162 end
163end
164if not true then
165 print("cool!")
166end
167if not (true and false) then
168 print("cool!")
169end
170if not false then
171 print("cool!")
172end
173if not false then
174 print("cool!")
175else
176 print("no way!")
177end
178if not nil then
179 print("hello")
180else
181 print("world")
182end
183local x
184if not true then
185 x = print("cool!")
186end
187if not (true and false) then
188 x = print("cool!")
189end
190local y
191if not false then
192 y = print("cool!")
193end
194if not false then
195 y = print("cool!")
196else
197 y = print("no way!")
198end
199if not nil then
200 z = print("hello")
201else
202 z = print("world")
203end
204print((function()
205 if not true then
206 return print("cool!")
207 end
208end)())
209print((function()
210 if not (true and false) then
211 return print("cool!")
212 end
213end)())
214print((function()
215 if not false then
216 return print("cool!")
217 end
218end)())
219print((function()
220 if not false then
221 return print("cool!")
222 else
223 return print("no way!")
224 end
225end)())
226print((function()
227 if not nil then
228 return print("hello")
229 else
230 return print("world")
231 end
232end)())
233if not value then
234 print("hello")
235end
236local dddd
237if not value then
238 dddd = {
239 1,
240 2,
241 3
242 }
243end
244do
245 local j = 100
246 j = hi()
247 if not j then
248 error("not j!")
249 end
250end
251local a = 12
252local c, b
253if something then
254 a, c, b = "cool"
255end
256local j
257if 1 then
258 if 2 then
259 j = 3
260 end
261else
262 j = 6
263end
264local m
265if 1 then
266 if 2 then
267 m = 3
268 end
269else
270 m = 6
271end
272return nil
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua
new file mode 100644
index 0000000..9ca13c8
--- /dev/null
+++ b/spec/outputs/destructure.lua
@@ -0,0 +1,357 @@
1do
2 local a, b
3 do
4 local _obj_0 = hello
5 a, b = _obj_0[1], _obj_0[2]
6 end
7 local c
8 do
9 local _obj_0 = hello
10 a, b, c = _obj_0[1][1], _obj_0[2], _obj_0[3][1]
11 end
12 local hello, world
13 do
14 local _obj_0 = value
15 hello, world = _obj_0.hello, _obj_0.world
16 end
17end
18do
19 local no, thing
20 do
21 local _obj_0 = world
22 no, thing = _obj_0.yes, _obj_0[1]
23 end
24 local a, b, c, d
25 do
26 local _obj_0 = yeah
27 a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d
28 end
29 local _ = two
30 a = one[1]
31 c = nil
32 b = one[1]
33 local e = two
34 d = one[1]
35 local x = one
36 local y = two[1]
37 local xx, yy = 1, 2
38 do
39 local _obj_0 = {
40 xx,
41 yy
42 }
43 yy, xx = _obj_0[1], _obj_0[2]
44 end
45 local f, g
46 do
47 local _obj_0 = tbl
48 a, b, c, d, e, f, g = _obj_0[1], _obj_0.b, _obj_0[2], _obj_0.d, _obj_0[3], _obj_0.f, _obj_0[4]
49 end
50 do
51 c = nil
52 do
53 local _obj_0 = tbl
54 a, b = _obj_0.a, _obj_0.b
55 end
56 end
57 do
58 a = tbl
59 b, c = _.b, _.c
60 end
61 do
62 b = _
63 a = tbl.a
64 c = _.c
65 end
66end
67do
68 local futurists = {
69 sculptor = "Umberto Boccioni",
70 painter = "Vladimir Burliuk",
71 poet = {
72 name = "F.T. Marinetti",
73 address = {
74 "Via Roma 42R",
75 "Bellagio, Italy 22021"
76 }
77 }
78 }
79 do
80 local name, street, city = futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2]
81 end
82 do
83 local sculptor, painter, name, street, city = futurists.sculptor, futurists.painter, futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2]
84 end
85end
86do
87 local c, e
88 do
89 local _obj_0 = tb
90 c, e = _obj_0.a.b, _obj_0.a.d
91 end
92end
93do
94 local c, e, f
95 do
96 local _obj_0 = tb
97 c, e, f = _obj_0.a[1].b, _obj_0.a[2].d, _obj_0.a[3]
98 end
99end
100do
101 self.world = x[1]
102 do
103 local _obj_0 = x
104 a.b, c.y, func().z = _obj_0[1], _obj_0[2], _obj_0[3]
105 end
106 self.world = x.world
107end
108do
109 local thing = {
110 {
111 1,
112 2
113 },
114 {
115 3,
116 4
117 }
118 }
119 for _index_0 = 1, #thing do
120 local _des_0 = thing[_index_0]
121 local x, y = _des_0[1], _des_0[2]
122 print(x, y)
123 end
124end
125do
126 do
127 local _with_0 = thing
128 local a, b = _with_0[1], _with_0[2]
129 print(a, b)
130 end
131end
132do
133 local thing = nil
134 if thing then
135 local a = thing[1]
136 print(a)
137 else
138 print("nothing")
139 end
140 local thang = {
141 1,
142 2
143 }
144 if thang then
145 local a, b = thang[1], thang[2]
146 print(a, b)
147 end
148 if thing then
149 local a, b = thing[1], thing[2]
150 print(a, b)
151 else
152 if thang then
153 local c, d = thang[1], thang[2]
154 print(c, d)
155 else
156 print("NO")
157 end
158 end
159end
160do
161 local z = "yeah"
162 local a, b, c = z[1], z[2], z[3]
163end
164do
165 local a, b, c
166 do
167 local _obj_0 = z
168 a, b, c = _obj_0[1], _obj_0[2], _obj_0[3]
169 end
170end
171local _
172_ = function(z)
173 local a, b, c = z[1], z[2], z[3]
174end
175do
176 local z = "oo"
177 _ = function(k)
178 local a, b, c = z[1], z[2], z[3]
179 end
180end
181do
182 local endVar = thing["function"]["end"]
183end
184do
185 local a, b, c
186 do
187 local _obj_0 = thing
188 a, b, c = _obj_0["if"][1], _obj_0["if"][2], _obj_0["if"][3]
189 end
190end
191do
192 local a, b
193 if true then
194 do
195 local _obj_0 = {
196 a = "Hello",
197 b = "World"
198 }
199 a, b = _obj_0.a, _obj_0.b
200 end
201 end
202 local days, hours, mins, secs
203 do
204 local _accum_0 = { }
205 local _len_0 = 1
206 local _list_0 = {
207 string.match("1 2 3 4", "(.+)%s(.+)%s(.+)%s(.+)")
208 }
209 for _index_0 = 1, #_list_0 do
210 local a = _list_0[_index_0]
211 _accum_0[_len_0] = tonumber(a)
212 _len_0 = _len_0 + 1
213 end
214 days, hours, mins, secs = _accum_0[1], _accum_0[2], _accum_0[3], _accum_0[4]
215 end
216 local one, two, three
217 do
218 local _tbl_0 = { }
219 for w in foo:gmatch("%S+") do
220 _tbl_0[w] = true
221 end
222 one, two, three = _tbl_0.one, _tbl_0.two, _tbl_0.three
223 end
224 b = 123
225 a = (a["if"](a, 123) + t).a
226end
227do
228 local name, job
229 do
230 local _obj_0 = person
231 name, job = _obj_0.name, _obj_0.job
232 end
233 if name == nil then
234 name = "nameless"
235 end
236 if job == nil then
237 job = "jobless"
238 end
239 local request
240 request = function(url, options)
241 if options == nil then
242 options = { }
243 end
244 local method, headers, parameters, payload, ok, err, final = options.method, options.headers, options.parameters, options.payload, options.ok, options.err, options.final
245 if method == nil then
246 method = "GET"
247 end
248 if headers == nil then
249 headers = { }
250 end
251 if parameters == nil then
252 parameters = { }
253 end
254 if payload == nil then
255 payload = ""
256 end
257 local res = makeRequest(url, method, parameters, payload, ok, err, final)
258 return res
259 end
260 local value1, key3
261 do
262 local _obj_0 = tb
263 value1, key3 = _obj_0.key1.key2, _obj_0.key3
264 end
265 if value1 == nil then
266 value1 = 123
267 end
268 if key3 == nil then
269 key3 = "abc"
270 end
271 local mt, call, add
272 do
273 local _obj_0 = getmetatable(tb)
274 mt, call, add = _obj_0, getmetatable(_obj_0).__call, getmetatable(_obj_0).__add
275 end
276 if mt == nil then
277 mt = {
278 __index = {
279 abc = 123
280 }
281 }
282 end
283 if call == nil then
284 call = (function()
285 return { }
286 end)
287 end
288 local _obj_0 = tb
289 local mtx, y, zItem = getmetatable(_obj_0.x), _obj_0.y, _obj_0.z
290 if mtx == nil then
291 mtx = { }
292 end
293 local index = getmetatable(_obj_0).__index
294 if index == nil then
295 index = function()
296 return nil
297 end
298 end
299 local _obj_1 = getmetatable(tb).func
300 if _obj_1 == nil then
301 if item ~= nil then
302 _obj_1 = item.defVal
303 end
304 end
305 a.b(function()
306 return 123
307 end).c = _obj_1
308end
309do
310 local mt, subFunc
311 do
312 local _obj_0 = getmetatable(tb.x)
313 mt, subFunc = _obj_0, _obj_0.__sub
314 end
315 if mt == nil then
316 mt = { }
317 end
318end
319do
320 local mt, subFunc
321 do
322 local _obj_0 = tb
323 mt, subFunc = getmetatable(_obj_0.x), getmetatable(_obj_0.x).__sub
324 end
325 if mt == nil then
326 mt = { }
327 end
328end
329do
330 local a, b, _obj_0
331 do
332 local _obj_1 = tb
333 a, b, _obj_0 = _obj_1[1], _obj_1[2], _obj_1.c[1]
334 end
335 if a == nil then
336 a = 1
337 end
338 if b == nil then
339 b = 2
340 end
341 if _obj_0 == nil then
342 _obj_0 = 3
343 end
344 d.e = _obj_0
345 local _list_0 = tuples
346 for _index_0 = 1, #_list_0 do
347 local _des_0 = _list_0[_index_0]
348 local left, right = _des_0[1], _des_0[2]
349 if left == nil then
350 left = "null"
351 end
352 if right == nil then
353 right = false
354 end
355 print(left, right)
356 end
357end
diff --git a/spec/outputs/do.lua b/spec/outputs/do.lua
new file mode 100644
index 0000000..96d1022
--- /dev/null
+++ b/spec/outputs/do.lua
@@ -0,0 +1,48 @@
1do
2 print("hello")
3 print("world")
4end
5local x
6do
7 print("hello")
8 x = print("world")
9end
10local y
11do
12 local things = "shhh"
13 y = function()
14 return "hello: " .. things
15 end
16end
17local _
18_ = function()
19 if something then
20 do
21 return "yeah"
22 end
23 end
24end
25local t = {
26 y = (function()
27 local number = 100
28 return function(x)
29 return x + number
30 end
31 end)()
32}
33return function(y, k)
34 if y == nil then
35 y = ((function()
36 x = 10 + 2
37 return x
38 end)())
39 end
40 if k == nil then
41 do
42 k = "nothing"
43 end
44 end
45 do
46 return "uhhh"
47 end
48end
diff --git a/spec/outputs/existential.lua b/spec/outputs/existential.lua
new file mode 100644
index 0000000..4a64c49
--- /dev/null
+++ b/spec/outputs/existential.lua
@@ -0,0 +1,156 @@
1if f1 ~= nil then
2 f1()
3end
4if f2 ~= nil then
5 f2("arg0", 123)
6end
7local x
8if tab ~= nil then
9 x = tab.value
10end
11print((function()
12 if abc ~= nil then
13 local _obj_0 = abc["hello world"]
14 if _obj_0 ~= nil then
15 return _obj_0.xyz
16 end
17 return nil
18 end
19 return nil
20end)())
21if print and (x ~= nil) then
22 print(x)
23end
24if self ~= nil then
25 self:func(998)
26end
27do
28 local _with_0
29 if abc ~= nil then
30 local _obj_0 = abc()
31 local _obj_1 = _obj_0.func
32 if _obj_1 ~= nil then
33 _with_0 = _obj_1(_obj_0)
34 end
35 end
36 if (function()
37 local _obj_0 = _with_0.p
38 if _obj_0 ~= nil then
39 return _obj_0(_with_0, "abc")
40 end
41 return nil
42 end)() then
43 return 123
44 end
45end
46do
47 local _des_0
48 if a ~= nil then
49 local _obj_0 = a["if"]
50 if _obj_0 ~= nil then
51 local _obj_1 = _obj_0["then"]
52 if _obj_1 ~= nil then
53 local _obj_2 = _obj_1(_obj_0, 123)
54 if _obj_2 ~= nil then
55 _des_0 = _obj_2((function()
56 if self ~= nil then
57 return self["function"](self, 998)
58 end
59 return nil
60 end)())
61 end
62 end
63 end
64 end
65 if _des_0 then
66 x = _des_0.x
67 print(x)
68 end
69end
70local res = ((function()
71 local _call_0 = b["function"]
72 local _obj_0 = _call_0["do"](_call_0)
73 local _obj_1 = _obj_0["while"]
74 if _obj_1 ~= nil then
75 local _call_1 = _obj_1(_obj_0, "OK")
76 local _base_0 = _call_1["if"](_call_1, "def", 998)
77 local _fn_0 = _base_0.f
78 return _fn_0 and function(...)
79 return _fn_0(_base_0, ...)
80 end
81 end
82 return nil
83end)() ~= nil)
84print(res)
85local solipsism
86if (mind ~= nil) and not (world ~= nil) then
87 solipsism = true
88end
89local speed = 0
90speed = speed or 15
91local footprints = yeti or "bear"
92local major = 'Computer Science'
93if not (major ~= nil) then
94 signUpForClass('Introduction to Wines')
95end
96if (window ~= nil) then
97 local environment = 'browser (probably)'
98end
99local zip
100local _obj_0 = lottery.drawWinner
101if _obj_0 ~= nil then
102 local _obj_1 = _obj_0().address
103 if _obj_1 ~= nil then
104 zip = _obj_1.zipcode
105 end
106end
107local len = (function()
108 if utf8 ~= nil then
109 return utf8.len
110 end
111 return nil
112end)() or (function()
113 if string ~= nil then
114 return string.len
115 end
116 return nil
117end)() or function(o)
118 return #o
119end
120local a
121if tb1 ~= nil then
122 local _obj_1 = tb1["end"]
123 if _obj_1 ~= nil then
124 a = _obj_1(tb1, 123 + (function()
125 if tb2 ~= nil then
126 return tb2["then"](tb2, 456)
127 end
128 return nil
129 end)())
130 end
131end
132local b = ((function()
133 if tb1 ~= nil then
134 local _base_0 = tb1
135 local _fn_0 = _base_0["end"]
136 return _fn_0 and function(...)
137 return _fn_0(_base_0, ...)
138 end
139 end
140 return nil
141end)() ~= nil) or (function()
142 if tb2 ~= nil then
143 local _base_0 = tb2
144 local _fn_0 = _base_0["then"]
145 return _fn_0 and function(...)
146 return _fn_0(_base_0, ...)
147 end
148 end
149 return nil
150end)()
151local _with_0 = io.open("test.txt", "w")
152if _with_0 ~= nil then
153 _with_0:write("hello")
154 _with_0:close()
155end
156return _with_0
diff --git a/spec/outputs/export.lua b/spec/outputs/export.lua
new file mode 100644
index 0000000..02546ec
--- /dev/null
+++ b/spec/outputs/export.lua
@@ -0,0 +1,307 @@
1local _module_0 = { }
2local a, b, c = 223, 343, 123
3_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
4local cool = "dad"
5_module_0["cool"] = cool
6local d, e, f = 3, 2, 1
7_module_0[#_module_0 + 1] = d
8_module_0[#_module_0 + 1] = e
9_module_0[#_module_0 + 1] = f
10local Something
11do
12 local _class_0
13 local _base_0 = {
14 umm = "cool"
15 }
16 _base_0.__index = _base_0
17 _class_0 = setmetatable({
18 __init = function() end,
19 __base = _base_0,
20 __name = "Something"
21 }, {
22 __index = _base_0,
23 __call = function(cls, ...)
24 local _self_0 = setmetatable({ }, _base_0)
25 cls.__init(_self_0, ...)
26 return _self_0
27 end
28 })
29 _base_0.__class = _class_0
30 Something = _class_0
31end
32_module_0["Something"] = Something
33if this then
34 _module_0[#_module_0 + 1] = 232
35else
36 _module_0[#_module_0 + 1] = 4343
37end
38local What
39if this then
40 What = 232
41else
42 What = 4343
43end
44_module_0["What"] = What
45local y
46y = function()
47 local hallo = 3434
48end
49_module_0["y"] = y
50do
51 local _with_0 = tmp
52 local j = 2000
53 _module_0[#_module_0 + 1] = _with_0
54end
55local cbVal
56do
57 local h = 100
58 cbVal = f(function(x)
59 return x(h)
60 end)
61end
62_module_0["cbVal"] = cbVal
63y = function()
64 local h = 100
65 local k = 100
66end
67_module_0["y"] = y
68local _exp_0 = h
69if 100 == _exp_0 or 150 == _exp_0 then
70 _module_0[#_module_0 + 1] = 200
71elseif 200 == _exp_0 then
72 _module_0[#_module_0 + 1] = 300
73else
74 _module_0[#_module_0 + 1] = 0
75end
76local Constant
77local _exp_1 = value
78if "good" == _exp_1 then
79 Constant = 1
80elseif "better" == _exp_1 then
81 Constant = 2
82elseif "best" == _exp_1 then
83 Constant = 3
84end
85_module_0["Constant"] = Constant
86local item = func(123)
87_module_0["item"] = item
88_module_0[#_module_0 + 1] = x
89f((function()
90 if a then
91 return b
92 end
93end)())
94f((function()
95 return 123
96end)())
97f((function()
98 if b == a then
99 return c
100 end
101end)())
102f((function()
103 local _accum_0 = { }
104 local _len_0 = 1
105 for i = 1, 10 do
106 _accum_0[_len_0] = i
107 _len_0 = _len_0 + 1
108 end
109 return _accum_0
110end)())
111f((function()
112 local _accum_0 = { }
113 local _len_0 = 1
114 for i = 1, 10 do
115 _accum_0[_len_0] = i
116 _len_0 = _len_0 + 1
117 end
118 return _accum_0
119end)())
120f((function()
121 local _tbl_0 = { }
122 for k, v in pairs(tb) do
123 _tbl_0[k] = v
124 end
125 return _tbl_0
126end)())
127f((function()
128 local _accum_0 = { }
129 local _len_0 = 1
130 for k, v in pairs(tb) do
131 _accum_0[_len_0] = k, v
132 _len_0 = _len_0 + 1
133 end
134 return _accum_0
135end)())
136f((function()
137 local _accum_0 = { }
138 local _len_0 = 1
139 while a do
140 _accum_0[_len_0] = true
141 _len_0 = _len_0 + 1
142 end
143 return _accum_0
144end)())
145f((function()
146 a.b = 123
147 return a
148end)())
149f((function()
150 if a ~= nil then
151 return a.b
152 end
153 return nil
154end)())
155f((function()
156 local _base_0 = a
157 local _fn_0 = _base_0.b
158 return _fn_0 and function(...)
159 return _fn_0(_base_0, ...)
160 end
161end)())
162f((function()
163 local A
164 do
165 local _class_0
166 local _base_0 = { }
167 _base_0.__index = _base_0
168 _class_0 = setmetatable({
169 __init = function() end,
170 __base = _base_0,
171 __name = "A"
172 }, {
173 __index = _base_0,
174 __call = function(cls, ...)
175 local _self_0 = setmetatable({ }, _base_0)
176 cls.__init(_self_0, ...)
177 return _self_0
178 end
179 })
180 _base_0.__class = _class_0
181 A = _class_0
182 return _class_0
183 end
184end)())
185local _ = tostring((function()
186 if a then
187 return b
188 end
189end)())
190_ = tostring((function()
191 return 123
192end)())
193_ = tostring((function()
194 if b == a then
195 return c
196 end
197end)())
198_ = tostring((function()
199 local _accum_0 = { }
200 local _len_0 = 1
201 for i = 1, 10 do
202 _accum_0[_len_0] = i
203 _len_0 = _len_0 + 1
204 end
205 return _accum_0
206end)())
207_ = tostring((function()
208 local _accum_0 = { }
209 local _len_0 = 1
210 for i = 1, 10 do
211 _accum_0[_len_0] = i
212 _len_0 = _len_0 + 1
213 end
214 return _accum_0
215end)())
216_ = tostring((function()
217 local _tbl_0 = { }
218 for k, v in pairs(tb) do
219 _tbl_0[k] = v
220 end
221 return _tbl_0
222end)())
223_ = tostring((function()
224 local _accum_0 = { }
225 local _len_0 = 1
226 for k, v in pairs(tb) do
227 _accum_0[_len_0] = k, v
228 _len_0 = _len_0 + 1
229 end
230 return _accum_0
231end)())
232_ = tostring((function()
233 local _accum_0 = { }
234 local _len_0 = 1
235 while a do
236 _accum_0[_len_0] = true
237 _len_0 = _len_0 + 1
238 end
239 return _accum_0
240end)())
241_ = tostring((function()
242 a.b = 123
243 return a
244end)())
245_ = tostring((function()
246 if a ~= nil then
247 return a.b
248 end
249 return nil
250end)())
251_ = tostring((function()
252 local _base_0 = a
253 local _fn_0 = _base_0.b
254 return _fn_0 and function(...)
255 return _fn_0(_base_0, ...)
256 end
257end)())
258_ = tostring((function()
259 local A
260 do
261 local _class_0
262 local _base_0 = { }
263 _base_0.__index = _base_0
264 _class_0 = setmetatable({
265 __init = function() end,
266 __base = _base_0,
267 __name = "A"
268 }, {
269 __index = _base_0,
270 __call = function(cls, ...)
271 local _self_0 = setmetatable({ }, _base_0)
272 cls.__init(_self_0, ...)
273 return _self_0
274 end
275 })
276 _base_0.__class = _class_0
277 A = _class_0
278 return _class_0
279 end
280end)())
281local v1, v2, v3, v4, v5
282v1 = 1
283v2 = 2
284_module_0["v2"] = v2
285do
286 local _class_0
287 local _base_0 = { }
288 _base_0.__index = _base_0
289 _class_0 = setmetatable({
290 __init = function() end,
291 __base = _base_0,
292 __name = "v4"
293 }, {
294 __index = _base_0,
295 __call = function(cls, ...)
296 local _self_0 = setmetatable({ }, _base_0)
297 cls.__init(_self_0, ...)
298 return _self_0
299 end
300 })
301 _base_0.__class = _class_0
302 v4 = _class_0
303 v3 = _class_0
304end
305_module_0["v3"] = v3
306v5 = 5
307return _module_0
diff --git a/spec/outputs/export_default.lua b/spec/outputs/export_default.lua
new file mode 100644
index 0000000..a9c787f
--- /dev/null
+++ b/spec/outputs/export_default.lua
@@ -0,0 +1,19 @@
1local _module_0 = nil
2print("OK")
3_module_0 = function()
4 print("hello")
5 return 123
6end
7if not isOff then
8 f(123, "abc", function(x, fy)
9 print(x)
10 return fy(function(y, res)
11 if res then
12 return abc + y
13 else
14 return abc
15 end
16 end)
17 end)
18end
19return _module_0
diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua
new file mode 100644
index 0000000..03281e4
--- /dev/null
+++ b/spec/outputs/funcs.lua
@@ -0,0 +1,222 @@
1local x
2x = function()
3 return print(what)
4end
5local _
6_ = function() end
7_ = function()
8 return function()
9 return function() end
10 end
11end
12go(to(the(barn)))
13open(function()
14 return the(function()
15 return door
16 end)
17end)
18open(function()
19 the(door)
20 local hello
21 hello = function()
22 return my(func)
23 end
24end)
25local h
26h = function()
27 return hi
28end
29eat(function() end, world);
30(function() end)()
31x = function(...) end
32hello()
33hello.world()
34_ = hello().something
35_ = what()["ofefe"]
36what()(the()(heck()))
37_ = function(a, b, c, d, e) end
38_ = function(a, a, a, a, a)
39 return print(a)
40end
41_ = function(x)
42 if x == nil then
43 x = 23023
44 end
45end
46_ = function(x)
47 if x == nil then
48 x = function(y)
49 if y == nil then
50 y = function() end
51 end
52 end
53 end
54end
55_ = function(x)
56 if x == nil then
57 if something then
58 x = yeah
59 else
60 x = no
61 end
62 end
63end
64local something
65something = function(hello, world)
66 if hello == nil then
67 hello = 100
68 end
69 if world == nil then
70 world = function(x)
71 if x == nil then
72 x = [[yeah cool]]
73 end
74 return print("eat rice")
75 end
76 end
77 return print(hello)
78end
79_ = function(self) end
80_ = function(self, x, y) end
81_ = function(self, x, y)
82 self.x = x
83 self.y = y
84end
85_ = function(self, x)
86 if x == nil then
87 x = 1
88 end
89end
90_ = function(self, x, y, z)
91 if x == nil then
92 x = 1
93 end
94 if z == nil then
95 z = "hello world"
96 end
97 self.x = x
98 self.z = z
99end
100x(function()
101 return
102end)
103y(function()
104 return 1
105end)
106z(function()
107 return 1, "hello", "world"
108end)
109k(function()
110 if yes then
111 return
112 else
113 return
114 end
115end)
116_ = function()
117 if something then
118 return real_name
119 end
120end
121d(function()
122 return print("hello world")
123end, 10)
124d(1, 2, 3, 4, 5, 6, (function()
125 if something then
126 print("okay")
127 return 10
128 end
129end)(), 10, 20)
130f()()(what)(function()
131 return print("srue")
132end, 123)
133x = function(a, b)
134 return print("what")
135end
136local y
137y = function(a, b)
138 if a == nil then
139 a = "hi"
140 end
141 if b == nil then
142 b = 23
143 end
144 return print("what")
145end
146local z
147z = function(a, b)
148 if a == nil then
149 a = "hi"
150 end
151 if b == nil then
152 b = 23
153 end
154 return print("what")
155end
156local j
157j = function(f, g, m, a, b)
158 if a == nil then
159 a = "hi"
160 end
161 if b == nil then
162 b = 23
163 end
164 return print("what")
165end
166y = function(a, b, ...)
167 if a == nil then
168 a = "hi"
169 end
170 if b == nil then
171 b = 23
172 end
173 return print("what")
174end
175y = function(a, b, ...)
176 if a == nil then
177 a = "hi"
178 end
179 if b == nil then
180 b = 23
181 end
182 return print("what")
183end
184local args
185args = function(a, b)
186 return print("what")
187end
188args = function(a, b)
189 if a == nil then
190 a = "hi"
191 end
192 if b == nil then
193 b = 23
194 end
195 return print("what")
196end
197args = function(a, b)
198 if a == nil then
199 a = "hi"
200 end
201 if b == nil then
202 b = 23
203 end
204 return print("what")
205end
206args = function(f, g, m, a, b)
207 if a == nil then
208 a = "hi"
209 end
210 if b == nil then
211 b = 23
212 end
213 return print("what")
214end
215local self
216self = function(n)
217 if n == 0 then
218 return 1
219 end
220 return n * self(n - 1)
221end
222return nil
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua
new file mode 100644
index 0000000..1c9a3cf
--- /dev/null
+++ b/spec/outputs/global.lua
@@ -0,0 +1,89 @@
1do
2 a, b, c = 223, 343
3 cool = "dad"
4end
5do
6 do
7 local _class_0
8 local _base_0 = {
9 umm = "cool"
10 }
11 _base_0.__index = _base_0
12 _class_0 = setmetatable({
13 __init = function() end,
14 __base = _base_0,
15 __name = "Something"
16 }, {
17 __index = _base_0,
18 __call = function(cls, ...)
19 local _self_0 = setmetatable({ }, _base_0)
20 cls.__init(_self_0, ...)
21 return _self_0
22 end
23 })
24 _base_0.__class = _class_0
25 Something = _class_0
26 end
27end
28do
29 local d
30 a, b, c, d = "hello"
31end
32do
33 local What
34 if this then
35 What = 232
36 else
37 What = 4343
38 end
39 local another = 3434
40 Another = 7890
41 if inner then
42 local Yeah = "10000"
43 end
44 if this then
45 What = 232
46 else
47 What = 4343
48 end
49end
50do
51 if this then
52 What = 232
53 else
54 What = 4343
55 end
56 x, y, z = 1, 2, 3
57 y = function()
58 local hallo = 3434
59 end
60 do
61 local _with_0 = tmp
62 local j = 2000
63 end
64end
65do
66 x = 3434
67 if y then
68 x = 10
69 end
70end
71do
72 if y then
73 local x = 10
74 end
75 x = 3434
76end
77do
78 do
79 k = 1212
80 do
81 local h = 100
82 end
83 y = function()
84 local h = 100
85 k = 100
86 end
87 end
88 local h = 100
89end
diff --git a/spec/outputs/goto.lua b/spec/outputs/goto.lua
new file mode 100644
index 0000000..d1f7b77
--- /dev/null
+++ b/spec/outputs/goto.lua
@@ -0,0 +1,67 @@
1do
2 local a = 0
3 ::start::
4 a = a + 1
5 if a == 5 then
6 goto done
7 end
8 goto start
9 ::done::
10end
11do
12 for z = 1, 10 do
13 for y = 1, 10 do
14 for x = 1, 10 do
15 if x ^ 2 + y ^ 2 == z ^ 2 then
16 print('found a Pythagorean triple:', x, y, z)
17 goto done
18 end
19 end
20 end
21 end
22 ::done::
23end
24do
25 for z = 1, 10 do
26 for y = 1, 10 do
27 for x = 1, 10 do
28 if x ^ 2 + y ^ 2 == z ^ 2 then
29 print('found a Pythagorean triple:', x, y, z)
30 print('now trying next z...')
31 goto zcontinue
32 end
33 end
34 end
35 ::zcontinue::
36 end
37end
38do
39 ::redo::
40 for x = 1, 10 do
41 for y = 1, 10 do
42 if not f(x, y) then
43 goto continue
44 end
45 if not g(x, y) then
46 goto skip
47 end
48 if not h(x, y) then
49 goto redo
50 end
51 ::continue::
52 end
53 end
54 ::skip::
55end
56do
57 local _list_0 = t
58 for _index_0 = 1, #_list_0 do
59 local x = _list_0[_index_0]
60 if x % 2 == 0 then
61 print('list has even number')
62 goto has
63 end
64 end
65 print('list lacks even number')
66 ::has::
67end
diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua
new file mode 100644
index 0000000..02e210b
--- /dev/null
+++ b/spec/outputs/import.lua
@@ -0,0 +1,92 @@
1local hello = yeah.hello
2local world
3do
4 local _obj_0 = table["cool"]
5 hello, world = _obj_0.hello, _obj_0.world
6end
7local a, b, c = items.a, (function()
8 local _base_0 = items
9 local _fn_0 = _base_0.b
10 return _fn_0 and function(...)
11 return _fn_0(_base_0, ...)
12 end
13end)(), items.c
14local master, ghost
15do
16 local _obj_0 = find("mytable")
17 master, ghost = _obj_0.master, (function()
18 local _base_0 = _obj_0
19 local _fn_0 = _base_0.ghost
20 return _fn_0 and function(...)
21 return _fn_0(_base_0, ...)
22 end
23 end)()
24end
25local yumm
26a, yumm = 3434, "hello"
27local _table_0 = 232
28local something
29do
30 local _obj_0 = a(table)
31 something = _obj_0.something
32end
33if indent then
34 local okay, well
35 do
36 local _obj_0 = tables[100]
37 okay, well = _obj_0.okay, (function()
38 local _base_0 = _obj_0
39 local _fn_0 = _base_0.well
40 return _fn_0 and function(...)
41 return _fn_0(_base_0, ...)
42 end
43 end)()
44 end
45end
46do
47 a, b, c = z.a, z.b, z.c
48end
49do
50 a, b, c = z.a, z.b, z.c
51end
52do
53 a, b, c = z.a, z.b, z.c
54end
55do
56 a, b, c = z.a, z.b, z.c
57end
58do
59 a, b, c = z.a, z.b, z.c
60end
61do
62 local module = require('module')
63 local module_x = require('module_x')
64 local d_a_s_h_e_s = require("d-a-s-h-e-s")
65 local part = require("module.part")
66end
67do
68 local Player = require("player")
69 local C, Ct, Cmt
70 do
71 local _obj_0 = require("lpeg")
72 C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt
73 end
74 local one, two, ch
75 do
76 local _obj_0 = require("export")
77 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
78 end
79 local Another = require("export").Another
80end
81do
82 module = require('module')
83 module_x = require('module_x')
84 module_y = require("org.package.module-y")
85end
86do
87 local func, ifVar
88 do
89 local _obj_0 = require("org.package.module")
90 func, ifVar = _obj_0["function"], _obj_0["if"]
91 end
92end
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua
new file mode 100644
index 0000000..581cc23
--- /dev/null
+++ b/spec/outputs/lists.lua
@@ -0,0 +1,282 @@
1local hi
2do
3 local _accum_0 = { }
4 local _len_0 = 1
5 for _, x in ipairs({
6 1,
7 2,
8 3,
9 4
10 }) do
11 _accum_0[_len_0] = x * 2
12 _len_0 = _len_0 + 1
13 end
14 hi = _accum_0
15end
16local items = {
17 1,
18 2,
19 3,
20 4,
21 5,
22 6
23}
24local _
25do
26 local _accum_0 = { }
27 local _len_0 = 1
28 for z in ipairs(items) do
29 if z > 4 then
30 _accum_0[_len_0] = z
31 _len_0 = _len_0 + 1
32 end
33 end
34 _ = _accum_0
35end
36local rad
37do
38 local _accum_0 = { }
39 local _len_0 = 1
40 for a in ipairs({
41 1,
42 2,
43 3,
44 4,
45 5,
46 6
47 }) do
48 if good_number(a) then
49 _accum_0[_len_0] = {
50 a
51 }
52 _len_0 = _len_0 + 1
53 end
54 end
55 rad = _accum_0
56end
57do
58 local _accum_0 = { }
59 local _len_0 = 1
60 for z in items do
61 for j in list do
62 if z > 4 then
63 _accum_0[_len_0] = z
64 _len_0 = _len_0 + 1
65 end
66 end
67 end
68 _ = _accum_0
69end
70require("util")
71local dump
72dump = function(x)
73 return print(util.dump(x))
74end
75local range
76range = function(count)
77 local i = 0
78 return coroutine.wrap(function()
79 while i < count do
80 coroutine.yield(i)
81 i = i + 1
82 end
83 end)
84end
85dump((function()
86 local _accum_0 = { }
87 local _len_0 = 1
88 for x in range(10) do
89 _accum_0[_len_0] = x
90 _len_0 = _len_0 + 1
91 end
92 return _accum_0
93end)())
94dump((function()
95 local _accum_0 = { }
96 local _len_0 = 1
97 for x in range(5) do
98 if x > 2 then
99 for y in range(5) do
100 _accum_0[_len_0] = {
101 x,
102 y
103 }
104 _len_0 = _len_0 + 1
105 end
106 end
107 end
108 return _accum_0
109end)())
110local things
111do
112 local _accum_0 = { }
113 local _len_0 = 1
114 for x in range(10) do
115 if x > 5 then
116 for y in range(10) do
117 if y > 7 then
118 _accum_0[_len_0] = x + y
119 _len_0 = _len_0 + 1
120 end
121 end
122 end
123 end
124 things = _accum_0
125end
126for x in ipairs({
127 1,
128 2,
129 4
130}) do
131 for y in ipairs({
132 1,
133 2,
134 3
135 }) do
136 if x ~= 2 then
137 print(x, y)
138 end
139 end
140end
141for x in items do
142 print("hello", x)
143end
144do
145 local _accum_0 = { }
146 local _len_0 = 1
147 for x in x do
148 _accum_0[_len_0] = x
149 _len_0 = _len_0 + 1
150 end
151 _ = _accum_0
152end
153local x
154do
155 local _accum_0 = { }
156 local _len_0 = 1
157 for x in x do
158 _accum_0[_len_0] = x
159 _len_0 = _len_0 + 1
160 end
161 x = _accum_0
162end
163for x in ipairs({
164 1,
165 2,
166 4
167}) do
168 for y in ipairs({
169 1,
170 2,
171 3
172 }) do
173 if x ~= 2 then
174 print(x, y)
175 end
176 end
177end
178local double
179do
180 local _accum_0 = { }
181 local _len_0 = 1
182 for _index_0 = 1, #items do
183 local x = items[_index_0]
184 _accum_0[_len_0] = x * 2
185 _len_0 = _len_0 + 1
186 end
187 double = _accum_0
188end
189for _index_0 = 1, #double do
190 local x = double[_index_0]
191 print(x)
192end
193local cut
194do
195 local _accum_0 = { }
196 local _len_0 = 1
197 for _index_0 = 1, #items do
198 local x = items[_index_0]
199 if x > 3 then
200 _accum_0[_len_0] = x
201 _len_0 = _len_0 + 1
202 end
203 end
204 cut = _accum_0
205end
206local hello
207do
208 local _accum_0 = { }
209 local _len_0 = 1
210 for _index_0 = 1, #items do
211 local x = items[_index_0]
212 for _index_1 = 1, #items do
213 local y = items[_index_1]
214 _accum_0[_len_0] = x + y
215 _len_0 = _len_0 + 1
216 end
217 end
218 hello = _accum_0
219end
220for _index_0 = 1, #hello do
221 local z = hello[_index_0]
222 print(z)
223end
224x = {
225 1,
226 2,
227 3,
228 4,
229 5,
230 6,
231 7
232}
233local _max_0 = -5
234for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do
235 local y = x[_index_0]
236 print(y)
237end
238local _max_1 = 3
239for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do
240 local y = x[_index_0]
241 print(y)
242end
243for _index_0 = 2, #x do
244 local y = x[_index_0]
245 print(y)
246end
247for _index_0 = 1, #x, 2 do
248 local y = x[_index_0]
249 print(y)
250end
251for _index_0 = 2, #x, 2 do
252 local y = x[_index_0]
253 print(y)
254end
255local a, b, c = 1, 5, 2
256local _max_2 = b
257for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do
258 local y = x[_index_0]
259 print(y)
260end
261local normal
262normal = function(hello)
263 local _accum_0 = { }
264 local _len_0 = 1
265 for x in yeah do
266 _accum_0[_len_0] = x
267 _len_0 = _len_0 + 1
268 end
269 return _accum_0
270end
271local test = x(1, 2, 3, 4, 5)
272for _index_0 = 1, #test do
273 local thing = test[_index_0]
274 print(thing)
275end
276return function()
277 local _list_0 = rows
278 for _index_0 = 1, #_list_0 do
279 local row = _list_0[_index_0]
280 a = b
281 end
282end
diff --git a/spec/outputs/literals.lua b/spec/outputs/literals.lua
new file mode 100644
index 0000000..1ffadc8
--- /dev/null
+++ b/spec/outputs/literals.lua
@@ -0,0 +1,28 @@
1local _ = {
2 121,
3 121.2323,
4 121.2323e-1,
5 121.2323e13434,
6 2323E34,
7 0x12323,
8 0xfF2323,
9 0xabcdef,
10 0xABCDEF,
11 .2323,
12 .2323e-1,
13 .2323e13434,
14 1LL,
15 1ULL,
16 9332LL,
17 9332,
18 0x2aLL,
19 0x2aULL,
20 [[ hello world ]],
21 [=[ hello world ]=],
22 [====[ hello world ]====],
23 "another world",
24 'what world',
25 "\n hello world\n ",
26 'yeah\n what is going on\n here is something cool'
27}
28return nil
diff --git a/spec/outputs/local.lua b/spec/outputs/local.lua
new file mode 100644
index 0000000..288764a
--- /dev/null
+++ b/spec/outputs/local.lua
@@ -0,0 +1,151 @@
1do
2 local a
3 local a, b, c
4 local g
5 b, g = 23232
6end
7do
8 local x = 1212
9 local something
10 something = function()
11 local x
12 x = 1212
13 end
14end
15do
16 local y, z
17 y = 2323
18 z = 2323
19end
20do
21 print("Nothing Here!")
22end
23do
24 local X, Y
25 local x = 3434
26 local y = 3434
27 X = 3434
28 Y = "yeah"
29end
30do
31 local x, y = "a", "b"
32end
33do
34 local x, y
35 x, y = "a", "b"
36end
37do
38 if something then
39 local x = 2323
40 end
41end
42do
43 local x
44 do
45 x = "one"
46 end
47 x = 100
48 do
49 x = "two"
50 end
51end
52do
53 local k, x, a, b, c
54 if what then
55 k = 10
56 end
57 x = 100
58 do
59 local _obj_0 = y
60 a, b, c = _obj_0.a, _obj_0.b, _obj_0.c
61 end
62end
63do
64 local a, b, c, d
65 a = 100
66 print("hi")
67 b = 200
68 c = 100
69 print("hi")
70 d = 200
71 d = 2323
72end
73do
74 local Uppercase, One, Two
75 local lowercase = 5
76 Uppercase = 3
77 do
78 local _class_0
79 local Five
80 local _base_0 = { }
81 _base_0.__index = _base_0
82 _class_0 = setmetatable({
83 __init = function() end,
84 __base = _base_0,
85 __name = "One"
86 }, {
87 __index = _base_0,
88 __call = function(cls, ...)
89 local _self_0 = setmetatable({ }, _base_0)
90 cls.__init(_self_0, ...)
91 return _self_0
92 end
93 })
94 _base_0.__class = _class_0
95 local self = _class_0;
96 Five = 6
97 One = _class_0
98 end
99 do
100 local _class_0
101 local No
102 local _base_0 = { }
103 _base_0.__index = _base_0
104 _class_0 = setmetatable({
105 __init = function() end,
106 __base = _base_0,
107 __name = "Two"
108 }, {
109 __index = _base_0,
110 __call = function(cls, ...)
111 local _self_0 = setmetatable({ }, _base_0)
112 cls.__init(_self_0, ...)
113 return _self_0
114 end
115 })
116 _base_0.__class = _class_0
117 local self = _class_0;
118 do
119 local _class_1
120 local _base_1 = { }
121 _base_1.__index = _base_1
122 _class_1 = setmetatable({
123 __init = function() end,
124 __base = _base_1,
125 __name = "No"
126 }, {
127 __index = _base_1,
128 __call = function(cls, ...)
129 local _self_0 = setmetatable({ }, _base_1)
130 cls.__init(_self_0, ...)
131 return _self_0
132 end
133 })
134 _base_1.__class = _class_1
135 No = _class_1
136 end
137 Two = _class_0
138 end
139end
140do
141 local _list_0 = { }
142 for _index_0 = 1, #_list_0 do
143 local a = _list_0[_index_0]
144 local _ = a
145 end
146end
147do
148 local x
149 x = a or b
150end
151local g = 2323
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua
new file mode 100644
index 0000000..a905e4e
--- /dev/null
+++ b/spec/outputs/loops.lua
@@ -0,0 +1,352 @@
1for x = 1, 10 do
2 print("yeah")
3end
4for x = 1, #something do
5 print("yeah")
6end
7for y = 100, 60, -3 do
8 print("count down", y)
9end
10for a = 1, 10 do
11 print("okay")
12end
13for a = 1, 10 do
14 for b = 2, 43 do
15 print(a, b)
16 end
17end
18for i in iter do
19 for j in yeah do
20 local x = 343 + i + j
21 print(i, j)
22 end
23end
24local _list_0 = something
25for _index_0 = 1, #_list_0 do
26 local x = _list_0[_index_0]
27 print(x)
28end
29for k, v in pairs(hello) do
30 print(k, v)
31end
32for x in y, z do
33 print(x)
34end
35for x in y, z, k do
36 print(x)
37end
38local _list_1 = modules
39for _index_0 = 1, #_list_1 do
40 local name, members = _list_1[_index_0]
41 print(name, member)
42end
43local x
44x = function()
45 for x in y do
46 local _ = y
47 end
48end
49local hello = {
50 1,
51 2,
52 3,
53 4,
54 5
55}
56do
57 local _accum_0 = { }
58 local _len_0 = 1
59 for _index_0 = 1, #hello do
60 local y = hello[_index_0]
61 if y % 2 == 0 then
62 _accum_0[_len_0] = y
63 end
64 _len_0 = _len_0 + 1
65 end
66 x = _accum_0
67end
68x = function()
69 for _index_0 = 1, #hello do
70 local x = hello[_index_0]
71 local _ = y
72 end
73end
74local t
75do
76 local _accum_0 = { }
77 local _len_0 = 1
78 for i = 10, 20 do
79 _accum_0[_len_0] = i * 2
80 _len_0 = _len_0 + 1
81 end
82 t = _accum_0
83end
84local hmm = 0
85local y
86do
87 local _accum_0 = { }
88 local _len_0 = 1
89 for j = 3, 30, 8 do
90 hmm = hmm + 1
91 _accum_0[_len_0] = j * hmm
92 _len_0 = _len_0 + 1
93 end
94 y = _accum_0
95end
96local _
97_ = function()
98 for k = 10, 40 do
99 _ = "okay"
100 end
101end
102_ = function()
103 local _accum_0 = { }
104 local _len_0 = 1
105 for k = 10, 40 do
106 _accum_0[_len_0] = "okay"
107 _len_0 = _len_0 + 1
108 end
109 return _accum_0
110end
111while true do
112 print("name")
113end
114while 5 + 5 do
115 print("okay world")
116 working(man)
117end
118while also do
119 i(work(too))
120 _ = "okay"
121end
122local i = 0
123do
124 local _accum_0 = { }
125 local _len_0 = 1
126 while i < 10 do
127 i = i + 1
128 _len_0 = _len_0 + 1
129 end
130 x = _accum_0
131end
132do
133 local _accum_0 = { }
134 local _len_0 = 1
135 local _list_2 = 3
136 for _index_0 = 1, #_list_2 do
137 local thing = _list_2[_index_0]
138 y = "hello"
139 _len_0 = _len_0 + 1
140 end
141 x = _accum_0
142end
143do
144 local _accum_0 = { }
145 local _len_0 = 1
146 for x = 1, 2 do
147 y = "hello"
148 _len_0 = _len_0 + 1
149 end
150 x = _accum_0
151end
152while true do
153 local _continue_0 = false
154 repeat
155 if false then
156 _continue_0 = true
157 break
158 end
159 print("yes")
160 if true then
161 break
162 end
163 print("no")
164 _continue_0 = true
165 until true
166 if not _continue_0 then
167 break
168 end
169end
170for i = 1, 10 do
171 while true do
172 local _continue_0 = false
173 repeat
174 if not true then
175 _continue_0 = true
176 break
177 end
178 break
179 _continue_0 = true
180 until true
181 if not _continue_0 then
182 break
183 end
184 end
185end
186local a = 1
187repeat
188 local _continue_0 = false
189 repeat
190 a = a + 1
191 if a == 5 then
192 _continue_0 = true
193 break
194 end
195 if a == 6 then
196 break
197 end
198 print(a)
199 _continue_0 = true
200 until true
201 if not _continue_0 then
202 break
203 end
204until a == 10
205a = 3
206while not (a == 0) do
207 a = a - 1
208end
209local done = false
210while not done do
211 done = true
212end
213repeat
214 print("hello")
215until true
216while not done do
217 x = 10
218 repeat
219 x = x - 1
220 until x == 0
221end
222while not cond do
223 print("okay")
224end
225for x = 1, 10 do
226 local _continue_0 = false
227 repeat
228 if x > 3 and x < 7 then
229 _continue_0 = true
230 break
231 end
232 print(x)
233 _continue_0 = true
234 until true
235 if not _continue_0 then
236 break
237 end
238end
239local list
240do
241 local _accum_0 = { }
242 local _len_0 = 1
243 for x = 1, 10 do
244 local _continue_0 = false
245 repeat
246 if x > 3 and x < 7 then
247 _continue_0 = true
248 break
249 end
250 _accum_0[_len_0] = x
251 _len_0 = _len_0 + 1
252 _continue_0 = true
253 until true
254 if not _continue_0 then
255 break
256 end
257 end
258 list = _accum_0
259end
260local _list_2 = {
261 1,
262 2,
263 3,
264 4,
265 5,
266 6
267}
268for _index_0 = 1, #_list_2 do
269 local a = _list_2[_index_0]
270 local _continue_0 = false
271 repeat
272 if a == 1 then
273 _continue_0 = true
274 break
275 end
276 if a == 3 then
277 _continue_0 = true
278 break
279 end
280 print(a)
281 _continue_0 = true
282 until true
283 if not _continue_0 then
284 break
285 end
286end
287for x = 1, 10 do
288 local _continue_0 = false
289 repeat
290 if x % 2 == 0 then
291 _continue_0 = true
292 break
293 end
294 for y = 2, 12 do
295 local _continue_1 = false
296 repeat
297 if y % 3 == 0 then
298 _continue_1 = true
299 break
300 end
301 _continue_1 = true
302 until true
303 if not _continue_1 then
304 break
305 end
306 end
307 _continue_0 = true
308 until true
309 if not _continue_0 then
310 break
311 end
312end
313while true do
314 local _continue_0 = false
315 repeat
316 if false then
317 _continue_0 = true
318 break
319 end
320 break
321 _continue_0 = true
322 until true
323 if not _continue_0 then
324 break
325 end
326end
327while true do
328 local _continue_0 = false
329 repeat
330 if false then
331 _continue_0 = true
332 break
333 end
334 return 22
335 _continue_0 = true
336 until true
337 if not _continue_0 then
338 break
339 end
340end
341do
342 local xxx = {
343 1,
344 2,
345 3,
346 4
347 }
348 for _index_0 = 1, #xxx do
349 local thing = xxx[_index_0]
350 print(thing)
351 end
352end
diff --git a/spec/outputs/macro-export.lua b/spec/outputs/macro-export.lua
new file mode 100644
index 0000000..b5a63f8
--- /dev/null
+++ b/spec/outputs/macro-export.lua
@@ -0,0 +1,2 @@
1local _module_0 = { }
2return _module_0
diff --git a/spec/outputs/macro-teal.tl b/spec/outputs/macro-teal.tl
new file mode 100644
index 0000000..b5a63f8
--- /dev/null
+++ b/spec/outputs/macro-teal.tl
@@ -0,0 +1,2 @@
1local _module_0 = { }
2return _module_0
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua
new file mode 100644
index 0000000..a2430a2
--- /dev/null
+++ b/spec/outputs/macro.lua
@@ -0,0 +1,233 @@
1assert(item == nil);
2local v = (item == nil)
3if f1() then
4 print("OK")
5end
6if (f1() and f2() and f3()) then
7 print("OK")
8end
9if (x == "Apple" or x == "Pig" or x == "Dog") then
10 print("exist")
11end
12local _list_0 = (function()
13 local _accum_0 = { }
14 local _len_0 = 1
15 local _list_0 = (function()
16 local _accum_1 = { }
17 local _len_1 = 1
18 local _list_0 = {
19 1,
20 2,
21 3
22 }
23 for _index_0 = 1, #_list_0 do
24 local _ = _list_0[_index_0]
25 _accum_1[_len_1] = _ * 2
26 _len_1 = _len_1 + 1
27 end
28 return _accum_1
29 end)()
30 for _index_0 = 1, #_list_0 do
31 local _ = _list_0[_index_0]
32 if _ > 4 then
33 _accum_0[_len_0] = _
34 _len_0 = _len_0 + 1
35 end
36 end
37 return _accum_0
38end)()
39for _index_0 = 1, #_list_0 do
40 local _ = _list_0[_index_0]
41 print(_)
42end
43local _list_1 = (function()
44 local _accum_0 = { }
45 local _len_0 = 1
46 local _list_1 = (function()
47 local _accum_1 = { }
48 local _len_1 = 1
49 local _list_1 = {
50 1,
51 2,
52 3
53 }
54 for _index_0 = 1, #_list_1 do
55 local _ = _list_1[_index_0]
56 _accum_1[_len_1] = _ * 2
57 _len_1 = _len_1 + 1
58 end
59 return _accum_1
60 end)()
61 for _index_0 = 1, #_list_1 do
62 local _ = _list_1[_index_0]
63 if _ > 4 then
64 _accum_0[_len_0] = _
65 _len_0 = _len_0 + 1
66 end
67 end
68 return _accum_0
69end)()
70for _index_0 = 1, #_list_1 do
71 local _ = _list_1[_index_0]
72 print(_)
73end
74local val
75do
76 local _2
77 do
78 local _accum_0 = { }
79 local _len_0 = 1
80 local _list_2 = {
81 1,
82 2,
83 3
84 }
85 for _index_0 = 1, #_list_2 do
86 local _ = _list_2[_index_0]
87 _accum_0[_len_0] = _ * 2
88 _len_0 = _len_0 + 1
89 end
90 _2 = _accum_0
91 end
92 local _3
93 do
94 local _accum_0 = { }
95 local _len_0 = 1
96 for _index_0 = 1, #_2 do
97 local _ = _2[_index_0]
98 if _ > 4 then
99 _accum_0[_len_0] = _
100 _len_0 = _len_0 + 1
101 end
102 end
103 _3 = _accum_0
104 end
105 local _4
106 if #_3 == 0 then
107 _4 = 0
108 else
109 local _1 = 0
110 for _index_0 = 1, #_3 do
111 local _2 = _3[_index_0]
112 _1 = _1 + _2
113 end
114 _4 = _1
115 end
116 val = _4
117end
118(1 + 2):call(123)
119local res = (1 + 2)
120local f
121f = function(x)
122 return function(y)
123 return function(z)
124 return print(x, y, z)
125 end
126 end
127end
128do
129 local a = 8
130 do
131 a = 1
132 a = a + 1
133 end
134 a = a + (function()
135 a = 1
136 return a + 1
137 end)()
138 print(a)
139end
140do
141 local a = 8
142 a = (function()
143 local a
144 a = 1
145 return a + 1
146 end)()
147 a = a + (function()
148 local a
149 a = 1
150 return a + 1
151 end)()
152 print(a)
153end
154local x = 0;
155local function f(a)
156 return a + 1
157end
158x = x + f(3);
159function tb:func()
160 print(123)
161end
162print(x)
163local sel
164sel = function(a, b, c)
165 if a then
166 return b
167 else
168 return c
169 end
170end
171local function sel(a, b, c)
172 if a then
173 return b
174 else
175 return c
176 end
177end
178local function dummy()
179
180end
181-- a comment here
182local _ = require('underscore')
183local a = ((((_({
184 1,
185 2,
186 3,
187 4,
188 -2,
189 3
190})):chain()):map(function(self)
191 return self * 2
192end)):filter(function(self)
193 return self > 3
194end)):value();
195((((_({
196 1,
197 2,
198 3,
199 4,
200 -2,
201 3
202})):chain()):map(function(self)
203 return self * 2
204end)):filter(function(self)
205 return self > 3
206end)):each(function(self)
207 return print(self)
208end)
209local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()):SelectEnable()):SelectVisible()):TagEqual("fx")):Where(function(x)
210 return x.name:EndsWith("(Clone)")
211end)):Destroy()
212do
213 local _1
214 _1 = origin.transform.root.gameObject:Parents()
215 local _2
216 _2 = _1:Descendants()
217 local _3
218 _3 = _2:SelectEnable()
219 local _4
220 _4 = _3:SelectVisible()
221 local _5
222 _5 = _4:TagEqual("fx")
223 local _6
224 _6 = _5:Where(function(x)
225 return x.name:EndsWith("(Clone)")
226 end)
227 _6:Destroy()
228end
229origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x)
230 return x.name:EndsWith("(Clone)")
231end):Destroy()
232print('abc')
233return 123
diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua
new file mode 100644
index 0000000..16ae86c
--- /dev/null
+++ b/spec/outputs/metatable.lua
@@ -0,0 +1,113 @@
1local a = setmetatable({
2 close = true,
3}, {
4 __close = function(self)
5 return print("out of scope")
6 end
7})
8local b = setmetatable({ }, {
9 __add = function(left, right)
10 return right - left
11 end
12})
13local c = setmetatable({
14 key1 = true,
15 key2 = true
16}, {
17 __add = add
18})
19local w = setmetatable({ }, {
20 [name] = 123,
21 ["new"] = function(self, val)
22 return {
23 val
24 }
25 end
26})
27getmetatable(w)["new"](getmetatable(w)[name])
28local _ <close> = setmetatable({ }, {
29 __close = function()
30 return print("out of scope")
31 end
32})
33local d, e = a.close, getmetatable(a).__close
34local f = getmetatable(a):__close(1)
35getmetatable(a).__add = function(x, y)
36 return x + y
37end
38do
39 local _obj_0 = a
40 local new = _obj_0.new
41 local close, closeA
42 do
43 local _obj_1 = getmetatable(_obj_0)
44 close, closeA = _obj_1.__close, _obj_1.__close
45 end
46 print(new, close, closeA)
47end
48do
49 local x, new, var, close, closeA, num, add, sub
50 local _obj_0, _obj_1
51 x, _obj_0, _obj_1 = 123, a.b.c, func()
52 new, var = _obj_0.new, _obj_0.var
53 do
54 local _obj_2 = getmetatable(_obj_0)
55 close, closeA = _obj_2.__close, _obj_2.__close
56 end
57 num = _obj_1.num
58 do
59 local _obj_2 = getmetatable(_obj_1)
60 add, sub = _obj_2.__add, _obj_2.__sub
61 end
62end
63setmetatable(a.b, { })
64x.abc = 123
65setmetatable(func(), mt)
66_ = extra
67setmetatable(b.c, mt)
68a, d, e = 1, "abc"
69local is_same = getmetatable(a).__index == getmetatable(a).__index
70setmetatable(a, {
71 __index = tb
72})
73getmetatable(a).__index = tb
74getmetatable(a).__index = tb
75local mt = getmetatable(a)
76tb:func(#list)
77getmetatable(tb):__func(list)
78getmetatable(tb):__func(list)
79local index, setFunc
80do
81 local _obj_0 = getmetatable(require("module"))
82 index, setFunc = _obj_0.__index, _obj_0.__newindex
83end
84do
85 local _with_0 = tb
86 print(getmetatable(_with_0).__add, getmetatable(_with_0.x):__index("key"))
87 a = getmetatable(getmetatable(getmetatable(_with_0).__index).__add):__new(123)
88 b = t(#getmetatable(_with_0).__close.test)
89 c = t(#getmetatable(_with_0).__close(_with_0.test))
90end
91mt = getmetatable(a)
92a = setmetatable({ }, mt)
93a = setmetatable({ }, {
94 __index = mt
95})
96local index
97index = getmetatable(a).__index
98index = getmetatable(a).__index
99do
100 local ctor, update
101 do
102 local _obj_0 = getmetatable(a)
103 ctor, update = _obj_0.new, _obj_0.update
104 end
105end
106do
107 local ctor, update
108 do
109 local _obj_0 = getmetatable(a)
110 ctor, update = _obj_0.new, _obj_0.update
111 end
112end
113return nil
diff --git a/spec/outputs/multiline_chain.lua b/spec/outputs/multiline_chain.lua
new file mode 100644
index 0000000..fea7bc6
--- /dev/null
+++ b/spec/outputs/multiline_chain.lua
@@ -0,0 +1,91 @@
1local x = a.b.c.d
2x.y = a.b:c()
3func(1, arg2.value:get(), arg3.value:get(), {
4 1,
5 ((function()
6 if x ~= nil then
7 local _obj_0 = x.y
8 if _obj_0 ~= nil then
9 return _obj_0.z
10 end
11 return nil
12 end
13 return nil
14 end)() ~= nil),
15 3
16})
17local tbb = {
18 k1 = a:b(123).c(),
19 k2 = {
20 w1 = a().b:c()
21 }
22}
23local tb
24if f2 ~= nil then
25 tb = f2("abc", f1({ }).a)
26end
27local f
28f = function()
29 local _accum_0 = { }
30 local _len_0 = 1
31 local _list_0 = vals
32 for _index_0 = 1, #_list_0 do
33 local _des_0 = _list_0[_index_0]
34 local a = _des_0[1]
35 _accum_0[_len_0] = a.b:c(123)
36 _len_0 = _len_0 + 1
37 end
38 return _accum_0
39end
40local f1
41f1 = function()
42 return x, a:b(123).c("abc")
43end
44local result = origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x)
45 if x:IsTargeted() then
46 return false
47 end
48 return x.name:EndsWith("(Clone)")
49end):Destroy()
50origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x)
51 return x.name:EndsWith("(Clone)")
52end):Destroy()
53do
54 local _with_0 = item
55 _with_0.itemFieldA = 123
56 _with_0:callMethod():chainCall()
57 _with_0:callMethod():chainCall()
58 _with_0:chainCall()
59 local _exp_0 = _with_0.itemFieldB:getValue()
60 if "Valid" == _exp_0 or _with_0:getItemState() == _exp_0 then
61 _with_0:itemMethodA():getValue()
62 else
63 _with_0:itemMethodB():getValue()
64 end
65 local a
66 if _with_0.itemFieldC then
67 a = _with_0.itemFieldD
68 else
69 a = _with_0.itemFieldE
70 end
71 local _list_0 = values
72 for _index_0 = 1, #_list_0 do
73 local v = _list_0[_index_0]
74 _with_0:itemMethodC(v)
75 end
76 for i = 1, counter do
77 _with_0:itemMethodC(i)
78 end
79 if not _with_0.b then
80 do
81 local _accum_0 = { }
82 local _len_0 = 1
83 while _with_0.itemFieldD do
84 _accum_0[_len_0] = _with_0:itemNext():get()
85 _len_0 = _len_0 + 1
86 end
87 _with_0.c = _accum_0
88 end
89 end
90end
91return nil
diff --git a/spec/outputs/operators.lua b/spec/outputs/operators.lua
new file mode 100644
index 0000000..d782f5c
--- /dev/null
+++ b/spec/outputs/operators.lua
@@ -0,0 +1,29 @@
1local x = 1 + 3
2local y = 1 + 3
3local z = 1 + 3 + 4
4local k = b and c and g
5local h = thing and function()
6 return print("hello world")
7end
8local i = thing or function()
9 return print("hello world")
10end
11local p = thing and function() end
12print("hello world")
13local s = thing or function() end and 234
14local u = {
15 color = 1 and 2 and 3,
16 4,
17 4
18}
19local v = {
20 color = 1 and function()
21 return "yeah"
22 end,
23 "great",
24 oksy = 3 ^ 2
25}
26local nno = (yeah + 2)
27local nn = (yeah + 2)
28local n = hello(b)(function() end)
29return hello(a, (yeah + 2) - okay)
diff --git a/spec/outputs/pipe.lua b/spec/outputs/pipe.lua
new file mode 100644
index 0000000..bf517ae
--- /dev/null
+++ b/spec/outputs/pipe.lua
@@ -0,0 +1,116 @@
1foreach({
2 "abc",
3 123,
4 998
5}, print)
6print(reduce(filter(map({
7 1,
8 2,
9 3
10}, function(x)
11 return x * 2
12end), function(x)
13 return x > 4
14end), 0, function(a, b)
15 return a + b
16end))
17print(table.concat((function()
18 local _accum_0 = { }
19 local _len_0 = 1
20 for i = 0, 10 do
21 _accum_0[_len_0] = tostring(i)
22 _len_0 = _len_0 + 1
23 end
24 return _accum_0
25end)(), ","))
26local b = 1 + 2 + (print(tostring(4), 1) or 123)
27do
28 local x = math.max(233, 998)
29 if x then
30 print(x)
31 end
32end
33do
34 local _with_0
35 if create ~= nil then
36 _with_0 = create(b, "new")
37 end
38 _with_0.value = 123
39 print(_with_0:work())
40end
41if f ~= nil then
42 f(123)
43end
44if f2 ~= nil then
45 f2((function()
46 if f1 ~= nil then
47 return f1("abc")
48 end
49 return nil
50 end)())
51end
52local c
53if f2 ~= nil then
54 c = f2((function()
55 if f1 ~= nil then
56 return f1("abc")
57 end
58 return nil
59 end)())
60end
61local f
62f = function()
63 local _obj_0 = x.y
64 if _obj_0 ~= nil then
65 return _obj_0["if"](_obj_0, arg)
66 end
67 return nil
68end
69func2(998, "abc", func1(func0(233)))
70func2(func1(func0(998, "abc", 233)))
71f(1, 2, 3, 4, 5)
72f(1, val(2), 3, 4, 5)
73f(1, 2, arr[3], 4, 5)
74local a = f2(1, f1(1, 2, 3, tonumber(table.concat({
75 "1",
76 "2",
77 "3"
78}, ""))), 3)
79print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
80print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
81print(render(emit(parse(extract(readFile("example.txt"), language, { }), language))))
82f(not func(123))
83do
84 local _1 = abc(123, -func(list({
85 "abc",
86 "xyz",
87 "123"
88 }):map("#"):value()), "x")
89 _2, _3, _4 = 1, 2, f(3)
90 local _5
91 _5 = f4(f3(f2(f1(v, 1), 2), 3), 4)
92end
93local x = b(a(123)) or d(c(456)) or (function()
94 local _call_0 = a["if"]
95 return _call_0["then"](_call_0, "abc")
96end)() or (function()
97 if a ~= nil then
98 local _obj_0 = a.b
99 local _obj_1 = _obj_0.c
100 if _obj_1 ~= nil then
101 return _obj_1(_obj_0, 123)
102 end
103 return nil
104 end
105 return nil
106end)() or (function()
107 local _base_0 = x
108 local _fn_0 = _base_0.y
109 return _fn_0 and function(...)
110 return _fn_0(_base_0, ...)
111 end
112end)()
113local x1 = 3 * f(-4)
114local x2 = 3 * f(-2 ^ 2)
115local y = 1 + b(3, (a ^ c)(not #2)) * f1(f(4 ^ -123)) or 123
116return nil
diff --git a/spec/outputs/plus.lua b/spec/outputs/plus.lua
new file mode 100644
index 0000000..749e830
--- /dev/null
+++ b/spec/outputs/plus.lua
@@ -0,0 +1,69 @@
1x["do"](x, "work")
2func((function()
3 local _call_0 = a["do"](a)
4 local _call_1 = _call_0["end"](_call_0, "OK")
5 return _call_1["if"](_call_1, "abc", 123)
6end)())
7local _call_0 = b["function"]
8local _call_1 = _call_0["do"](_call_0)
9local _call_2 = _call_1["while"](_call_1, "OK")
10local res = _call_2["if"](_call_2, "def", 998)
11local _call_3 = c["repeat"]["if"]
12local _call_4 = _call_3["then"](_call_3, "xyz")
13_call_4["else"](_call_4, res)
14print(self["for"], self.__class["function"](self.__class, 123))
15do
16 local fcolor = message:match("<%w*>")
17 if fcolor then
18 local message = message:gsub("<%->", fcolor)
19 end
20end
21local message
22do
23 local fcolor = message:match("<%w*>")
24 if fcolor then
25 message = message:gsub("<%->", fcolor)
26 end
27end
28local valA
29do
30 local func = getfunc()
31 if func then
32 valA = func()
33 end
34end
35local valA
36do
37 local func = getfunc()
38 if func then
39 valA = func()
40 end
41end
42local valB
43do
44 local func = getfunc()
45 if func ~= nil then
46 valB = func()
47 end
48end
49backpack = {
50 something = {
51 yeah = 200,
52 they = function()
53 print("hello")
54 return yor_feet("small")
55 end,
56 pretty = hair,
57 gold = hmm
58 },
59 yow = 1000,
60 eat = goo,
61 yeah = dudd
62}
63local start = {
64 something = "cold"
65}
66local bathe
67bathe = {
68 on = "fire"
69}
diff --git a/spec/outputs/return.lua b/spec/outputs/return.lua
new file mode 100644
index 0000000..0735b23
--- /dev/null
+++ b/spec/outputs/return.lua
@@ -0,0 +1,102 @@
1local _
2_ = function()
3 local _list_0 = things
4 for _index_0 = 1, #_list_0 do
5 local x = _list_0[_index_0]
6 _ = x
7 end
8end
9_ = function()
10 local _accum_0 = { }
11 local _len_0 = 1
12 local _list_0 = things
13 for _index_0 = 1, #_list_0 do
14 local x = _list_0[_index_0]
15 _accum_0[_len_0] = x
16 _len_0 = _len_0 + 1
17 end
18 return _accum_0
19end
20do
21 local _list_0 = things
22 for _index_0 = 1, #_list_0 do
23 local x = _list_0[_index_0]
24 return x
25 end
26end
27do
28 local _accum_0 = { }
29 local _len_0 = 1
30 local _list_0 = things
31 for _index_0 = 1, #_list_0 do
32 local x = _list_0[_index_0]
33 _accum_0[_len_0] = x
34 _len_0 = _len_0 + 1
35 end
36 return _accum_0
37end
38do
39 local _tbl_0 = { }
40 local _list_0 = things
41 for _index_0 = 1, #_list_0 do
42 local x, y = _list_0[_index_0]
43 _tbl_0[x] = y
44 end
45 return _tbl_0
46end
47_ = function()
48 if a then
49 if a then
50 return a
51 else
52 return b
53 end
54 elseif b then
55 if a then
56 return a
57 else
58 return b
59 end
60 else
61 if a then
62 return a
63 else
64 return b
65 end
66 end
67end
68do
69 if a then
70 if a then
71 return a
72 else
73 return b
74 end
75 elseif b then
76 if a then
77 return a
78 else
79 return b
80 end
81 else
82 if a then
83 return a
84 else
85 return b
86 end
87 end
88end
89_ = function()
90 local _base_0 = a
91 local _fn_0 = _base_0.b
92 return _fn_0 and function(...)
93 return _fn_0(_base_0, ...)
94 end
95end
96do
97 local _base_0 = a
98 local _fn_0 = _base_0.b
99 return _fn_0 and function(...)
100 return _fn_0(_base_0, ...)
101 end
102end
diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua
new file mode 100644
index 0000000..84b6700
--- /dev/null
+++ b/spec/outputs/string.lua
@@ -0,0 +1,42 @@
1local hi = "hello"
2local hello = "what the heckyes"
3print(hi)
4local umm = 'umm'
5local here, another = "yeah", 'world'
6local aye = "YU'M"
7you('"hmmm" I said')
8print(aye, you)
9another = [[ hello world ]]
10local hi_there = [[ hi there
11]]
12local well = [==[ "helo" ]==]
13local hola = [===[ eat noots]===]
14local mm = [[well trhere]]
15local txt = [[
16
17nil
18Fail to compile
19]]
20local oo = ""
21local x = "\\"
22x = "a\\b"
23x = "\\\n"
24x = "\""
25local a = "hello " .. tostring(hello) .. " hello"
26local b = tostring(hello) .. " hello"
27local c = "hello " .. tostring(5 + 1)
28local d = tostring(hello(world))
29local e = tostring(1) .. " " .. tostring(2) .. " " .. tostring(3)
30local f = [[hello #{world} world]]
31a = 'hello #{hello} hello'
32b = '#{hello} hello'
33c = 'hello #{hello}'
34local _ = "hello";
35("hello"):format(1);
36("hello"):format(1, 2, 3);
37("hello"):format(1, 2, 3)(1, 2, 3);
38("hello"):world();
39("hello"):format().hello(1, 2, 3);
40("hello"):format(1, 2, 3)
41something("hello"):world()
42return something(("hello"):world())
diff --git a/spec/outputs/stub.lua b/spec/outputs/stub.lua
new file mode 100644
index 0000000..ff867ba
--- /dev/null
+++ b/spec/outputs/stub.lua
@@ -0,0 +1,26 @@
1local x = {
2 val = 100,
3 hello = function(self)
4 return print(self.val)
5 end
6}
7local fn
8do
9 local _base_0 = x
10 local _fn_0 = _base_0.val
11 fn = _fn_0 and function(...)
12 return _fn_0(_base_0, ...)
13 end
14end
15print(fn())
16print(x:val());
17(function(...)
18 do
19 local _base_0 = hello(...)
20 local _fn_0 = _base_0.world
21 x = _fn_0 and function(...)
22 return _fn_0(_base_0, ...)
23 end
24 end
25end)()
26return nil
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua
new file mode 100644
index 0000000..1c8839f
--- /dev/null
+++ b/spec/outputs/switch.lua
@@ -0,0 +1,71 @@
1local _exp_0 = value
2if "cool" == _exp_0 then
3 print("hello world")
4end
5local _exp_1 = value
6if "cool" == _exp_1 then
7 print("hello world")
8else
9 print("okay rad")
10end
11local _exp_2 = value
12if "cool" == _exp_2 then
13 print("hello world")
14elseif "yeah" == _exp_2 then
15 local _ = [[FFFF]] + [[MMMM]]
16elseif (2323 + 32434) == _exp_2 then
17 print("okay")
18else
19 print("okay rad")
20end
21local out
22local _exp_3 = value
23if "cool" == _exp_3 then
24 out = print("hello world")
25else
26 out = print("okay rad")
27end
28local _exp_4 = value
29if "cool" == _exp_4 then
30 out = xxxx
31elseif "umm" == _exp_4 then
32 out = 34340
33else
34 out = error("this failed big time")
35end
36do
37 local _with_0 = something
38 local _exp_5 = _with_0:value()
39 if _with_0.okay == _exp_5 then
40 local _ = "world"
41 else
42 local _ = "yesh"
43 end
44end
45fix(this)
46call_func((function()
47 local _exp_5 = something
48 if 1 == _exp_5 then
49 return "yes"
50 else
51 return "no"
52 end
53end)())
54local _exp_5 = hi
55if (hello or world) == _exp_5 then
56 local _ = greene
57end
58local _exp_6 = hi
59if "one" == _exp_6 or "two" == _exp_6 then
60 print("cool")
61elseif "dad" == _exp_6 then
62 local _ = no
63end
64local _exp_7 = hi
65if (3 + 1) == _exp_7 or hello() == _exp_7 or (function()
66 return 4
67end)() == _exp_7 then
68 return yello
69else
70 return print("cool")
71end
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua
new file mode 100644
index 0000000..3187898
--- /dev/null
+++ b/spec/outputs/syntax.lua
@@ -0,0 +1,360 @@
1local a = 1 + 2 * 3 / 6
2local bunch, go, here
3a, bunch, go, here = another, world
4func(arg1, arg2, another, arg3)
5local we
6here, we = function() end, yeah
7local the, different
8the, different = function()
9 return approach
10end, yeah
11dad()
12dad(lord)
13hello(one, two)();
14(5 + 5)(world)
15fun(a)(b)
16fun(a)(b)
17fun(a)(b, bad(hello))
18hello(world(what(are(you(doing(here))))))
19what(the)[3243](world, yeck(heck))
20hairy[hands][are](gross)(okay(okay[world]))
21local _ = (get[something] + 5)[years]
22local i, x = 200, 300
23local yeah = (1 + 5) * 3
24yeah = ((1 + 5) * 3) / 2
25yeah = ((1 + 5) * 3) / 2 + i % 100
26local whoa = (1 + 2) * (3 + 4) * (4 + 5)
27_ = function()
28 if something then
29 return 1, 2, 4
30 end
31 return print("hello")
32end
33_ = function()
34 if hello then
35 return "heloo", "world"
36 else
37 return no, way
38 end
39end
40_ = function()
41 return 1, 2, 34
42end
43return 5 + function()
44 return 4 + 2
45end
46return 5 + (function()
47 return 4
48end) + 2
49print(5 + function()
50 _ = 34
51 return good(nads)
52end)
53something('else', "ya")
54something('else')
55something("else")
56_ = something([[hey]]) * 2
57_ = something([======[hey]======]) * 2
58_ = something[ [======[hey]======]] * 2
59_ = something('else'), 2
60_ = something("else"), 2
61_ = something([[else]]), 2
62_ = something[ [[else]]], 2
63something('else', 2)
64something("else", 2)
65something([[else]], 2)
66_ = here(we)("go")[12123]
67split("abc xyz 123"):map("#"):printAll()
68_ = f("")[a]
69_ = f(""):b()
70_ = f("").c()
71f(("")[a])
72f((""):b())
73f(("").c())
74list({
75 "abc",
76 "xyz",
77 "123"
78}):map("#"):printAll()
79_ = f({ })[a]
80_ = f({ }):b()
81_ = f({ }).c()
82local something = {
83 test = 12323,
84 what = function()
85 return print("hello world")
86 end
87}
88print(something.test)
89local frick = {
90 hello = "world"
91}
92local argon = {
93 num = 100,
94 world = function(self)
95 print(self.num)
96 return {
97 something = function()
98 return print("hi from something")
99 end
100 }
101 end,
102 somethin = function(self, str)
103 print("string is", str)
104 return {
105 world = function(a, b)
106 return print("sum", a + b)
107 end
108 }
109 end
110}
111something.what()
112argon:world().something()
113argon:somethin("200").world(1, 2)
114x = -434
115x = -hello(world(one(two)))
116local hi = -"herfef"
117x = -(function()
118 local _accum_0 = { }
119 local _len_0 = 1
120 for x in x do
121 _accum_0[_len_0] = x
122 _len_0 = _len_0 + 1
123 end
124 return _accum_0
125end)()
126if cool then
127 print("hello")
128end
129if not cool then
130 print("hello")
131end
132if not (1212 and 3434) then
133 print("hello")
134end
135for i = 1, 10 do
136 print("hello")
137end
138print("nutjob")
139if hello then
140 _ = 343
141end
142if cool then
143 print("what")
144end
145(function(...)
146 local arg = {
147 ...
148 }
149end)()
150x = function(...)
151 return dump({
152 ...
153 })
154end
155x = not true
156local y = not (5 + 5)
157y = #"hello"
158x = #{
159 #{ },
160 #{
161 1
162 },
163 #{
164 1,
165 2
166 }
167}
168_ = hello, world
169something:hello(what)(a, b)
170something:hello(what)
171something.hello:world(a, b)
172something.hello:world(1, 2, 3)(a, b)
173something.hello:world(1, 2, 3)(a, b)
174x = 1232
175x = x + (10 + 3)
176local j = j - "hello"
177y = y * 2
178y = y / 100
179local m = m % 2
180local hello = hello .. "world"
181self.__class.something = self.__class.something + 10
182self.something = self.something + 10
183local _update_0 = "hello"
184a[_update_0] = a[_update_0] + 10
185local _update_1 = "hello" .. tostring(tostring(ff))
186a[_update_1] = a[_update_1] + 10
187a[four].x = a[four].x + 10
188x = 0
189local _list_0 = values
190for _index_0 = 1, #_list_0 do
191 local v = _list_0[_index_0]
192 _ = ((function()
193 if ntype(v) == "fndef" then
194 x = x + 1
195 end
196 end)())
197end
198hello = {
199 something = world,
200 ["if"] = "hello",
201 ["else"] = 3434,
202 ["function"] = "okay",
203 good = 230203
204}
205local tb = {
206 ["do"] = b,
207 (function()
208 return {
209 b = b
210 }
211 end)()
212}
213div({
214 class = "cool"
215})
216_ = 5 + what(wack)
217what(whack + 5)
218_ = 5 - what(wack)
219what(whack - 5)
220x = hello - world - something;
221(function(something)
222 if something == nil then
223 do
224 local _with_0 = what
225 _with_0:cool(100)
226 something = _with_0
227 end
228 end
229 return print(something)
230end)()
231if something then
232 _ = 03589
233else
234 _ = 3434
235end
236if something then
237 _ = yeah
238elseif "ymmm" then
239 print("cool")
240else
241 _ = okay
242end
243x = notsomething
244y = ifsomething
245local z = x and b
246z = x(andb)
247while 10 > something({
248 something = "world"
249 }) do
250 print("yeah")
251end
252x = {
253 okay = sure
254}
255yeah({
256 okay = man,
257 sure = sir
258})
259hello("no comma", {
260 yeah = dada,
261 another = world
262})
263hello("comma", {
264 something = hello_world,
265 frick = you
266})
267another(hello, one, two, three, four, {
268 yeah = man,
269 okay = yeah,
270 fine = alright
271})
272another(hello, one, two, three, four, {
273 yeah = man,
274 okay = yeah,
275 {
276 fine = alright,
277 okay = 1
278 },
279 {
280 fine = alright,
281 okay = 2
282 }
283})
284another(hello, one, two, three, four, {
285 yeah = man,
286 okay = yeah
287})
288another(hello, one, two, three, four, {
289 yeah = man({
290 okay = yeah
291 })
292})
293ajax(url, function(data)
294 return process(data)
295end, function(error)
296 return print(error)
297end)
298a = a + (3 - 5)
299a = a * (3 + 5)
300a = a * 3
301a = a >> 3
302a = a << 3
303a = a / func("cool")
304x["then"] = "hello"
305x["while"]["true"] = "hello"
306x["while"]["true"] = "hello"
307x = x or "hello"
308x = x and "hello"
309z = a - b
310z = a(-b)
311z = a - b
312z = a - b
313local str = strA .. strB .. strC
314func(3000, "192.168.1.1")
315local f
316f = function()
317 return a, b, c, d, e, f
318end
319f = function()
320 return a, b, c, d, e, f
321end
322do
323 local _with_0 = obj
324 invoke(_with_0:func(), 123, "abc")
325end
326invokeA(invokeB(invokeC(123)))
327invokeA(invokeB(invokeC(123)))
328local v = {
329 a(-1),
330 a(-1),
331 a - 1,
332 a - 1,
333 a - 1,
334 a - 1,
335 a - 1,
336 a - 1,
337 a(~1),
338 a(~1),
339 a ~ 1,
340 a ~ 1,
341 a ~ 1,
342 a ~ 1,
343 a ~ 1,
344 a ~ 1
345}
346do
347 a = 1 + 2 * 3 / 4
348 local _1 = f1(-1 + 2 + 3)
349 local _2 = f1 - 1 + 2 + 3
350 local f2
351 f2 = function(x)
352 return print(x + 1)
353 end
354 a = f2()
355 f2(-1)
356 a = f2() - f2(1)
357 local _3, _4
358 _1, _2, _3, _4 = 1, f(2, 3, f(4, 4))
359end
360return nil
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua
new file mode 100644
index 0000000..086e8b3
--- /dev/null
+++ b/spec/outputs/tables.lua
@@ -0,0 +1,351 @@
1local backpack = {
2 something = {
3 yeah = 200,
4 they = function()
5 print("hello")
6 return yor_feet("small")
7 end,
8 pretty = hair,
9 gold = hmm
10 },
11 yow = 1000,
12 eat = goo,
13 yeah = dudd
14}
15local start = {
16 something = "cold"
17}
18local bathe = {
19 on = "fire"
20}
21local another = {
22 [4] = 232,
23 ["good food"] = "is the best"
24}
25local fwip = {
26 something = hello("what"),
27 number = 2323,
28 what = yo("momma", "yeah"),
29 fruit = basket,
30 nuts = day
31}
32local frick = {
33 hello = "world"
34}
35local frack, best = {
36 hello = "world",
37 rice = 3434
38}, "what"
39local ya = {
40 1,
41 2,
42 3,
43 key = 100,
44 343,
45 "hello",
46 umm = 232
47}
48local x = {
49 1,
50 2,
51 4343,
52 343,
53 343
54}
55local g, p = {
56 1,
57 2,
58 nowy = "yes",
59 3,
60 4,
61 hey = 232,
62 another = "day"
63}, 234
64local annother = {
65 1,
66 2,
67 3,
68 3,
69 4,
70 5,
71 6,
72 7,
73 8
74}
75local yeah = {
76 [232] = 3434,
77 "helo",
78 ice = "cake"
79}
80local whatabout = {
81 hello(world, another),
82 what,
83 about,
84 now,
85 hello("world"),
86 yeah,
87 hello("world", yeah)
88}
89x = {
90 something = function(self)
91 return "hello"
92 end,
93 cool = {
94 bed = {
95 2323,
96 2323
97 },
98 red = 2343
99 },
100 name = function(self, node)
101 return self:value(node)
102 end
103}
104x = {
105 something = something,
106 something = something
107}
108local y = {
109 hi = hi,
110 there = there,
111 how = how,
112 you = you,
113 thing = thing
114}
115call_me("hello", {
116 x = x,
117 y = y,
118 z = z
119})
120local t = {
121 a = 'a',
122 [b] = 'b'
123}
124local xam = {
125 hello = 1234,
126 ["hello"] = 12354,
127 [ [[hello]]] = 12354,
128 ["hello"] = 12354,
129 [ [[hello]]] = 12354
130}
131local kam = {
132 hello = 12,
133 goodcheese = "mmm",
134 yeah = 12 + 232,
135 lets = keepit({
136 going = true,
137 okay = "yeah"
138 }),
139 more = {
140 1,
141 (function()
142 local _accum_0 = { }
143 local _len_0 = 1
144 for x = 1, 10 do
145 _accum_0[_len_0] = x
146 _len_0 = _len_0 + 1
147 end
148 return _accum_0
149 end)()
150 },
151 [{
152 "one",
153 "two"
154 }] = one_thing(function(self) end)
155}
156keepit({
157 going = true,
158 okay = "yeah",
159 workd = "okay"
160})
161thing({
162 what = "great",
163 no = "more",
164 okay = 123
165})
166thing({
167 what = "great",
168 no = "more"
169})
170local _ = {
171 okay = 123
172}
173local k = {
174 ["hello"] = "world"
175}
176k = {
177 ['hello'] = 'world'
178}
179k = {
180 ["hello"] = 'world',
181 ["hat"] = "zat"
182}
183please({
184 ["hello"] = "world"
185})
186k = {
187 ["hello"] = "world",
188 ["one"] = "zone"
189}
190local f = "one", {
191 ["two"] = three
192}, "four"
193f = {
194 ["two"] = three
195}, "four"
196f = {
197 "one",
198 ["two"] = three,
199 "four"
200}
201local j = "one", {
202 ["two"] = three,
203 ["four"] = five
204}, 6, 7
205local heroine = {
206 name = "Christina",
207 age = 18,
208 job = "Princess",
209 likes = {
210 {
211 name = "kittens",
212 img = "/image/kittens.png"
213 },
214 {
215 name = "flower",
216 img = "/image/flower.png"
217 }
218 },
219 items = {
220 {
221 name = "ring",
222 amount = 2
223 },
224 {
225 name = "necklace",
226 amount = 1
227 }
228 },
229 status = {
230 desc = "weak",
231 {
232 attribute = "health",
233 value = 50
234 },
235 {
236 attribute = "mana",
237 value = 100
238 }
239 }
240}
241local inventory = {
242 equipment = {
243 "sword",
244 "shield"
245 },
246 items = {
247 {
248 name = "potion",
249 count = 10
250 },
251 {
252 name = "bread",
253 count = 3
254 }
255 }
256}
257local items = {
258 func(),
259 (function()
260 local _with_0 = tb
261 _with_0.abc = 123
262 return _with_0
263 end)(),
264 {
265 1,
266 2,
267 3
268 },
269 f({
270 1,
271 2,
272 3
273 }),
274 f({
275 1,
276 2,
277 3
278 }),
279 (function()
280 local _accum_0 = { }
281 local _len_0 = 1
282 for i = 1, 3 do
283 _accum_0[_len_0] = i
284 _len_0 = _len_0 + 1
285 end
286 return _accum_0
287 end)(),
288 tostring((function()
289 if a then
290 return b
291 end
292 end)())
293}
294local pairs = {
295 {
296 "king",
297 "queen"
298 },
299 {
300 "hero",
301 "princess"
302 }
303}
304items = {
305 {
306 name = "ring",
307 amount = 2
308 },
309 {
310 name = "necklace",
311 amount = 1
312 }
313}
314local menus = {
315 {
316 text = "Save",
317 sub = {
318 {
319 text = "Slot 1: " .. (slots[1].name or "None"),
320 click = function() end
321 },
322 {
323 text = {
324 "Slot 2"
325 },
326 click = function() end
327 },
328 {
329 text = [[Slot 3]],
330 click = function() end
331 },
332 {
333 text = ("Slot 4"):name(),
334 click = function() end
335 },
336 {
337 text = ({
338 {
339 "slot5"
340 }
341 })[1]:name(),
342 click = function() end
343 },
344 [6] = {
345 text = ("Slot 6"),
346 click = function() end
347 }
348 }
349 }
350}
351return nil
diff --git a/spec/outputs/teal-lang.lua b/spec/outputs/teal-lang.lua
new file mode 100644
index 0000000..0e627f4
--- /dev/null
+++ b/spec/outputs/teal-lang.lua
@@ -0,0 +1,49 @@
1local a = {
2 value = 123
3};
4local b = a.value;
5local add = function(a, b)
6 return a + b
7end
8local s = add(a.value, b)
9print(s);
10local Point = {};
11Point.new = function(x, y)
12local point = setmetatable({ }, {
13 __index = Point
14})
15 point.x = x or 0
16 point.y = y or 0
17 return point
18end
19Point.move = function(self, dx, dy)
20 self.x = self.x + dx
21 self.y = self.y + dy
22end
23local p = Point.new(100, 100)
24p:move(50, 50);
25local filter = function(tab, handler)
26 local _accum_0 = { }
27 local _len_0 = 1
28 for _index_0 = 1, #tab do
29 local item = tab[_index_0]
30 if handler(item) then
31 _accum_0[_len_0] = item
32 _len_0 = _len_0 + 1
33 end
34 end
35 return _accum_0
36end
37local cond = function(item)
38 return item ~= "a"
39end
40local res = filter({
41 "a",
42 "b",
43 "c",
44 "a"
45}, cond)
46for _index_0 = 1, #res do
47 local s = res[_index_0]
48 print(s)
49end
diff --git a/spec/outputs/teal-lang.tl b/spec/outputs/teal-lang.tl
new file mode 100644
index 0000000..8f0bf36
--- /dev/null
+++ b/spec/outputs/teal-lang.tl
@@ -0,0 +1,60 @@
1local a:{string:number} = {
2 value = 123
3};
4local b:number = a.value;
5local function add(a:number, b:number):number
6
7 return a + b
8
9end
10local s = add(a.value, b)
11print(s);
12local record Point
13 x: number
14 y: number
15end
16function Point.new(x:number, y:number):Point
17local point:Point = setmetatable({ }, {
18 __index = Point
19})
20 point.x = x or 0
21 point.y = y or 0
22 return point
23
24end
25function Point:move(dx:number, dy:number)
26 self.x = self.x + dx
27 self.y = self.y + dy
28
29end
30local p:Point = Point.new(100, 100)
31p:move(50, 50);
32local function filter(tab:{string}, handler:function(item:string):boolean):{string}
33
34 local _accum_0 = { }
35 local _len_0 = 1
36 for _index_0 = 1, #tab do
37 local item = tab[_index_0]
38 if handler(item) then
39 _accum_0[_len_0] = item
40 _len_0 = _len_0 + 1
41 end
42 end
43 return _accum_0
44
45end
46local function cond(item:string):boolean
47
48 return item ~= "a"
49
50end
51local res = filter({
52 "a",
53 "b",
54 "c",
55 "a"
56}, cond)
57for _index_0 = 1, #res do
58 local s = res[_index_0]
59 print(s)
60end
diff --git a/spec/outputs/unless_else.lua b/spec/outputs/unless_else.lua
new file mode 100644
index 0000000..c85d4bf
--- /dev/null
+++ b/spec/outputs/unless_else.lua
@@ -0,0 +1,7 @@
1if a then
2 if not b then
3 return print("hi")
4 elseif c then
5 return print("not hi")
6 end
7end
diff --git a/spec/outputs/using.lua b/spec/outputs/using.lua
new file mode 100644
index 0000000..6d0d888
--- /dev/null
+++ b/spec/outputs/using.lua
@@ -0,0 +1,23 @@
1local hello = "hello"
2local world = "world"
3local _
4_ = function()
5 local hello = 3223
6end
7_ = function(a)
8 local hello = 3223
9 a = 323
10end
11_ = function(a, b, c)
12 a, b, c = 1, 2, 3
13 local world = 12321
14end
15_ = function(a, e, f)
16 local b, c
17 a, b, c = 1, 2, 3
18 hello = 12321
19 local world = "yeah"
20end
21_ = function()
22 local hello = hello or 2
23end
diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua
new file mode 100644
index 0000000..e799a94
--- /dev/null
+++ b/spec/outputs/vararg.lua
@@ -0,0 +1,218 @@
1local join
2join = function(...)
3 f_with((function()
4 local _with_0 = a
5 _with_0:func()
6 return _with_0
7 end)())
8 f_with((function(...)
9 local _with_0 = a
10 _with_0:func(...)
11 return _with_0
12 end)(...))
13 f_listcomp((function()
14 local _accum_0 = { }
15 local _len_0 = 1
16 for i = 1, 10 do
17 _accum_0[_len_0] = items[i]
18 _len_0 = _len_0 + 1
19 end
20 return _accum_0
21 end)())
22 f_listcomp((function(...)
23 local _accum_0 = { }
24 local _len_0 = 1
25 for i = 1, 10 do
26 _accum_0[_len_0] = items[i](...)
27 _len_0 = _len_0 + 1
28 end
29 return _accum_0
30 end)(...))
31 f_listcomp((function()
32 local _accum_0 = { }
33 local _len_0 = 1
34 local _list_0 = items
35 for _index_0 = 1, #_list_0 do
36 local item = _list_0[_index_0]
37 _accum_0[_len_0] = item
38 _len_0 = _len_0 + 1
39 end
40 return _accum_0
41 end)())
42 f_listcomp((function(...)
43 local _accum_0 = { }
44 local _len_0 = 1
45 local _list_0 = items
46 for _index_0 = 1, #_list_0 do
47 local item = _list_0[_index_0]
48 _accum_0[_len_0] = item(...)
49 _len_0 = _len_0 + 1
50 end
51 return _accum_0
52 end)(...))
53 f_class((function()
54 local A
55 do
56 local _class_0
57 local _base_0 = { }
58 _base_0.__index = _base_0
59 _class_0 = setmetatable({
60 __init = function() end,
61 __base = _base_0,
62 __name = "A"
63 }, {
64 __index = _base_0,
65 __call = function(cls, ...)
66 local _self_0 = setmetatable({ }, _base_0)
67 cls.__init(_self_0, ...)
68 return _self_0
69 end
70 })
71 _base_0.__class = _class_0
72 local self = _class_0;
73 func()
74 A = _class_0
75 return _class_0
76 end
77 end)())
78 f_class((function(...)
79 local A
80 do
81 local _class_0
82 local _base_0 = { }
83 _base_0.__index = _base_0
84 _class_0 = setmetatable({
85 __init = function() end,
86 __base = _base_0,
87 __name = "A"
88 }, {
89 __index = _base_0,
90 __call = function(cls, ...)
91 local _self_0 = setmetatable({ }, _base_0)
92 cls.__init(_self_0, ...)
93 return _self_0
94 end
95 })
96 _base_0.__class = _class_0
97 local self = _class_0;
98 func(...)
99 A = _class_0
100 return _class_0
101 end
102 end)(...))
103 f_tblcomp((function()
104 local _tbl_0 = { }
105 for k, v in pairs(tb) do
106 _tbl_0[k] = v
107 end
108 return _tbl_0
109 end)())
110 f_tblcomp((function(...)
111 local _tbl_0 = { }
112 for k, v in pairs(tb) do
113 _tbl_0[k] = v(...)
114 end
115 return _tbl_0
116 end)(...))
117 f_tblcomp((function()
118 local _tbl_0 = { }
119 local _list_0 = items
120 for _index_0 = 1, #_list_0 do
121 local item = _list_0[_index_0]
122 _tbl_0[item] = true
123 end
124 return _tbl_0
125 end)())
126 f_tblcomp((function(...)
127 local _tbl_0 = { }
128 local _list_0 = items
129 for _index_0 = 1, #_list_0 do
130 local item = _list_0[_index_0]
131 _tbl_0[item(...)] = true
132 end
133 return _tbl_0
134 end)(...))
135 f_do((function()
136 return func()
137 end)())
138 f_do((function(...)
139 return func(...)
140 end)(...))
141 f_while((function()
142 local _accum_0 = { }
143 local _len_0 = 1
144 while false do
145 _accum_0[_len_0] = func()
146 _len_0 = _len_0 + 1
147 end
148 return _accum_0
149 end)())
150 f_while((function(...)
151 local _accum_0 = { }
152 local _len_0 = 1
153 while false do
154 _accum_0[_len_0] = func(...)
155 _len_0 = _len_0 + 1
156 end
157 return _accum_0
158 end)(...))
159 f_if((function()
160 if false then
161 return func()
162 end
163 end)())
164 f_if((function(...)
165 if false then
166 return func(...)
167 end
168 end)(...))
169 f_unless((function()
170 if not true then
171 return func()
172 end
173 end)())
174 f_unless((function(...)
175 if not true then
176 return func(...)
177 end
178 end)(...))
179 f_switch((function()
180 local _exp_0 = x
181 if "abc" == _exp_0 then
182 return func()
183 end
184 end)())
185 f_switch((function(...)
186 local _exp_0 = x
187 if "abc" == _exp_0 then
188 return func(...)
189 end
190 end)(...))
191 f_eop((function()
192 if func ~= nil then
193 return func()
194 end
195 return nil
196 end)())
197 f_eop((function(...)
198 if func ~= nil then
199 return func(...)
200 end
201 return nil
202 end)(...))
203 f_colon((function()
204 local _base_0 = f()
205 local _fn_0 = _base_0.func
206 return _fn_0 and function(...)
207 return _fn_0(_base_0, ...)
208 end
209 end)())
210 f_colon((function(...)
211 local _base_0 = f(...)
212 local _fn_0 = _base_0.func
213 return _fn_0 and function(...)
214 return _fn_0(_base_0, ...)
215 end
216 end)(...))
217 return nil
218end
diff --git a/spec/outputs/whitespace.lua b/spec/outputs/whitespace.lua
new file mode 100644
index 0000000..1bc4503
--- /dev/null
+++ b/spec/outputs/whitespace.lua
@@ -0,0 +1,98 @@
1local _ = {
2 1,
3 2
4}
5_ = {
6 1,
7 2
8}
9_ = {
10 1,
11 2
12}
13_ = {
14 1,
15 2
16}
17_ = {
18 1,
19 2
20}
21_ = {
22 something(1, 2, 4, 5, 6),
23 3,
24 4,
25 5
26}
27_ = {
28 a(1, 2, 3),
29 4,
30 5,
31 6,
32 1,
33 2,
34 3
35}
36_ = {
37 b(1, 2, 3, 4, 5, 6),
38 1,
39 2,
40 3,
41 1,
42 2,
43 3
44}
45_ = {
46 1,
47 2,
48 3
49}
50_ = {
51 c(1, 2, 3)
52}
53hello(1, 2, 3, 4, 1, 2, 3, 4, 4, 5)
54x(1, 2, 3, 4, 5, 6)
55hello(1, 2, 3, world(4, 5, 6, 5, 6, 7, 8))
56hello(1, 2, 3, world(4, 5, 6, 5, 6, 7, 8), 9, 9)
57_ = {
58 hello(1, 2),
59 3,
60 4,
61 5,
62 6
63}
64local x = {
65 hello(1, 2, 3, 4, 5, 6, 7),
66 1,
67 2,
68 3,
69 4
70}
71if hello(1, 2, 3, world, world) then
72 print("hello")
73end
74if hello(1, 2, 3, world, world) then
75 print("hello")
76end
77a(one, two, three)
78b(one, two, three)
79c(one, two, three, four)
80local v
81v = function()
82 return a, b, c
83end
84local v1, v2, v3
85v1, v2, v3 = function()
86 return a
87end, b, c
88local a, b, c, d, e, f = 1, f2({
89 abc = abc
90}), 3, 4, f5(abc), 6
91for a, b, c in pairs(tb) do
92 print(a, b, c)
93end
94for i = 1, 10, -1 do
95 print(i)
96end
97local a, b, c
98return nil
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua
new file mode 100644
index 0000000..e1497c6
--- /dev/null
+++ b/spec/outputs/with.lua
@@ -0,0 +1,164 @@
1do
2 local a
3 a = function()
4 local _with_0 = something
5 print(_with_0.hello)
6 print(hi)
7 print("world")
8 return _with_0
9 end
10end
11do
12 do
13 local _with_0 = leaf
14 _with_0.world()
15 _with_0.world(1, 2, 3)
16 local g = _with_0.what.is.this
17 _with_0.hi(1, 2, 3)
18 _with_0:hi(1, 2).world(2323)
19 _with_0:hi("yeah", "man")
20 _with_0.world = 200
21 end
22end
23do
24 local zyzyzy
25 do
26 local _with_0 = something
27 _with_0.set_state("hello world")
28 zyzyzy = _with_0
29 end
30end
31do
32 local x = 5 + (function()
33 local _with_0 = Something()
34 _with_0:write("hello world")
35 return _with_0
36 end)()
37end
38do
39 local x = {
40 hello = (function()
41 local _with_0 = yeah
42 _with_0:okay()
43 return _with_0
44 end)()
45 }
46end
47do
48 do
49 local _with_0 = foo
50 local _ = _with_0:prop("something").hello
51 _with_0.prop:send(one)
52 _with_0.prop:send(one)
53 end
54end
55do
56 do
57 local _with_0 = a, b
58 print(_with_0.world)
59 end
60 local mod
61 do
62 local _M = { }
63 _M.Thing = "hi"
64 mod = _M
65 end
66 do
67 local a, b = something, pooh
68 print(a.world)
69 end
70 local x
71 do
72 local a, b = 1, 2
73 print(a + b)
74 x = a
75 end
76 print((function()
77 local a, b = 1, 2
78 print(a + b)
79 return a
80 end)())
81 local p
82 do
83 local _with_0 = 1
84 hello().x, world().y = _with_0, 2
85 print(a + b)
86 p = _with_0
87 end
88end
89do
90 local x = "hello"
91 x:upper()
92end
93do
94 do
95 local k = "jo"
96 print(k:upper())
97 end
98end
99do
100 do
101 local a, b, c = "", "", ""
102 print(a:upper())
103 end
104end
105do
106 local a = "bunk"
107 do
108 local b, c
109 a, b, c = "", "", ""
110 print(a:upper())
111 end
112end
113do
114 do
115 local _with_0 = j
116 print(_with_0:upper())
117 end
118end
119do
120 do
121 local _with_0 = "jo"
122 k.j = _with_0
123 print(_with_0:upper())
124 end
125end
126do
127 do
128 local _with_0 = a
129 print(_with_0.b)
130 do
131 local _with_1 = _with_0.c
132 print(_with_1.d)
133 end
134 end
135end
136do
137 do
138 local _with_0 = a
139 do
140 local _with_1 = 2
141 _with_0.b = _with_1
142 print(_with_1.c)
143 end
144 end
145end
146do
147 local _
148 _ = function()
149 local _with_0 = hi
150 return _with_0.a, _with_0.b
151 end
152end
153do
154 do
155 local _with_0 = tb
156 _with_0.x = item.field:func(123)
157 end
158end
159do
160 local _with_0 = dad
161 _with_0["if"]("yes")
162 local y = _with_0["end"].of["function"]
163 return _with_0
164end