aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs')
-rw-r--r--spec/outputs/5.1/import_global.lua131
-rw-r--r--spec/outputs/5.1/literals.lua44
-rw-r--r--spec/outputs/5.1/loops.lua132
-rw-r--r--spec/outputs/5.1/try_catch.lua265
-rw-r--r--spec/outputs/assign.lua6
-rw-r--r--spec/outputs/codes_from_doc.lua1118
-rw-r--r--spec/outputs/codes_from_doc_zh.lua1118
-rw-r--r--spec/outputs/comprehension.lua10
-rw-r--r--spec/outputs/destructure.lua110
-rw-r--r--spec/outputs/funcs.lua153
-rw-r--r--spec/outputs/global.lua25
-rw-r--r--spec/outputs/import.lua10
-rw-r--r--spec/outputs/import_global.lua131
-rw-r--r--spec/outputs/lists.lua594
-rw-r--r--spec/outputs/loops.lua132
-rw-r--r--spec/outputs/macro.lua15
-rw-r--r--spec/outputs/props.lua240
-rw-r--r--spec/outputs/string.lua41
-rw-r--r--spec/outputs/switch.lua362
-rw-r--r--spec/outputs/syntax.lua94
-rw-r--r--spec/outputs/tables.lua22
-rw-r--r--spec/outputs/test/format_spec.lua2
-rw-r--r--spec/outputs/try_catch.lua266
-rw-r--r--spec/outputs/unicode/assign.lua6
-rw-r--r--spec/outputs/unicode/comprehension.lua10
-rw-r--r--spec/outputs/unicode/funcs.lua2
-rw-r--r--spec/outputs/unicode/import.lua4
-rw-r--r--spec/outputs/unicode/lists.lua23
-rw-r--r--spec/outputs/unicode/loops.lua4
-rw-r--r--spec/outputs/unicode/macro.lua48
-rw-r--r--spec/outputs/unicode/multiline_chain.lua6
-rw-r--r--spec/outputs/unicode/syntax.lua10
-rw-r--r--spec/outputs/unicode/vararg.lua28
-rw-r--r--spec/outputs/unicode/whitespace.lua8
-rw-r--r--spec/outputs/upvalue_func.lua48
-rw-r--r--spec/outputs/vararg.lua100
-rw-r--r--spec/outputs/whitespace.lua8
-rw-r--r--spec/outputs/with.lua62
38 files changed, 5136 insertions, 252 deletions
diff --git a/spec/outputs/5.1/import_global.lua b/spec/outputs/5.1/import_global.lua
new file mode 100644
index 0000000..3b8334a
--- /dev/null
+++ b/spec/outputs/5.1/import_global.lua
@@ -0,0 +1,131 @@
1do
2 local print = print
3 local math = math
4 print("hello")
5 math.random(10)
6end
7do
8 local print = print
9 local value = 1
10 value = value + 2
11 print(value)
12end
13do
14 local print
15 print = function(msg)
16 return msg
17 end
18 do
19 local math = math
20 print("local")
21 math.random(1)
22 end
23end
24do
25 local print = print
26 local tostring
27 tostring = function(v)
28 return "local"
29 end
30 tostring("value")
31 print(tostring(123))
32end
33do
34 local func
35 func = function(x, y)
36 local type = type
37 local tostring = tostring
38 local print = print
39 return type(x, tostring(y, print))
40 end
41 func(1, 2)
42end
43do
44 local xpcall = xpcall
45 local func = func
46 local world = world
47 local tostring = tostring
48 local print = print
49 xpcall(function()
50 return func("hello " .. tostring(world))
51 end, function(err)
52 return print(err)
53 end)
54end
55do
56 local print = print
57 print(FLAG)
58 FLAG = 123
59end
60do
61 local print = print
62 Foo = 10
63 print(Foo)
64 Foo = Foo + 2
65end
66do
67 local print = print
68 Bar = 1
69 Baz = 2
70 print(Bar, Baz)
71end
72do
73 local y = y
74 x = 3434
75 if y then
76 x = 10
77 end
78end
79do
80 local lowercase = lowercase
81 local tostring = tostring
82 local Uppercase = Uppercase
83 local foobar = "all " .. tostring(lowercase)
84 FooBar = "pascal case"
85 FOOBAR = "all " .. tostring(Uppercase)
86end
87do
88 local setmetatable = setmetatable
89 local print = print
90 do
91 local _class_0
92 local _base_0 = { }
93 if _base_0.__index == nil then
94 _base_0.__index = _base_0
95 end
96 _class_0 = setmetatable({
97 __init = function() end,
98 __base = _base_0,
99 __name = "A"
100 }, {
101 __index = _base_0,
102 __call = function(cls, ...)
103 local _self_0 = setmetatable({ }, _base_0)
104 cls.__init(_self_0, ...)
105 return _self_0
106 end
107 })
108 _base_0.__class = _class_0
109 A = _class_0
110 end
111 Flag = 1
112 const, x, y = "const", 1, 2
113 print(math, table)
114end
115do
116 local X = X
117 X:func(1, 2, 3)
118 X.tag = "abc"
119end
120local _anon_func_0 = function(func)
121 return func
122end
123do
124 local func = func
125 local pcall = pcall
126 local f
127 f = function()
128 func()
129 return pcall(_anon_func_0, func)
130 end
131end
diff --git a/spec/outputs/5.1/literals.lua b/spec/outputs/5.1/literals.lua
deleted file mode 100644
index 36c705a..0000000
--- a/spec/outputs/5.1/literals.lua
+++ /dev/null
@@ -1,44 +0,0 @@
1local _ = {
2 121,
3 121.2323,
4 121.2323e-1,
5 121.2323e13434,
6 2323E34,
7 0x12323,
8 0xfF2323,
9 0xabcdef,
10 0xABCDEF,
11 0XFBC400,
12 2.7365508487142853e-35,
13 0xABCP321,
14 2.4074124304840448e-35,
15 6.4326233113470805e-94,
16 0.1171875,
17 162.1875,
18 3.1415926535897931,
19 1,
20 8,
21 15,
22 201,
23 .2323,
24 .2323e-1,
25 .2323e13434,
26 1LL,
27 1ULL,
28 9332LL,
29 9332,
30 0x2aLL,
31 0x2aULL,
32 1000000.0000001,
33 1234e5678,
34 1234E-5678,
35 0xDEADBEEF,
36 [[ hello world ]],
37 [=[ hello world ]=],
38 [====[ hello world ]====],
39 "another world",
40 'what world',
41 "\n hello world\n ",
42 'yeah\n what is going on\n here is something cool'
43}
44return nil
diff --git a/spec/outputs/5.1/loops.lua b/spec/outputs/5.1/loops.lua
index 57b19be..e4f2871 100644
--- a/spec/outputs/5.1/loops.lua
+++ b/spec/outputs/5.1/loops.lua
@@ -60,8 +60,8 @@ do
60 local y = hello[_index_0] 60 local y = hello[_index_0]
61 if y % 2 == 0 then 61 if y % 2 == 0 then
62 _accum_0[_len_0] = y 62 _accum_0[_len_0] = y
63 _len_0 = _len_0 + 1
63 end 64 end
64 _len_0 = _len_0 + 1
65 end 65 end
66 x = _accum_0 66 x = _accum_0
67end 67end
@@ -132,13 +132,11 @@ do
132end 132end
133do 133do
134 local _accum_0 = { } 134 local _accum_0 = { }
135 local _len_0 = 1
136 local _list_2 = 3 135 local _list_2 = 3
137 for _index_0 = 1, #_list_2 do 136 for _index_0 = 1, #_list_2 do
138 local thing = _list_2[_index_0] 137 local thing = _list_2[_index_0]
139 y = "hello" 138 y = "hello"
140 break 139 break
141 _len_0 = _len_0 + 1
142 end 140 end
143 x = _accum_0 141 x = _accum_0
144end 142end
@@ -489,3 +487,131 @@ do
489 end 487 end
490 until false 488 until false
491end 489end
490local _anon_func_0 = function(i, tb)
491 local _accum_0 = { }
492 local _len_0 = 1
493 while tb[i] do
494 i = i + 1
495 _accum_0[_len_0] = i - 1
496 _len_0 = _len_0 + 1
497 end
498 return _accum_0
499end
500do
501 local index
502 do
503 local _accum_0
504 for i = 1, #tb do
505 if tb[i] then
506 _accum_0 = i
507 break
508 end
509 end
510 index = _accum_0
511 end
512 f((function()
513 local _accum_0
514 for i = 1, #tb do
515 if tb[i] then
516 _accum_0 = i
517 break
518 end
519 end
520 return _accum_0
521 end)())
522 f((function()
523 local _accum_0 = { }
524 local _len_0 = 1
525 for i = 1, #tb do
526 if tb[i] then
527 _accum_0[_len_0] = i
528 _len_0 = _len_0 + 1
529 end
530 end
531 return _accum_0
532 end)())
533 i = 1
534 local ids
535 do
536 local _accum_0 = { }
537 local _len_0 = 1
538 while tb[i] do
539 i = i + 1
540 _accum_0[_len_0] = i - 1
541 _len_0 = _len_0 + 1
542 end
543 ids = _accum_0
544 end
545 i = 1
546 local idx
547 do
548 local _accum_0
549 while tb[i] do
550 i = i + 1
551 _accum_0 = i - 1
552 break
553 end
554 idx = _accum_0
555 end
556 local f1
557 f1 = function()
558 i = 1
559 return f(_anon_func_0(i, tb))
560 end
561 i = 1
562 f((function()
563 local _accum_0
564 while tb[i] do
565 i = i + 1
566 _accum_0 = i - 1
567 break
568 end
569 return _accum_0
570 end)())
571 local _accum_0 = { }
572 local _len_0 = 1
573 local _list_3 = items
574 for _index_0 = 1, #_list_3 do
575 local item = _list_3[_index_0]
576 local _type_0 = type(item)
577 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
578 if _tab_0 then
579 local value = item.value
580 if "A" == item.type and value ~= nil then
581 if value > 5 then
582 _accum_0[_len_0] = item
583 _len_0 = _len_0 + 1
584 end
585 end
586 end
587 end
588 list = _accum_0
589end
590do
591 repeat
592 print(1)
593 until true
594 do
595 local _accum_0
596 repeat
597 a = func()
598 _accum_0 = a.x
599 break
600 until a.v
601 x = _accum_0
602 end
603 local items
604 local _accum_0 = { }
605 local _len_0 = 1
606 repeat
607 local item = getItem()
608 if not item then
609 break
610 end
611 if item.value > 0 then
612 _accum_0[_len_0] = item
613 _len_0 = _len_0 + 1
614 end
615 until false
616 items = _accum_0
617end
diff --git a/spec/outputs/5.1/try_catch.lua b/spec/outputs/5.1/try_catch.lua
index efd92c6..d2b58bc 100644
--- a/spec/outputs/5.1/try_catch.lua
+++ b/spec/outputs/5.1/try_catch.lua
@@ -22,6 +22,43 @@ end
22local _anon_func_7 = function(a, b, c, tb) 22local _anon_func_7 = function(a, b, c, tb)
23 return tb.f(a, b, c) 23 return tb.f(a, b, c)
24end 24end
25local _anon_func_8 = function(_arg_0, ...)
26 local ok = _arg_0
27 return ...
28end
29local _anon_func_10 = function(_arg_0, ...)
30 local _ok_0 = _arg_0
31 if _ok_0 then
32 return ...
33 end
34end
35local _anon_func_9 = function(func, pcall)
36 return _anon_func_10(pcall(func))
37end
38local _anon_func_12 = function(_arg_0, ...)
39 local _ok_0 = _arg_0
40 if _ok_0 then
41 return ...
42 end
43end
44local _anon_func_11 = function(func, pcall)
45 return _anon_func_12(pcall(func))
46end
47local _anon_func_14 = function(_arg_0, ...)
48 local _ok_0 = _arg_0
49 if _ok_0 then
50 return ...
51 end
52end
53local _anon_func_13 = function(func, print, xpcall)
54 return _anon_func_14(xpcall(function()
55 print(123)
56 return func()
57 end, function(e)
58 print(e)
59 return e
60 end))
61end
25local f 62local f
26f = function() 63f = function()
27 xpcall(function() 64 xpcall(function()
@@ -104,10 +141,236 @@ f = function()
104 do 141 do
105 x(function() 142 x(function()
106 local tb, a, b, c 143 local tb, a, b, c
107 f = function() 144 local f1
145 f1 = function()
108 return pcall(_anon_func_7, a, b, c, tb) 146 return pcall(_anon_func_7, a, b, c, tb)
109 end 147 end
110 end) 148 end)
111 end 149 end
150 do
151 local f1
152 f1 = function()
153 do
154 return _anon_func_8(pcall(function()
155 return func()
156 end))
157 end
158 end
159 end
160 do
161 local func
162 local a, b, c
163 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
164 if _ok_0 then
165 a, b, c = _ret_0, _ret_1, _ret_2
166 end
167 end
168 do
169 local a, b, c
170 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
171 return func()
172 end)
173 if _ok_0 then
174 a, b, c = _ret_0, _ret_1, _ret_2
175 end
176 end
177 do
178 local a
179 local _exp_0 = (_anon_func_9(func, pcall))
180 if _exp_0 ~= nil then
181 a = _exp_0
182 else
183 a = "default"
184 end
185 end
186 do
187 f(_anon_func_11(func, pcall))
188 end
189 do
190 f(_anon_func_13(func, print, xpcall))
191 end
112 return nil 192 return nil
113end 193end
194local _anon_func_15 = function(a, b, c, tb)
195 return tb.f(a, b, c)
196end
197local _anon_func_16 = function(_arg_0, ...)
198 local ok = _arg_0
199 return ...
200end
201do
202 xpcall(function()
203 return func(1, 2, 3)
204 end, function(err)
205 return print(err)
206 end)
207 xpcall(function()
208 return func(1, 2, 3)
209 end, function(err)
210 return print(err)
211 end)
212 pcall(function()
213 print("trying")
214 return func(1, 2, 3)
215 end)
216 do
217 local success, result = xpcall(function()
218 return func(1, 2, 3)
219 end, function(err)
220 return print(err)
221 end)
222 success, result = pcall(function()
223 return func(1, 2, 3)
224 end)
225 end
226 local tb = { }
227 pcall(function()
228 return tb.func
229 end)
230 pcall(function()
231 return tb.func()
232 end)
233 pcall(function()
234 return tb.func()
235 end)
236 pcall(function()
237 return (tb.func())
238 end)
239 pcall(function()
240 return (tb:func(1, 2, 3))
241 end)
242 pcall(function()
243 return tb.func(1)
244 end)
245 pcall(function()
246 return tb.func(1)
247 end)
248 if (xpcall(function()
249 return func(1)
250 end, function(err)
251 return print(err)
252 end)) then
253 print("OK")
254 end
255 if xpcall(function()
256 return (func(1))
257 end, function(err)
258 return print(err)
259 end) then
260 print("OK")
261 end
262 do
263 do
264 local success, result = pcall(function()
265 return func("abc", 123)
266 end)
267 if success then
268 print(result)
269 end
270 end
271 local success, result = xpcall(function()
272 return func("abc", 123)
273 end, function(err)
274 return print(err)
275 end)
276 success, result = xpcall(function()
277 return func("abc", 123)
278 end, function(err)
279 return print(err)
280 end)
281 if success then
282 print(result)
283 end
284 end
285 do
286 pcall(function()
287 return func(1, 2, 3)
288 end)
289 pcall(function()
290 return func(1, 2, 3)
291 end)
292 end
293 do
294 x(function()
295 local tb, a, b, c
296 local f1
297 f1 = function()
298 return pcall(_anon_func_15, a, b, c, tb)
299 end
300 end)
301 end
302 do
303 local f1
304 f1 = function()
305 do
306 return _anon_func_16(pcall(function()
307 return func()
308 end))
309 end
310 end
311 end
312 do
313 local func
314 local a, b, c
315 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
316 if _ok_0 then
317 a, b, c = _ret_0, _ret_1, _ret_2
318 end
319 end
320 do
321 local a, b, c
322 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
323 return func()
324 end)
325 if _ok_0 then
326 a, b, c = _ret_0, _ret_1, _ret_2
327 end
328 end
329 do
330 local a
331 local _exp_0 = ((function()
332 return (function(_arg_0, ...)
333 local _ok_0 = _arg_0
334 if _ok_0 then
335 return ...
336 end
337 end)(pcall(function()
338 return func()
339 end))
340 end)())
341 if _exp_0 ~= nil then
342 a = _exp_0
343 else
344 a = "default"
345 end
346 end
347 do
348 f((function()
349 return (function(_arg_0, ...)
350 local _ok_0 = _arg_0
351 if _ok_0 then
352 return ...
353 end
354 end)(pcall(function()
355 return func()
356 end))
357 end)())
358 end
359 do
360 f((function()
361 return (function(_arg_0, ...)
362 local _ok_0 = _arg_0
363 if _ok_0 then
364 return ...
365 end
366 end)(xpcall(function()
367 print(123)
368 return func()
369 end, function(e)
370 print(e)
371 return e
372 end))
373 end)())
374 end
375end
376return nil
diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua
index 162c5a8..89c5f8a 100644
--- a/spec/outputs/assign.lua
+++ b/spec/outputs/assign.lua
@@ -43,10 +43,8 @@ do
43 end 43 end
44end 44end
45local _anon_func_0 = function(print) 45local _anon_func_0 = function(print)
46 do 46 print(123)
47 print(123) 47 return { }
48 return { }
49 end
50end 48end
51return _(function() 49return _(function()
52 setmetatable(a, _anon_func_0(print)) 50 setmetatable(a, _anon_func_0(print))
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index f6d5d61..3b0724a 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.lua
@@ -20,6 +20,38 @@ local inventory = {
20 } 20 }
21 } 21 }
22} 22}
23local map
24map = function(arr, action)
25 local _accum_0 = { }
26 local _len_0 = 1
27 for _index_0 = 1, #arr do
28 local item = arr[_index_0]
29 _accum_0[_len_0] = action(item)
30 _len_0 = _len_0 + 1
31 end
32 return _accum_0
33end
34local filter
35filter = function(arr, cond)
36 local _accum_0 = { }
37 local _len_0 = 1
38 for _index_0 = 1, #arr do
39 local item = arr[_index_0]
40 if cond(item) then
41 _accum_0[_len_0] = item
42 _len_0 = _len_0 + 1
43 end
44 end
45 return _accum_0
46end
47local reduce
48reduce = function(arr, init, action)
49 for _index_0 = 1, #arr do
50 local item = arr[_index_0]
51 init = action(init, item)
52 end
53 return init
54end
23print(reduce(filter(map({ 55print(reduce(filter(map({
24 1, 56 1,
25 2, 57 2,
@@ -41,8 +73,8 @@ local apple = setmetatable({
41if (getmetatable(apple) ~= nil) then 73if (getmetatable(apple) ~= nil) then
42 p(apple.size, apple.color, getmetatable(apple).__index) 74 p(apple.size, apple.color, getmetatable(apple).__index)
43end 75end
44local _ud83c_udf1b = "月之脚本" 76local _u1f31b = "月之脚本"
45_module_0["🌛"] = _ud83c_udf1b 77_module_0["🌛"] = _u1f31b
46return _module_0 78return _module_0
47local area = 6.2831853071796 * 5 79local area = 6.2831853071796 * 5
48print('hello world') 80print('hello world')
@@ -77,6 +109,12 @@ end
77print("yuescript") 109print("yuescript")
78print(3) 110print(3)
79print("Valid enum type:", "Static") 111print("Valid enum type:", "Static")
112do
113 print(123, "hello")
114end
115do
116 print(123, "hello")
117end
80if tb ~= nil then 118if tb ~= nil then
81 tb:func() 119 tb:func()
82end 120end
@@ -109,6 +147,21 @@ print((function()
109end)()) 147end)())
110local tab = { } 148local tab = { }
111tab[#tab + 1] = "Value" 149tab[#tab + 1] = "Value"
150local tbA = {
151 1,
152 2,
153 3
154}
155local tbB = {
156 4,
157 5,
158 6
159}
160local _len_0 = #tbA + 1
161for _index_0 = 1, #tbB do
162 local _elm_0 = tbB[_index_0]
163 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
164end
112local parts = { 165local parts = {
113 "shoulders", 166 "shoulders",
114 "knees" 167 "knees"
@@ -177,6 +230,18 @@ for _key_0, _value_0 in pairs(b) do
177 end 230 end
178end 231end
179merge = _tab_0 232merge = _tab_0
233local last
234do
235 local _item_0 = data.items
236 last = _item_0[#_item_0]
237end
238local second_last
239do
240 local _item_0 = data.items
241 second_last = _item_0[#_item_0 - 1]
242end
243local _obj_0 = data.items
244_obj_0[#_obj_0] = 1
180local mt = { } 245local mt = { }
181local add 246local add
182add = function(self, right) 247add = function(self, right)
@@ -307,6 +372,14 @@ func({
307 2, 372 2,
308 3 373 3
309}) 374})
375local f
376f = function()
377 return {
378 1,
379 2,
380 3
381 }
382end
310local tb = { 383local tb = {
311 name = "abc", 384 name = "abc",
312 values = { 385 values = {
@@ -368,6 +441,25 @@ do
368 local _obj_0 = require("export") 441 local _obj_0 = require("export")
369 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 442 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
370end 443end
444do
445 local tostring <const> = tostring
446 local concat <const> = table.concat
447 print(concat({
448 "a",
449 tostring(1)
450 }))
451end
452do
453 local print <const> = print
454 local math <const> = math
455 print("hello")
456 math.random(3)
457end
458do
459 local print <const> = print
460 print(FLAG)
461 FLAG = 123
462end
371local _module_0 = { } 463local _module_0 = { }
372local a, b, c = 1, 2, 3 464local a, b, c = 1, 2, 3
373_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 465_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -547,6 +639,59 @@ end
547local two, four 639local two, four
548local _obj_0 = items 640local _obj_0 = items
549two, four = _obj_0[2], _obj_0[4] 641two, four = _obj_0[2], _obj_0[4]
642local orders = {
643 "first",
644 "second",
645 "third",
646 "fourth",
647 "last"
648}
649local first, bulk, last = orders[1], (function()
650 local _accum_0 = { }
651 local _len_0 = 1
652 local _max_0 = #orders + -2 + 1
653 for _index_0 = 2, _max_0 do
654 local _item_0 = orders[_index_0]
655 _accum_0[_len_0] = _item_0
656 _len_0 = _len_0 + 1
657 end
658 return _accum_0
659end)(), orders[#orders]
660print(first)
661print(bulk)
662print(last)
663local first, rest
664do
665 local _obj_0 = orders
666 first, rest = _obj_0[1], (function()
667 local _accum_0 = { }
668 local _len_0 = 1
669 local _max_0 = #_obj_0
670 for _index_0 = 2, _max_0 do
671 local _item_0 = _obj_0[_index_0]
672 _accum_0[_len_0] = _item_0
673 _len_0 = _len_0 + 1
674 end
675 return _accum_0
676 end)()
677end
678local start, last
679do
680 local _obj_0 = orders
681 start, last = (function()
682 local _accum_0 = { }
683 local _len_0 = 1
684 local _max_0 = #_obj_0 + -2 + 1
685 for _index_0 = 1, _max_0 do
686 local _item_0 = _obj_0[_index_0]
687 _accum_0[_len_0] = _item_0
688 _len_0 = _len_0 + 1
689 end
690 return _accum_0
691 end)(), _obj_0[#_obj_0]
692end
693local _obj_0 = orders
694first, last = _obj_0[1], _obj_0[#_obj_0]
550local tuples = { 695local tuples = {
551 { 696 {
552 "hello", 697 "hello",
@@ -611,6 +756,9 @@ end
611 local first = select(1, ...) 756 local first = select(1, ...)
612 return print(ok, count, first) 757 return print(ok, count, first)
613end)(fn(true)) 758end)(fn(true))
759local a = 1
760local b = 2
761print(a + b)
614Rx.Observable.fromRange(1, 8):filter(function(x) 762Rx.Observable.fromRange(1, 8):filter(function(x)
615 return x % 2 == 0 763 return x % 2 == 0
616end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 764end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -648,6 +796,56 @@ end)
648if success then 796if success then
649 print(result) 797 print(result)
650end 798end
799local a, b, c
800do
801 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
802 return func()
803 end)
804 if _ok_0 then
805 a, b, c = _ret_0, _ret_1, _ret_2
806 end
807end
808do
809 local _exp_0 = ((function()
810 return (function(_arg_0, ...)
811 local _ok_0 = _arg_0
812 if _ok_0 then
813 return ...
814 end
815 end)(pcall(function()
816 return func()
817 end))
818 end)())
819 if _exp_0 ~= nil then
820 a = _exp_0
821 else
822 a = "default"
823 end
824end
825f((function()
826 return (function(_arg_0, ...)
827 local _ok_0 = _arg_0
828 if _ok_0 then
829 return ...
830 end
831 end)(pcall(function()
832 return func()
833 end))
834end)())
835f((function()
836 return (function(_arg_0, ...)
837 local _ok_0 = _arg_0
838 if _ok_0 then
839 return ...
840 end
841 end)(xpcall(function()
842 print(123)
843 return func()
844 end, function(e)
845 print(e)
846 return e
847 end))
848end)())
651local a <const> = 123 849local a <const> = 123
652local _ <close> = setmetatable({ }, { 850local _ <close> = setmetatable({ }, {
653 __close = function() 851 __close = function()
@@ -657,10 +855,19 @@ local _ <close> = setmetatable({ }, {
657local a, b, c, d 855local a, b, c, d
658local _obj_0 = tb 856local _obj_0 = tb
659a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 857a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
858Constant = 123
660local some_string = "Here is a string\n that has a line break in it." 859local some_string = "Here is a string\n that has a line break in it."
661print("I am " .. tostring(math.random() * 100) .. "% sure.") 860print("I am " .. tostring(math.random() * 100) .. "% sure.")
662local integer = 1000000 861local integer = 1000000
663local hex = 0xEFBBBF 862local hex = 0xEFBBBF
863local binary = 19
864local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
865local fn
866fn = function()
867 local str = "foo:\n bar: baz"
868 return str
869end
870local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
664local my_function 871local my_function
665my_function = function() end 872my_function = function() end
666my_function() 873my_function()
@@ -755,6 +962,66 @@ if func(1, 2, 3, "hello", "world") then
755 print("hello") 962 print("hello")
756 print("I am inside if") 963 print("I am inside if")
757end 964end
965local f1
966f1 = function(_arg_0)
967 local a, b, c
968 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
969 return print(a, b, c)
970end
971f1({
972 a = 1,
973 b = "2",
974 c = { }
975})
976local f2
977f2 = function(_arg_0, c)
978 local a1, b
979 a1, b = _arg_0.a, _arg_0.b
980 if a1 == nil then
981 a1 = 123
982 end
983 if b == nil then
984 b = 'abc'
985 end
986 if c == nil then
987 c = { }
988 end
989 return print(a1, b, c)
990end
991local arg1 = {
992 a = 0
993}
994f2(arg1, arg2)
995local f
996f = function(...)
997 local t = {
998 n = select("#", ...),
999 ...
1000 }
1001 print("argument count:", t.n)
1002 print("table length:", #t)
1003 for i = 1, t.n do
1004 print(t[i])
1005 end
1006end
1007f(1, 2, 3)
1008f("a", "b", "c", "d")
1009f()
1010local process
1011process = function(...)
1012 local args = {
1013 n = select("#", ...),
1014 ...
1015 }
1016 local sum = 0
1017 for i = 1, args.n do
1018 if args[i] ~= nil and type(args[i]) == "number" then
1019 sum = sum + args[i]
1020 end
1021 end
1022 return sum
1023end
1024process(1, nil, 3, nil, 5)
758f(function() 1025f(function()
759 return print("hello") 1026 return print("hello")
760end) 1027end)
@@ -880,6 +1147,28 @@ for _index_0 = 1, #_list_0 do
880 _len_0 = _len_0 + 1 1147 _len_0 = _len_0 + 1
881end 1148end
882doubled = _accum_0 1149doubled = _accum_0
1150local data = {
1151 a = {
1152 1,
1153 2,
1154 3
1155 },
1156 b = {
1157 4,
1158 5,
1159 6
1160 }
1161}
1162local flat
1163local _accum_0 = { }
1164for k, v in pairs(data) do
1165 local _len_0 = #_accum_0 + 1
1166 for _index_0 = 1, #v do
1167 local _elm_0 = v[_index_0]
1168 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
1169 end
1170end
1171flat = _accum_0
883local x_coords = { 1172local x_coords = {
884 4, 1173 4,
885 5, 1174 5,
@@ -970,8 +1259,18 @@ local slice
970local _accum_0 = { } 1259local _accum_0 = { }
971local _len_0 = 1 1260local _len_0 = 1
972local _list_0 = items 1261local _list_0 = items
973local _max_0 = 5 1262for _index_0 = 1, 5 do
974for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 1263 local item = _list_0[_index_0]
1264 _accum_0[_len_0] = item
1265 _len_0 = _len_0 + 1
1266end
1267slice = _accum_0
1268local slice
1269local _accum_0 = { }
1270local _len_0 = 1
1271local _list_0 = items
1272local _max_0 = #_list_0
1273for _index_0 = 2, _max_0 do
975 local item = _list_0[_index_0] 1274 local item = _list_0[_index_0]
976 _accum_0[_len_0] = item 1275 _accum_0[_len_0] = item
977 _len_0 = _len_0 + 1 1276 _len_0 = _len_0 + 1
@@ -981,7 +1280,8 @@ local slice
981local _accum_0 = { } 1280local _accum_0 = { }
982local _len_0 = 1 1281local _len_0 = 1
983local _list_0 = items 1282local _list_0 = items
984for _index_0 = 2, #_list_0 do 1283local _max_0 = #_list_0
1284for _index_0 = 1, _max_0, 2 do
985 local item = _list_0[_index_0] 1285 local item = _list_0[_index_0]
986 _accum_0[_len_0] = item 1286 _accum_0[_len_0] = item
987 _len_0 = _len_0 + 1 1287 _len_0 = _len_0 + 1
@@ -991,12 +1291,35 @@ local slice
991local _accum_0 = { } 1291local _accum_0 = { }
992local _len_0 = 1 1292local _len_0 = 1
993local _list_0 = items 1293local _list_0 = items
994for _index_0 = 1, #_list_0, 2 do 1294local _min_0 = #_list_0 + -4 + 1
1295local _max_0 = #_list_0 + -1 + 1
1296for _index_0 = _min_0, _max_0 do
995 local item = _list_0[_index_0] 1297 local item = _list_0[_index_0]
996 _accum_0[_len_0] = item 1298 _accum_0[_len_0] = item
997 _len_0 = _len_0 + 1 1299 _len_0 = _len_0 + 1
998end 1300end
999slice = _accum_0 1301slice = _accum_0
1302local reverse_slice
1303local _accum_0 = { }
1304local _len_0 = 1
1305local _list_0 = items
1306local _min_0 = #_list_0 + -1 + 1
1307for _index_0 = _min_0, 1, -1 do
1308 local item = _list_0[_index_0]
1309 _accum_0[_len_0] = item
1310 _len_0 = _len_0 + 1
1311end
1312reverse_slice = _accum_0
1313local sub_list
1314local _accum_0 = { }
1315local _len_0 = 1
1316local _list_0 = items
1317for _index_0 = 2, 4 do
1318 local _item_0 = _list_0[_index_0]
1319 _accum_0[_len_0] = _item_0
1320 _len_0 = _len_0 + 1
1321end
1322sub_list = _accum_0
1000for i = 10, 20 do 1323for i = 10, 20 do
1001 print(i) 1324 print(i)
1002end 1325end
@@ -1007,8 +1330,7 @@ for key, value in pairs(object) do
1007 print(key, value) 1330 print(key, value)
1008end 1331end
1009local _list_0 = items 1332local _list_0 = items
1010local _max_0 = 4 1333for _index_0 = 2, 4 do
1011for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1012 local item = _list_0[_index_0] 1334 local item = _list_0[_index_0]
1013 print(item) 1335 print(item)
1014end 1336end
@@ -1026,12 +1348,24 @@ local _len_0 = 1
1026for i = 1, 20 do 1348for i = 1, 20 do
1027 if i % 2 == 0 then 1349 if i % 2 == 0 then
1028 _accum_0[_len_0] = i * 2 1350 _accum_0[_len_0] = i * 2
1351 _len_0 = _len_0 + 1
1029 else 1352 else
1030 _accum_0[_len_0] = i 1353 _accum_0[_len_0] = i
1354 _len_0 = _len_0 + 1
1031 end 1355 end
1032 _len_0 = _len_0 + 1
1033end 1356end
1034doubled_evens = _accum_0 1357doubled_evens = _accum_0
1358local first_large
1359local _accum_0
1360local _list_0 = numbers
1361for _index_0 = 1, #_list_0 do
1362 local n = _list_0[_index_0]
1363 if n > 10 then
1364 _accum_0 = n
1365 break
1366 end
1367end
1368first_large = _accum_0
1035local func_a 1369local func_a
1036func_a = function() 1370func_a = function()
1037 for i = 1, 10 do 1371 for i = 1, 10 do
@@ -1180,7 +1514,7 @@ if "Robert" == name then
1180elseif "Dan" == name or "Daniel" == name then 1514elseif "Dan" == name or "Daniel" == name then
1181 print("Your name, it's Dan") 1515 print("Your name, it's Dan")
1182else 1516else
1183 print("I don't know about your name") 1517 print("I don't know about you with name " .. tostring(name))
1184end 1518end
1185local b = 1 1519local b = 1
1186local next_number 1520local next_number
@@ -1280,6 +1614,192 @@ if _tab_0 then
1280 end 1614 end
1281 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1615 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1282end 1616end
1617local _exp_0 = tb
1618local _type_0 = type(_exp_0)
1619local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1620local _match_0 = false
1621if _tab_0 then
1622 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1623 _match_0 = true
1624 print("1, 2, 3")
1625 end
1626end
1627if not _match_0 then
1628 local _match_1 = false
1629 if _tab_0 then
1630 local b = _exp_0[2]
1631 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1632 _match_1 = true
1633 print("1, " .. tostring(b) .. ", 3")
1634 end
1635 end
1636 if not _match_1 then
1637 if _tab_0 then
1638 local b = _exp_0[3]
1639 if b == nil then
1640 b = 3
1641 end
1642 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1643 print("1, 2, " .. tostring(b))
1644 end
1645 end
1646 end
1647end
1648local _exp_0 = tb
1649local _type_0 = type(_exp_0)
1650local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1651local _match_0 = false
1652if _tab_0 then
1653 local result = _exp_0.result
1654 if true == _exp_0.success and result ~= nil then
1655 _match_0 = true
1656 print("success", result)
1657 end
1658end
1659if not _match_0 then
1660 local _match_1 = false
1661 if _tab_0 then
1662 if false == _exp_0.success then
1663 _match_1 = true
1664 print("failed", result)
1665 end
1666 end
1667 if not _match_1 then
1668 print("invalid")
1669 end
1670end
1671local _exp_0 = tb
1672local _type_0 = type(_exp_0)
1673local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1674local _match_0 = false
1675if _tab_0 then
1676 local content
1677 do
1678 local _obj_0 = _exp_0.data
1679 local _type_1 = type(_obj_0)
1680 if "table" == _type_1 or "userdata" == _type_1 then
1681 content = _obj_0.content
1682 end
1683 end
1684 local _val_0
1685 do
1686 local _obj_0 = _exp_0.data
1687 if _obj_0 ~= nil then
1688 _val_0 = _obj_0.type
1689 end
1690 end
1691 if "success" == _val_0 and content ~= nil then
1692 _match_0 = true
1693 print("success", content)
1694 end
1695end
1696if not _match_0 then
1697 local _match_1 = false
1698 if _tab_0 then
1699 local content
1700 do
1701 local _obj_0 = _exp_0.data
1702 local _type_1 = type(_obj_0)
1703 if "table" == _type_1 or "userdata" == _type_1 then
1704 content = _obj_0.content
1705 end
1706 end
1707 local _val_0
1708 do
1709 local _obj_0 = _exp_0.data
1710 if _obj_0 ~= nil then
1711 _val_0 = _obj_0.type
1712 end
1713 end
1714 if "error" == _val_0 and content ~= nil then
1715 _match_1 = true
1716 print("failed", content)
1717 end
1718 end
1719 if not _match_1 then
1720 print("invalid")
1721 end
1722end
1723local _exp_0 = tb
1724local _type_0 = type(_exp_0)
1725local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1726if _tab_0 then
1727 local fourth = _exp_0[4]
1728 local _val_0
1729 do
1730 local _obj_0 = _exp_0[1]
1731 if _obj_0 ~= nil then
1732 _val_0 = _obj_0.a
1733 end
1734 end
1735 local _val_1
1736 do
1737 local _obj_0 = _exp_0[1]
1738 if _obj_0 ~= nil then
1739 _val_1 = _obj_0.b
1740 end
1741 end
1742 local _val_2
1743 do
1744 local _obj_0 = _exp_0[2]
1745 if _obj_0 ~= nil then
1746 _val_2 = _obj_0.a
1747 end
1748 end
1749 local _val_3
1750 do
1751 local _obj_0 = _exp_0[2]
1752 if _obj_0 ~= nil then
1753 _val_3 = _obj_0.b
1754 end
1755 end
1756 local _val_4
1757 do
1758 local _obj_0 = _exp_0[3]
1759 if _obj_0 ~= nil then
1760 _val_4 = _obj_0.a
1761 end
1762 end
1763 local _val_5
1764 do
1765 local _obj_0 = _exp_0[3]
1766 if _obj_0 ~= nil then
1767 _val_5 = _obj_0.b
1768 end
1769 end
1770 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
1771 print("matched", fourth)
1772 end
1773end
1774local segments = {
1775 "admin",
1776 "users",
1777 "logs",
1778 "view"
1779}
1780local _type_0 = type(segments)
1781local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1782if _tab_0 then
1783 local groups
1784 do
1785 local _accum_0 = { }
1786 local _len_0 = 1
1787 local _max_0 = #segments + -3 + 1
1788 for _index_0 = 1, _max_0 do
1789 local _item_0 = segments[_index_0]
1790 _accum_0[_len_0] = _item_0
1791 _len_0 = _len_0 + 1
1792 end
1793 groups = _accum_0
1794 end
1795 local resource = segments[#segments - 1]
1796 local action = segments[#segments]
1797 if resource ~= nil and action ~= nil then
1798 print("Group:", groups)
1799 print("Resource:", resource)
1800 print("Action:", action)
1801 end
1802end
1283local Inventory 1803local Inventory
1284local _class_0 1804local _class_0
1285local _base_0 = { 1805local _base_0 = {
@@ -1936,6 +2456,10 @@ do
1936 _with_1["key-name"] = value 2456 _with_1["key-name"] = value
1937end 2457end
1938_with_0[#_with_0 + 1] = "abc" 2458_with_0[#_with_0 + 1] = "abc"
2459local _with_0 = obj
2460if _with_0 ~= nil then
2461 print(obj.name)
2462end
1939do 2463do
1940 local var = "hello" 2464 local var = "hello"
1941 print(var) 2465 print(var)
@@ -2026,6 +2550,38 @@ local inventory = {
2026 } 2550 }
2027 } 2551 }
2028} 2552}
2553local map
2554map = function(arr, action)
2555 local _accum_0 = { }
2556 local _len_0 = 1
2557 for _index_0 = 1, #arr do
2558 local item = arr[_index_0]
2559 _accum_0[_len_0] = action(item)
2560 _len_0 = _len_0 + 1
2561 end
2562 return _accum_0
2563end
2564local filter
2565filter = function(arr, cond)
2566 local _accum_0 = { }
2567 local _len_0 = 1
2568 for _index_0 = 1, #arr do
2569 local item = arr[_index_0]
2570 if cond(item) then
2571 _accum_0[_len_0] = item
2572 _len_0 = _len_0 + 1
2573 end
2574 end
2575 return _accum_0
2576end
2577local reduce
2578reduce = function(arr, init, action)
2579 for _index_0 = 1, #arr do
2580 local item = arr[_index_0]
2581 init = action(init, item)
2582 end
2583 return init
2584end
2029print(reduce(filter(map({ 2585print(reduce(filter(map({
2030 1, 2586 1,
2031 2, 2587 2,
@@ -2047,8 +2603,8 @@ local apple = setmetatable({
2047if (getmetatable(apple) ~= nil) then 2603if (getmetatable(apple) ~= nil) then
2048 p(apple.size, apple.color, getmetatable(apple).__index) 2604 p(apple.size, apple.color, getmetatable(apple).__index)
2049end 2605end
2050local _ud83c_udf1b = "月之脚本" 2606local _u1f31b = "月之脚本"
2051_module_0["🌛"] = _ud83c_udf1b 2607_module_0["🌛"] = _u1f31b
2052return _module_0 2608return _module_0
2053local area = 6.2831853071796 * 5 2609local area = 6.2831853071796 * 5
2054print('hello world') 2610print('hello world')
@@ -2083,6 +2639,12 @@ end
2083print("yuescript") 2639print("yuescript")
2084print(3) 2640print(3)
2085print("Valid enum type:", "Static") 2641print("Valid enum type:", "Static")
2642do
2643 print(123, "hello")
2644end
2645do
2646 print(123, "hello")
2647end
2086if tb ~= nil then 2648if tb ~= nil then
2087 tb:func() 2649 tb:func()
2088end 2650end
@@ -2115,6 +2677,21 @@ print((function()
2115end)()) 2677end)())
2116local tab = { } 2678local tab = { }
2117tab[#tab + 1] = "Value" 2679tab[#tab + 1] = "Value"
2680local tbA = {
2681 1,
2682 2,
2683 3
2684}
2685local tbB = {
2686 4,
2687 5,
2688 6
2689}
2690local _len_0 = #tbA + 1
2691for _index_0 = 1, #tbB do
2692 local _elm_0 = tbB[_index_0]
2693 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
2694end
2118local parts = { 2695local parts = {
2119 "shoulders", 2696 "shoulders",
2120 "knees" 2697 "knees"
@@ -2183,6 +2760,18 @@ for _key_0, _value_0 in pairs(b) do
2183 end 2760 end
2184end 2761end
2185merge = _tab_0 2762merge = _tab_0
2763local last
2764do
2765 local _item_0 = data.items
2766 last = _item_0[#_item_0]
2767end
2768local second_last
2769do
2770 local _item_0 = data.items
2771 second_last = _item_0[#_item_0 - 1]
2772end
2773local _obj_0 = data.items
2774_obj_0[#_obj_0] = 1
2186local mt = { } 2775local mt = { }
2187local add 2776local add
2188add = function(self, right) 2777add = function(self, right)
@@ -2313,6 +2902,14 @@ func({
2313 2, 2902 2,
2314 3 2903 3
2315}) 2904})
2905local f
2906f = function()
2907 return {
2908 1,
2909 2,
2910 3
2911 }
2912end
2316local tb = { 2913local tb = {
2317 name = "abc", 2914 name = "abc",
2318 values = { 2915 values = {
@@ -2374,6 +2971,25 @@ do
2374 local _obj_0 = require("export") 2971 local _obj_0 = require("export")
2375 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 2972 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
2376end 2973end
2974do
2975 local tostring <const> = tostring
2976 local concat <const> = table.concat
2977 print(concat({
2978 "a",
2979 tostring(1)
2980 }))
2981end
2982do
2983 local print <const> = print
2984 local math <const> = math
2985 print("hello")
2986 math.random(3)
2987end
2988do
2989 local print <const> = print
2990 print(FLAG)
2991 FLAG = 123
2992end
2377local _module_0 = { } 2993local _module_0 = { }
2378local a, b, c = 1, 2, 3 2994local a, b, c = 1, 2, 3
2379_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 2995_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -2553,6 +3169,59 @@ end
2553local two, four 3169local two, four
2554local _obj_0 = items 3170local _obj_0 = items
2555two, four = _obj_0[2], _obj_0[4] 3171two, four = _obj_0[2], _obj_0[4]
3172local orders = {
3173 "first",
3174 "second",
3175 "third",
3176 "fourth",
3177 "last"
3178}
3179local first, bulk, last = orders[1], (function()
3180 local _accum_0 = { }
3181 local _len_0 = 1
3182 local _max_0 = #orders + -2 + 1
3183 for _index_0 = 2, _max_0 do
3184 local _item_0 = orders[_index_0]
3185 _accum_0[_len_0] = _item_0
3186 _len_0 = _len_0 + 1
3187 end
3188 return _accum_0
3189end)(), orders[#orders]
3190print(first)
3191print(bulk)
3192print(last)
3193local first, rest
3194do
3195 local _obj_0 = orders
3196 first, rest = _obj_0[1], (function()
3197 local _accum_0 = { }
3198 local _len_0 = 1
3199 local _max_0 = #_obj_0
3200 for _index_0 = 2, _max_0 do
3201 local _item_0 = _obj_0[_index_0]
3202 _accum_0[_len_0] = _item_0
3203 _len_0 = _len_0 + 1
3204 end
3205 return _accum_0
3206 end)()
3207end
3208local start, last
3209do
3210 local _obj_0 = orders
3211 start, last = (function()
3212 local _accum_0 = { }
3213 local _len_0 = 1
3214 local _max_0 = #_obj_0 + -2 + 1
3215 for _index_0 = 1, _max_0 do
3216 local _item_0 = _obj_0[_index_0]
3217 _accum_0[_len_0] = _item_0
3218 _len_0 = _len_0 + 1
3219 end
3220 return _accum_0
3221 end)(), _obj_0[#_obj_0]
3222end
3223local _obj_0 = orders
3224first, last = _obj_0[1], _obj_0[#_obj_0]
2556local tuples = { 3225local tuples = {
2557 { 3226 {
2558 "hello", 3227 "hello",
@@ -2617,6 +3286,9 @@ end
2617 local first = select(1, ...) 3286 local first = select(1, ...)
2618 return print(ok, count, first) 3287 return print(ok, count, first)
2619end)(fn(true)) 3288end)(fn(true))
3289local a = 1
3290local b = 2
3291print(a + b)
2620Rx.Observable.fromRange(1, 8):filter(function(x) 3292Rx.Observable.fromRange(1, 8):filter(function(x)
2621 return x % 2 == 0 3293 return x % 2 == 0
2622end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 3294end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -2654,6 +3326,56 @@ end)
2654if success then 3326if success then
2655 print(result) 3327 print(result)
2656end 3328end
3329local a, b, c
3330do
3331 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3332 return func()
3333 end)
3334 if _ok_0 then
3335 a, b, c = _ret_0, _ret_1, _ret_2
3336 end
3337end
3338do
3339 local _exp_0 = ((function()
3340 return (function(_arg_0, ...)
3341 local _ok_0 = _arg_0
3342 if _ok_0 then
3343 return ...
3344 end
3345 end)(pcall(function()
3346 return func()
3347 end))
3348 end)())
3349 if _exp_0 ~= nil then
3350 a = _exp_0
3351 else
3352 a = "default"
3353 end
3354end
3355f((function()
3356 return (function(_arg_0, ...)
3357 local _ok_0 = _arg_0
3358 if _ok_0 then
3359 return ...
3360 end
3361 end)(pcall(function()
3362 return func()
3363 end))
3364end)())
3365f((function()
3366 return (function(_arg_0, ...)
3367 local _ok_0 = _arg_0
3368 if _ok_0 then
3369 return ...
3370 end
3371 end)(xpcall(function()
3372 print(123)
3373 return func()
3374 end, function(e)
3375 print(e)
3376 return e
3377 end))
3378end)())
2657local a <const> = 123 3379local a <const> = 123
2658local _ <close> = setmetatable({ }, { 3380local _ <close> = setmetatable({ }, {
2659 __close = function() 3381 __close = function()
@@ -2663,10 +3385,19 @@ local _ <close> = setmetatable({ }, {
2663local a, b, c, d 3385local a, b, c, d
2664local _obj_0 = tb 3386local _obj_0 = tb
2665a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3387a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3388Constant = 123
2666local some_string = "Here is a string\n that has a line break in it." 3389local some_string = "Here is a string\n that has a line break in it."
2667print("I am " .. tostring(math.random() * 100) .. "% sure.") 3390print("I am " .. tostring(math.random() * 100) .. "% sure.")
2668local integer = 1000000 3391local integer = 1000000
2669local hex = 0xEFBBBF 3392local hex = 0xEFBBBF
3393local binary = 19
3394local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3395local fn
3396fn = function()
3397 local str = "foo:\n bar: baz"
3398 return str
3399end
3400local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2670local my_function 3401local my_function
2671my_function = function() end 3402my_function = function() end
2672my_function() 3403my_function()
@@ -2761,6 +3492,96 @@ if func(1, 2, 3, "hello", "world") then
2761 print("hello") 3492 print("hello")
2762 print("I am inside if") 3493 print("I am inside if")
2763end 3494end
3495local f1
3496f1 = function(_arg_0)
3497 local a, b, c
3498 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
3499 return print(a, b, c)
3500end
3501f1({
3502 a = 1,
3503 b = "2",
3504 c = { }
3505})
3506local f2
3507f2 = function(_arg_0, c)
3508 local a1, b
3509 a1, b = _arg_0.a, _arg_0.b
3510 if a1 == nil then
3511 a1 = 123
3512 end
3513 if b == nil then
3514 b = 'abc'
3515 end
3516 if c == nil then
3517 c = { }
3518 end
3519end
3520print(a1, b, c)
3521local arg1 = {
3522 a = 0
3523}
3524f2(arg1, arg2)
3525local findFirstEven
3526findFirstEven = function(list)
3527 for _index_0 = 1, #list do
3528 local item = list[_index_0]
3529 if type(item) == "table" then
3530 for _index_1 = 1, #item do
3531 local sub = item[_index_1]
3532 if sub % 2 == 0 then
3533 return sub
3534 end
3535 end
3536 end
3537 end
3538 return nil
3539end
3540local findFirstEven
3541findFirstEven = function(list)
3542 for _index_0 = 1, #list do
3543 local item = list[_index_0]
3544 if type(item) == "table" then
3545 for _index_1 = 1, #item do
3546 local sub = item[_index_1]
3547 if sub % 2 == 0 then
3548 return sub
3549 end
3550 end
3551 end
3552 end
3553 return nil
3554end
3555local f
3556f = function(...)
3557 local t = {
3558 n = select("#", ...),
3559 ...
3560 }
3561 print("argument count:", t.n)
3562 print("table length:", #t)
3563 for i = 1, t.n do
3564 print(t[i])
3565 end
3566end
3567f(1, 2, 3)
3568f("a", "b", "c", "d")
3569f()
3570local process
3571process = function(...)
3572 local args = {
3573 n = select("#", ...),
3574 ...
3575 }
3576 local sum = 0
3577 for i = 1, args.n do
3578 if args[i] ~= nil and type(args[i]) == "number" then
3579 sum = sum + args[i]
3580 end
3581 end
3582 return sum
3583end
3584process(1, nil, 3, nil, 5)
2764f(function() 3585f(function()
2765 return print("hello") 3586 return print("hello")
2766end) 3587end)
@@ -2886,6 +3707,28 @@ for _index_0 = 1, #_list_0 do
2886 _len_0 = _len_0 + 1 3707 _len_0 = _len_0 + 1
2887end 3708end
2888doubled = _accum_0 3709doubled = _accum_0
3710local data = {
3711 a = {
3712 1,
3713 2,
3714 3
3715 },
3716 b = {
3717 4,
3718 5,
3719 6
3720 }
3721}
3722local flat
3723local _accum_0 = { }
3724for k, v in pairs(data) do
3725 local _len_0 = #_accum_0 + 1
3726 for _index_0 = 1, #v do
3727 local _elm_0 = v[_index_0]
3728 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
3729 end
3730end
3731flat = _accum_0
2889local x_coords = { 3732local x_coords = {
2890 4, 3733 4,
2891 5, 3734 5,
@@ -2976,8 +3819,7 @@ local slice
2976local _accum_0 = { } 3819local _accum_0 = { }
2977local _len_0 = 1 3820local _len_0 = 1
2978local _list_0 = items 3821local _list_0 = items
2979local _max_0 = 5 3822for _index_0 = 1, 5 do
2980for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
2981 local item = _list_0[_index_0] 3823 local item = _list_0[_index_0]
2982 _accum_0[_len_0] = item 3824 _accum_0[_len_0] = item
2983 _len_0 = _len_0 + 1 3825 _len_0 = _len_0 + 1
@@ -2987,7 +3829,8 @@ local slice
2987local _accum_0 = { } 3829local _accum_0 = { }
2988local _len_0 = 1 3830local _len_0 = 1
2989local _list_0 = items 3831local _list_0 = items
2990for _index_0 = 2, #_list_0 do 3832local _max_0 = #_list_0
3833for _index_0 = 2, _max_0 do
2991 local item = _list_0[_index_0] 3834 local item = _list_0[_index_0]
2992 _accum_0[_len_0] = item 3835 _accum_0[_len_0] = item
2993 _len_0 = _len_0 + 1 3836 _len_0 = _len_0 + 1
@@ -2997,12 +3840,46 @@ local slice
2997local _accum_0 = { } 3840local _accum_0 = { }
2998local _len_0 = 1 3841local _len_0 = 1
2999local _list_0 = items 3842local _list_0 = items
3000for _index_0 = 1, #_list_0, 2 do 3843local _max_0 = #_list_0
3844for _index_0 = 1, _max_0, 2 do
3001 local item = _list_0[_index_0] 3845 local item = _list_0[_index_0]
3002 _accum_0[_len_0] = item 3846 _accum_0[_len_0] = item
3003 _len_0 = _len_0 + 1 3847 _len_0 = _len_0 + 1
3004end 3848end
3005slice = _accum_0 3849slice = _accum_0
3850local slice
3851local _accum_0 = { }
3852local _len_0 = 1
3853local _list_0 = items
3854local _min_0 = #_list_0 + -4 + 1
3855local _max_0 = #_list_0 + -1 + 1
3856for _index_0 = _min_0, _max_0 do
3857 local item = _list_0[_index_0]
3858 _accum_0[_len_0] = item
3859 _len_0 = _len_0 + 1
3860end
3861slice = _accum_0
3862local reverse_slice
3863local _accum_0 = { }
3864local _len_0 = 1
3865local _list_0 = items
3866local _min_0 = #_list_0 + -1 + 1
3867for _index_0 = _min_0, 1, -1 do
3868 local item = _list_0[_index_0]
3869 _accum_0[_len_0] = item
3870 _len_0 = _len_0 + 1
3871end
3872reverse_slice = _accum_0
3873local sub_list
3874local _accum_0 = { }
3875local _len_0 = 1
3876local _list_0 = items
3877for _index_0 = 2, 4 do
3878 local _item_0 = _list_0[_index_0]
3879 _accum_0[_len_0] = _item_0
3880 _len_0 = _len_0 + 1
3881end
3882sub_list = _accum_0
3006for i = 10, 20 do 3883for i = 10, 20 do
3007 print(i) 3884 print(i)
3008end 3885end
@@ -3013,8 +3890,7 @@ for key, value in pairs(object) do
3013 print(key, value) 3890 print(key, value)
3014end 3891end
3015local _list_0 = items 3892local _list_0 = items
3016local _max_0 = 4 3893for _index_0 = 2, 4 do
3017for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3018 local item = _list_0[_index_0] 3894 local item = _list_0[_index_0]
3019 print(item) 3895 print(item)
3020end 3896end
@@ -3032,12 +3908,24 @@ local _len_0 = 1
3032for i = 1, 20 do 3908for i = 1, 20 do
3033 if i % 2 == 0 then 3909 if i % 2 == 0 then
3034 _accum_0[_len_0] = i * 2 3910 _accum_0[_len_0] = i * 2
3911 _len_0 = _len_0 + 1
3035 else 3912 else
3036 _accum_0[_len_0] = i 3913 _accum_0[_len_0] = i
3914 _len_0 = _len_0 + 1
3037 end 3915 end
3038 _len_0 = _len_0 + 1
3039end 3916end
3040doubled_evens = _accum_0 3917doubled_evens = _accum_0
3918local first_large
3919local _accum_0
3920local _list_0 = numbers
3921for _index_0 = 1, #_list_0 do
3922 local n = _list_0[_index_0]
3923 if n > 10 then
3924 _accum_0 = n
3925 break
3926 end
3927end
3928first_large = _accum_0
3041local func_a 3929local func_a
3042func_a = function() 3930func_a = function()
3043 for i = 1, 10 do 3931 for i = 1, 10 do
@@ -3186,7 +4074,7 @@ if "Robert" == name then
3186elseif "Dan" == name or "Daniel" == name then 4074elseif "Dan" == name or "Daniel" == name then
3187 print("Your name, it's Dan") 4075 print("Your name, it's Dan")
3188else 4076else
3189 print("I don't know about your name") 4077 print("I don't know about you with name " .. tostring(name))
3190end 4078end
3191local b = 1 4079local b = 1
3192local next_number 4080local next_number
@@ -3286,6 +4174,192 @@ if _tab_0 then
3286 end 4174 end
3287 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 4175 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3288end 4176end
4177local _exp_0 = tb
4178local _type_0 = type(_exp_0)
4179local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4180local _match_0 = false
4181if _tab_0 then
4182 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
4183 _match_0 = true
4184 print("1, 2, 3")
4185 end
4186end
4187if not _match_0 then
4188 local _match_1 = false
4189 if _tab_0 then
4190 local b = _exp_0[2]
4191 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
4192 _match_1 = true
4193 print("1, " .. tostring(b) .. ", 3")
4194 end
4195 end
4196 if not _match_1 then
4197 if _tab_0 then
4198 local b = _exp_0[3]
4199 if b == nil then
4200 b = 3
4201 end
4202 if 1 == _exp_0[1] and 2 == _exp_0[2] then
4203 print("1, 2, " .. tostring(b))
4204 end
4205 end
4206 end
4207end
4208local _exp_0 = tb
4209local _type_0 = type(_exp_0)
4210local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4211local _match_0 = false
4212if _tab_0 then
4213 local result = _exp_0.result
4214 if true == _exp_0.success and result ~= nil then
4215 _match_0 = true
4216 print("success", result)
4217 end
4218end
4219if not _match_0 then
4220 local _match_1 = false
4221 if _tab_0 then
4222 if false == _exp_0.success then
4223 _match_1 = true
4224 print("failed", result)
4225 end
4226 end
4227 if not _match_1 then
4228 print("invalid")
4229 end
4230end
4231local _exp_0 = tb
4232local _type_0 = type(_exp_0)
4233local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4234local _match_0 = false
4235if _tab_0 then
4236 local content
4237 do
4238 local _obj_0 = _exp_0.data
4239 local _type_1 = type(_obj_0)
4240 if "table" == _type_1 or "userdata" == _type_1 then
4241 content = _obj_0.content
4242 end
4243 end
4244 local _val_0
4245 do
4246 local _obj_0 = _exp_0.data
4247 if _obj_0 ~= nil then
4248 _val_0 = _obj_0.type
4249 end
4250 end
4251 if "success" == _val_0 and content ~= nil then
4252 _match_0 = true
4253 print("success", content)
4254 end
4255end
4256if not _match_0 then
4257 local _match_1 = false
4258 if _tab_0 then
4259 local content
4260 do
4261 local _obj_0 = _exp_0.data
4262 local _type_1 = type(_obj_0)
4263 if "table" == _type_1 or "userdata" == _type_1 then
4264 content = _obj_0.content
4265 end
4266 end
4267 local _val_0
4268 do
4269 local _obj_0 = _exp_0.data
4270 if _obj_0 ~= nil then
4271 _val_0 = _obj_0.type
4272 end
4273 end
4274 if "error" == _val_0 and content ~= nil then
4275 _match_1 = true
4276 print("failed", content)
4277 end
4278 end
4279 if not _match_1 then
4280 print("invalid")
4281 end
4282end
4283local _exp_0 = tb
4284local _type_0 = type(_exp_0)
4285local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4286if _tab_0 then
4287 local fourth = _exp_0[4]
4288 local _val_0
4289 do
4290 local _obj_0 = _exp_0[1]
4291 if _obj_0 ~= nil then
4292 _val_0 = _obj_0.a
4293 end
4294 end
4295 local _val_1
4296 do
4297 local _obj_0 = _exp_0[1]
4298 if _obj_0 ~= nil then
4299 _val_1 = _obj_0.b
4300 end
4301 end
4302 local _val_2
4303 do
4304 local _obj_0 = _exp_0[2]
4305 if _obj_0 ~= nil then
4306 _val_2 = _obj_0.a
4307 end
4308 end
4309 local _val_3
4310 do
4311 local _obj_0 = _exp_0[2]
4312 if _obj_0 ~= nil then
4313 _val_3 = _obj_0.b
4314 end
4315 end
4316 local _val_4
4317 do
4318 local _obj_0 = _exp_0[3]
4319 if _obj_0 ~= nil then
4320 _val_4 = _obj_0.a
4321 end
4322 end
4323 local _val_5
4324 do
4325 local _obj_0 = _exp_0[3]
4326 if _obj_0 ~= nil then
4327 _val_5 = _obj_0.b
4328 end
4329 end
4330 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
4331 print("matched", fourth)
4332 end
4333end
4334local segments = {
4335 "admin",
4336 "users",
4337 "logs",
4338 "view"
4339}
4340local _type_0 = type(segments)
4341local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4342if _tab_0 then
4343 local groups
4344 do
4345 local _accum_0 = { }
4346 local _len_0 = 1
4347 local _max_0 = #segments + -3 + 1
4348 for _index_0 = 1, _max_0 do
4349 local _item_0 = segments[_index_0]
4350 _accum_0[_len_0] = _item_0
4351 _len_0 = _len_0 + 1
4352 end
4353 groups = _accum_0
4354 end
4355 local resource = segments[#segments - 1]
4356 local action = segments[#segments]
4357 if resource ~= nil and action ~= nil then
4358 print("Group:", groups)
4359 print("Resource:", resource)
4360 print("Action:", action)
4361 end
4362end
3289local Inventory 4363local Inventory
3290local _class_0 4364local _class_0
3291local _base_0 = { 4365local _base_0 = {
@@ -3942,6 +5016,10 @@ do
3942 _with_1["key-name"] = value 5016 _with_1["key-name"] = value
3943end 5017end
3944_with_0[#_with_0 + 1] = "abc" 5018_with_0[#_with_0 + 1] = "abc"
5019local _with_0 = obj
5020if _with_0 ~= nil then
5021 print(obj.name)
5022end
3945do 5023do
3946 local var = "hello" 5024 local var = "hello"
3947 print(var) 5025 print(var)
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index acd41a0..89335c9 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -20,6 +20,38 @@ local inventory = {
20 } 20 }
21 } 21 }
22} 22}
23local map
24map = function(arr, action)
25 local _accum_0 = { }
26 local _len_0 = 1
27 for _index_0 = 1, #arr do
28 local item = arr[_index_0]
29 _accum_0[_len_0] = action(item)
30 _len_0 = _len_0 + 1
31 end
32 return _accum_0
33end
34local filter
35filter = function(arr, cond)
36 local _accum_0 = { }
37 local _len_0 = 1
38 for _index_0 = 1, #arr do
39 local item = arr[_index_0]
40 if cond(item) then
41 _accum_0[_len_0] = item
42 _len_0 = _len_0 + 1
43 end
44 end
45 return _accum_0
46end
47local reduce
48reduce = function(arr, init, action)
49 for _index_0 = 1, #arr do
50 local item = arr[_index_0]
51 init = action(init, item)
52 end
53 return init
54end
23print(reduce(filter(map({ 55print(reduce(filter(map({
24 1, 56 1,
25 2, 57 2,
@@ -41,8 +73,8 @@ local apple = setmetatable({
41if (getmetatable(apple) ~= nil) then 73if (getmetatable(apple) ~= nil) then
42 p(apple.size, apple.color, getmetatable(apple).__index) 74 p(apple.size, apple.color, getmetatable(apple).__index)
43end 75end
44local _ud83c_udf1b = "月之脚本" 76local _u1f31b = "月之脚本"
45_module_0["🌛"] = _ud83c_udf1b 77_module_0["🌛"] = _u1f31b
46return _module_0 78return _module_0
47local area = 6.2831853071796 * 5 79local area = 6.2831853071796 * 5
48print('你好 世界') 80print('你好 世界')
@@ -77,6 +109,12 @@ end
77print("yuescript") 109print("yuescript")
78print(3) 110print(3)
79print("有效的枚举类型:", "Static") 111print("有效的枚举类型:", "Static")
112do
113 print(123, "hello")
114end
115do
116 print(123, "hello")
117end
80if tb ~= nil then 118if tb ~= nil then
81 tb:func() 119 tb:func()
82end 120end
@@ -109,6 +147,21 @@ print((function()
109end)()) 147end)())
110local tab = { } 148local tab = { }
111tab[#tab + 1] = "Value" 149tab[#tab + 1] = "Value"
150local tbA = {
151 1,
152 2,
153 3
154}
155local tbB = {
156 4,
157 5,
158 6
159}
160local _len_0 = #tbA + 1
161for _index_0 = 1, #tbB do
162 local _elm_0 = tbB[_index_0]
163 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
164end
112local parts = { 165local parts = {
113 "shoulders", 166 "shoulders",
114 "knees" 167 "knees"
@@ -177,6 +230,18 @@ for _key_0, _value_0 in pairs(b) do
177 end 230 end
178end 231end
179merge = _tab_0 232merge = _tab_0
233local last
234do
235 local _item_0 = data.items
236 last = _item_0[#_item_0]
237end
238local second_last
239do
240 local _item_0 = data.items
241 second_last = _item_0[#_item_0 - 1]
242end
243local _obj_0 = data.items
244_obj_0[#_obj_0] = 1
180local mt = { } 245local mt = { }
181local add 246local add
182add = function(self, right) 247add = function(self, right)
@@ -307,6 +372,14 @@ func({
307 2, 372 2,
308 3 373 3
309}) 374})
375local f
376f = function()
377 return {
378 1,
379 2,
380 3
381 }
382end
310local tb = { 383local tb = {
311 name = "abc", 384 name = "abc",
312 values = { 385 values = {
@@ -368,6 +441,25 @@ do
368 local _obj_0 = require("export") 441 local _obj_0 = require("export")
369 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 442 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
370end 443end
444do
445 local tostring <const> = tostring
446 local concat <const> = table.concat
447 print(concat({
448 "a",
449 tostring(1)
450 }))
451end
452do
453 local print <const> = print
454 local math <const> = math
455 print("hello")
456 math.random(3)
457end
458do
459 local print <const> = print
460 print(FLAG)
461 FLAG = 123
462end
371local _module_0 = { } 463local _module_0 = { }
372local a, b, c = 1, 2, 3 464local a, b, c = 1, 2, 3
373_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 465_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -547,6 +639,59 @@ end
547local two, four 639local two, four
548local _obj_0 = items 640local _obj_0 = items
549two, four = _obj_0[2], _obj_0[4] 641two, four = _obj_0[2], _obj_0[4]
642local orders = {
643 "first",
644 "second",
645 "third",
646 "fourth",
647 "last"
648}
649local first, bulk, last = orders[1], (function()
650 local _accum_0 = { }
651 local _len_0 = 1
652 local _max_0 = #orders + -2 + 1
653 for _index_0 = 2, _max_0 do
654 local _item_0 = orders[_index_0]
655 _accum_0[_len_0] = _item_0
656 _len_0 = _len_0 + 1
657 end
658 return _accum_0
659end)(), orders[#orders]
660print(first)
661print(bulk)
662print(last)
663local first, rest
664do
665 local _obj_0 = orders
666 first, rest = _obj_0[1], (function()
667 local _accum_0 = { }
668 local _len_0 = 1
669 local _max_0 = #_obj_0
670 for _index_0 = 2, _max_0 do
671 local _item_0 = _obj_0[_index_0]
672 _accum_0[_len_0] = _item_0
673 _len_0 = _len_0 + 1
674 end
675 return _accum_0
676 end)()
677end
678local start, last
679do
680 local _obj_0 = orders
681 start, last = (function()
682 local _accum_0 = { }
683 local _len_0 = 1
684 local _max_0 = #_obj_0 + -2 + 1
685 for _index_0 = 1, _max_0 do
686 local _item_0 = _obj_0[_index_0]
687 _accum_0[_len_0] = _item_0
688 _len_0 = _len_0 + 1
689 end
690 return _accum_0
691 end)(), _obj_0[#_obj_0]
692end
693local _obj_0 = orders
694first, last = _obj_0[1], _obj_0[#_obj_0]
550local tuples = { 695local tuples = {
551 { 696 {
552 "hello", 697 "hello",
@@ -611,6 +756,9 @@ end
611 local first = select(1, ...) 756 local first = select(1, ...)
612 return print(ok, count, first) 757 return print(ok, count, first)
613end)(fn(true)) 758end)(fn(true))
759local a = 1
760local b = 2
761print(a + b)
614Rx.Observable.fromRange(1, 8):filter(function(x) 762Rx.Observable.fromRange(1, 8):filter(function(x)
615 return x % 2 == 0 763 return x % 2 == 0
616end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 764end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -648,6 +796,56 @@ end)
648if success then 796if success then
649 print(result) 797 print(result)
650end 798end
799local a, b, c
800do
801 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
802 return func()
803 end)
804 if _ok_0 then
805 a, b, c = _ret_0, _ret_1, _ret_2
806 end
807end
808do
809 local _exp_0 = ((function()
810 return (function(_arg_0, ...)
811 local _ok_0 = _arg_0
812 if _ok_0 then
813 return ...
814 end
815 end)(pcall(function()
816 return func()
817 end))
818 end)())
819 if _exp_0 ~= nil then
820 a = _exp_0
821 else
822 a = "default"
823 end
824end
825f((function()
826 return (function(_arg_0, ...)
827 local _ok_0 = _arg_0
828 if _ok_0 then
829 return ...
830 end
831 end)(pcall(function()
832 return func()
833 end))
834end)())
835f((function()
836 return (function(_arg_0, ...)
837 local _ok_0 = _arg_0
838 if _ok_0 then
839 return ...
840 end
841 end)(xpcall(function()
842 print(123)
843 return func()
844 end, function(e)
845 print(e)
846 return e
847 end))
848end)())
651local a <const> = 123 849local a <const> = 123
652local _ <close> = setmetatable({ }, { 850local _ <close> = setmetatable({ }, {
653 __close = function() 851 __close = function()
@@ -657,10 +855,19 @@ local _ <close> = setmetatable({ }, {
657local a, b, c, d 855local a, b, c, d
658local _obj_0 = tb 856local _obj_0 = tb
659a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 857a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
858Constant = 123
660local some_string = "这是一个字符串\n 并包括一个换行。" 859local some_string = "这是一个字符串\n 并包括一个换行。"
661print("我有" .. tostring(math.random() * 100) .. "%的把握。") 860print("我有" .. tostring(math.random() * 100) .. "%的把握。")
662local integer = 1000000 861local integer = 1000000
663local hex = 0xEFBBBF 862local hex = 0xEFBBBF
863local binary = 19
864local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
865local fn
866fn = function()
867 local str = "foo:\n bar: baz"
868 return str
869end
870local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
664local my_function 871local my_function
665my_function = function() end 872my_function = function() end
666my_function() 873my_function()
@@ -749,6 +956,66 @@ if func(1, 2, 3, "你好", "世界") then
749 print("hello") 956 print("hello")
750 print("我在if内部") 957 print("我在if内部")
751end 958end
959local f1
960f1 = function(_arg_0)
961 local a, b, c
962 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
963 return print(a, b, c)
964end
965f1({
966 a = 1,
967 b = "2",
968 c = { }
969})
970local f2
971f2 = function(_arg_0, c)
972 local a1, b
973 a1, b = _arg_0.a, _arg_0.b
974 if a1 == nil then
975 a1 = 123
976 end
977 if b == nil then
978 b = 'abc'
979 end
980 if c == nil then
981 c = { }
982 end
983 return print(a1, b, c)
984end
985local arg1 = {
986 a = 0
987}
988f2(arg1, arg2)
989local f
990f = function(...)
991 local t = {
992 n = select("#", ...),
993 ...
994 }
995 print("参数个数:", t.n)
996 print("表长度:", #t)
997 for i = 1, t.n do
998 print(t[i])
999 end
1000end
1001f(1, 2, 3)
1002f("a", "b", "c", "d")
1003f()
1004local process
1005process = function(...)
1006 local args = {
1007 n = select("#", ...),
1008 ...
1009 }
1010 local sum = 0
1011 for i = 1, args.n do
1012 if args[i] ~= nil and type(args[i]) == "number" then
1013 sum = sum + args[i]
1014 end
1015 end
1016 return sum
1017end
1018process(1, nil, 3, nil, 5)
752f(function() 1019f(function()
753 return print("hello") 1020 return print("hello")
754end) 1021end)
@@ -874,6 +1141,28 @@ for _index_0 = 1, #_list_0 do
874 _len_0 = _len_0 + 1 1141 _len_0 = _len_0 + 1
875end 1142end
876doubled = _accum_0 1143doubled = _accum_0
1144local data = {
1145 a = {
1146 1,
1147 2,
1148 3
1149 },
1150 b = {
1151 4,
1152 5,
1153 6
1154 }
1155}
1156local flat
1157local _accum_0 = { }
1158for k, v in pairs(data) do
1159 local _len_0 = #_accum_0 + 1
1160 for _index_0 = 1, #v do
1161 local _elm_0 = v[_index_0]
1162 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
1163 end
1164end
1165flat = _accum_0
877local x_coords = { 1166local x_coords = {
878 4, 1167 4,
879 5, 1168 5,
@@ -964,8 +1253,18 @@ local slice
964local _accum_0 = { } 1253local _accum_0 = { }
965local _len_0 = 1 1254local _len_0 = 1
966local _list_0 = items 1255local _list_0 = items
967local _max_0 = 5 1256for _index_0 = 1, 5 do
968for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do 1257 local item = _list_0[_index_0]
1258 _accum_0[_len_0] = item
1259 _len_0 = _len_0 + 1
1260end
1261slice = _accum_0
1262local slice
1263local _accum_0 = { }
1264local _len_0 = 1
1265local _list_0 = items
1266local _max_0 = #_list_0
1267for _index_0 = 2, _max_0 do
969 local item = _list_0[_index_0] 1268 local item = _list_0[_index_0]
970 _accum_0[_len_0] = item 1269 _accum_0[_len_0] = item
971 _len_0 = _len_0 + 1 1270 _len_0 = _len_0 + 1
@@ -975,7 +1274,8 @@ local slice
975local _accum_0 = { } 1274local _accum_0 = { }
976local _len_0 = 1 1275local _len_0 = 1
977local _list_0 = items 1276local _list_0 = items
978for _index_0 = 2, #_list_0 do 1277local _max_0 = #_list_0
1278for _index_0 = 1, _max_0, 2 do
979 local item = _list_0[_index_0] 1279 local item = _list_0[_index_0]
980 _accum_0[_len_0] = item 1280 _accum_0[_len_0] = item
981 _len_0 = _len_0 + 1 1281 _len_0 = _len_0 + 1
@@ -985,12 +1285,35 @@ local slice
985local _accum_0 = { } 1285local _accum_0 = { }
986local _len_0 = 1 1286local _len_0 = 1
987local _list_0 = items 1287local _list_0 = items
988for _index_0 = 1, #_list_0, 2 do 1288local _min_0 = #_list_0 + -4 + 1
1289local _max_0 = #_list_0 + -1 + 1
1290for _index_0 = _min_0, _max_0 do
989 local item = _list_0[_index_0] 1291 local item = _list_0[_index_0]
990 _accum_0[_len_0] = item 1292 _accum_0[_len_0] = item
991 _len_0 = _len_0 + 1 1293 _len_0 = _len_0 + 1
992end 1294end
993slice = _accum_0 1295slice = _accum_0
1296local reverse_slice
1297local _accum_0 = { }
1298local _len_0 = 1
1299local _list_0 = items
1300local _min_0 = #_list_0 + -1 + 1
1301for _index_0 = _min_0, 1, -1 do
1302 local item = _list_0[_index_0]
1303 _accum_0[_len_0] = item
1304 _len_0 = _len_0 + 1
1305end
1306reverse_slice = _accum_0
1307local sub_list
1308local _accum_0 = { }
1309local _len_0 = 1
1310local _list_0 = items
1311for _index_0 = 2, 4 do
1312 local _item_0 = _list_0[_index_0]
1313 _accum_0[_len_0] = _item_0
1314 _len_0 = _len_0 + 1
1315end
1316sub_list = _accum_0
994for i = 10, 20 do 1317for i = 10, 20 do
995 print(i) 1318 print(i)
996end 1319end
@@ -1001,8 +1324,7 @@ for key, value in pairs(object) do
1001 print(key, value) 1324 print(key, value)
1002end 1325end
1003local _list_0 = items 1326local _list_0 = items
1004local _max_0 = 4 1327for _index_0 = 2, 4 do
1005for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
1006 local item = _list_0[_index_0] 1328 local item = _list_0[_index_0]
1007 print(item) 1329 print(item)
1008end 1330end
@@ -1020,12 +1342,24 @@ local _len_0 = 1
1020for i = 1, 20 do 1342for i = 1, 20 do
1021 if i % 2 == 0 then 1343 if i % 2 == 0 then
1022 _accum_0[_len_0] = i * 2 1344 _accum_0[_len_0] = i * 2
1345 _len_0 = _len_0 + 1
1023 else 1346 else
1024 _accum_0[_len_0] = i 1347 _accum_0[_len_0] = i
1348 _len_0 = _len_0 + 1
1025 end 1349 end
1026 _len_0 = _len_0 + 1
1027end 1350end
1028doubled_evens = _accum_0 1351doubled_evens = _accum_0
1352local first_large
1353local _accum_0
1354local _list_0 = numbers
1355for _index_0 = 1, #_list_0 do
1356 local n = _list_0[_index_0]
1357 if n > 10 then
1358 _accum_0 = n
1359 break
1360 end
1361end
1362first_large = _accum_0
1029local func_a 1363local func_a
1030func_a = function() 1364func_a = function()
1031 for i = 1, 10 do 1365 for i = 1, 10 do
@@ -1174,7 +1508,7 @@ if "Robert" == name then
1174elseif "Dan" == name or "Daniel" == name then 1508elseif "Dan" == name or "Daniel" == name then
1175 print("你的名字是Dan") 1509 print("你的名字是Dan")
1176else 1510else
1177 print("我不知道你的名字") 1511 print("我不认识,你的名字" .. tostring(name))
1178end 1512end
1179local b = 1 1513local b = 1
1180local next_number 1514local next_number
@@ -1274,6 +1608,192 @@ if _tab_0 then
1274 end 1608 end
1275 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 1609 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
1276end 1610end
1611local _exp_0 = tb
1612local _type_0 = type(_exp_0)
1613local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1614local _match_0 = false
1615if _tab_0 then
1616 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
1617 _match_0 = true
1618 print("1, 2, 3")
1619 end
1620end
1621if not _match_0 then
1622 local _match_1 = false
1623 if _tab_0 then
1624 local b = _exp_0[2]
1625 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
1626 _match_1 = true
1627 print("1, " .. tostring(b) .. ", 3")
1628 end
1629 end
1630 if not _match_1 then
1631 if _tab_0 then
1632 local b = _exp_0[3]
1633 if b == nil then
1634 b = 3
1635 end
1636 if 1 == _exp_0[1] and 2 == _exp_0[2] then
1637 print("1, 2, " .. tostring(b))
1638 end
1639 end
1640 end
1641end
1642local _exp_0 = tb
1643local _type_0 = type(_exp_0)
1644local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1645local _match_0 = false
1646if _tab_0 then
1647 local result = _exp_0.result
1648 if true == _exp_0.success and result ~= nil then
1649 _match_0 = true
1650 print("成功", result)
1651 end
1652end
1653if not _match_0 then
1654 local _match_1 = false
1655 if _tab_0 then
1656 if false == _exp_0.success then
1657 _match_1 = true
1658 print("失败", result)
1659 end
1660 end
1661 if not _match_1 then
1662 print("无效值")
1663 end
1664end
1665local _exp_0 = tb
1666local _type_0 = type(_exp_0)
1667local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1668local _match_0 = false
1669if _tab_0 then
1670 local content
1671 do
1672 local _obj_0 = _exp_0.data
1673 local _type_1 = type(_obj_0)
1674 if "table" == _type_1 or "userdata" == _type_1 then
1675 content = _obj_0.content
1676 end
1677 end
1678 local _val_0
1679 do
1680 local _obj_0 = _exp_0.data
1681 if _obj_0 ~= nil then
1682 _val_0 = _obj_0.type
1683 end
1684 end
1685 if "success" == _val_0 and content ~= nil then
1686 _match_0 = true
1687 print("成功", content)
1688 end
1689end
1690if not _match_0 then
1691 local _match_1 = false
1692 if _tab_0 then
1693 local content
1694 do
1695 local _obj_0 = _exp_0.data
1696 local _type_1 = type(_obj_0)
1697 if "table" == _type_1 or "userdata" == _type_1 then
1698 content = _obj_0.content
1699 end
1700 end
1701 local _val_0
1702 do
1703 local _obj_0 = _exp_0.data
1704 if _obj_0 ~= nil then
1705 _val_0 = _obj_0.type
1706 end
1707 end
1708 if "error" == _val_0 and content ~= nil then
1709 _match_1 = true
1710 print("失败", content)
1711 end
1712 end
1713 if not _match_1 then
1714 print("无效值")
1715 end
1716end
1717local _exp_0 = tb
1718local _type_0 = type(_exp_0)
1719local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1720if _tab_0 then
1721 local fourth = _exp_0[4]
1722 local _val_0
1723 do
1724 local _obj_0 = _exp_0[1]
1725 if _obj_0 ~= nil then
1726 _val_0 = _obj_0.a
1727 end
1728 end
1729 local _val_1
1730 do
1731 local _obj_0 = _exp_0[1]
1732 if _obj_0 ~= nil then
1733 _val_1 = _obj_0.b
1734 end
1735 end
1736 local _val_2
1737 do
1738 local _obj_0 = _exp_0[2]
1739 if _obj_0 ~= nil then
1740 _val_2 = _obj_0.a
1741 end
1742 end
1743 local _val_3
1744 do
1745 local _obj_0 = _exp_0[2]
1746 if _obj_0 ~= nil then
1747 _val_3 = _obj_0.b
1748 end
1749 end
1750 local _val_4
1751 do
1752 local _obj_0 = _exp_0[3]
1753 if _obj_0 ~= nil then
1754 _val_4 = _obj_0.a
1755 end
1756 end
1757 local _val_5
1758 do
1759 local _obj_0 = _exp_0[3]
1760 if _obj_0 ~= nil then
1761 _val_5 = _obj_0.b
1762 end
1763 end
1764 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
1765 print("匹配成功", fourth)
1766 end
1767end
1768local segments = {
1769 "admin",
1770 "users",
1771 "logs",
1772 "view"
1773}
1774local _type_0 = type(segments)
1775local _tab_0 = "table" == _type_0 or "userdata" == _type_0
1776if _tab_0 then
1777 local groups
1778 do
1779 local _accum_0 = { }
1780 local _len_0 = 1
1781 local _max_0 = #segments + -3 + 1
1782 for _index_0 = 1, _max_0 do
1783 local _item_0 = segments[_index_0]
1784 _accum_0[_len_0] = _item_0
1785 _len_0 = _len_0 + 1
1786 end
1787 groups = _accum_0
1788 end
1789 local resource = segments[#segments - 1]
1790 local action = segments[#segments]
1791 if resource ~= nil and action ~= nil then
1792 print("Group:", groups)
1793 print("Resource:", resource)
1794 print("Action:", action)
1795 end
1796end
1277local Inventory 1797local Inventory
1278local _class_0 1798local _class_0
1279local _base_0 = { 1799local _base_0 = {
@@ -1930,6 +2450,10 @@ do
1930 _with_1["key-name"] = value 2450 _with_1["key-name"] = value
1931end 2451end
1932_with_0[#_with_0 + 1] = "abc" 2452_with_0[#_with_0 + 1] = "abc"
2453local _with_0 = obj
2454if _with_0 ~= nil then
2455 print(obj.name)
2456end
1933do 2457do
1934 local var = "hello" 2458 local var = "hello"
1935 print(var) 2459 print(var)
@@ -2020,6 +2544,38 @@ local inventory = {
2020 } 2544 }
2021 } 2545 }
2022} 2546}
2547local map
2548map = function(arr, action)
2549 local _accum_0 = { }
2550 local _len_0 = 1
2551 for _index_0 = 1, #arr do
2552 local item = arr[_index_0]
2553 _accum_0[_len_0] = action(item)
2554 _len_0 = _len_0 + 1
2555 end
2556 return _accum_0
2557end
2558local filter
2559filter = function(arr, cond)
2560 local _accum_0 = { }
2561 local _len_0 = 1
2562 for _index_0 = 1, #arr do
2563 local item = arr[_index_0]
2564 if cond(item) then
2565 _accum_0[_len_0] = item
2566 _len_0 = _len_0 + 1
2567 end
2568 end
2569 return _accum_0
2570end
2571local reduce
2572reduce = function(arr, init, action)
2573 for _index_0 = 1, #arr do
2574 local item = arr[_index_0]
2575 init = action(init, item)
2576 end
2577 return init
2578end
2023print(reduce(filter(map({ 2579print(reduce(filter(map({
2024 1, 2580 1,
2025 2, 2581 2,
@@ -2041,8 +2597,8 @@ local apple = setmetatable({
2041if (getmetatable(apple) ~= nil) then 2597if (getmetatable(apple) ~= nil) then
2042 p(apple.size, apple.color, getmetatable(apple).__index) 2598 p(apple.size, apple.color, getmetatable(apple).__index)
2043end 2599end
2044local _ud83c_udf1b = "月之脚本" 2600local _u1f31b = "月之脚本"
2045_module_0["🌛"] = _ud83c_udf1b 2601_module_0["🌛"] = _u1f31b
2046return _module_0 2602return _module_0
2047local area = 6.2831853071796 * 5 2603local area = 6.2831853071796 * 5
2048print('你好 世界') 2604print('你好 世界')
@@ -2077,6 +2633,12 @@ end
2077print("yuescript") 2633print("yuescript")
2078print(3) 2634print(3)
2079print("有效的枚举类型:", "Static") 2635print("有效的枚举类型:", "Static")
2636do
2637 print(123, "hello")
2638end
2639do
2640 print(123, "hello")
2641end
2080if tb ~= nil then 2642if tb ~= nil then
2081 tb:func() 2643 tb:func()
2082end 2644end
@@ -2109,6 +2671,21 @@ print((function()
2109end)()) 2671end)())
2110local tab = { } 2672local tab = { }
2111tab[#tab + 1] = "Value" 2673tab[#tab + 1] = "Value"
2674local tbA = {
2675 1,
2676 2,
2677 3
2678}
2679local tbB = {
2680 4,
2681 5,
2682 6
2683}
2684local _len_0 = #tbA + 1
2685for _index_0 = 1, #tbB do
2686 local _elm_0 = tbB[_index_0]
2687 tbA[_len_0], _len_0 = _elm_0, _len_0 + 1
2688end
2112local parts = { 2689local parts = {
2113 "shoulders", 2690 "shoulders",
2114 "knees" 2691 "knees"
@@ -2177,6 +2754,18 @@ for _key_0, _value_0 in pairs(b) do
2177 end 2754 end
2178end 2755end
2179merge = _tab_0 2756merge = _tab_0
2757local last
2758do
2759 local _item_0 = data.items
2760 last = _item_0[#_item_0]
2761end
2762local second_last
2763do
2764 local _item_0 = data.items
2765 second_last = _item_0[#_item_0 - 1]
2766end
2767local _obj_0 = data.items
2768_obj_0[#_obj_0] = 1
2180local mt = { } 2769local mt = { }
2181local add 2770local add
2182add = function(self, right) 2771add = function(self, right)
@@ -2307,6 +2896,14 @@ func({
2307 2, 2896 2,
2308 3 2897 3
2309}) 2898})
2899local f
2900f = function()
2901 return {
2902 1,
2903 2,
2904 3
2905 }
2906end
2310local tb = { 2907local tb = {
2311 name = "abc", 2908 name = "abc",
2312 values = { 2909 values = {
@@ -2368,6 +2965,25 @@ do
2368 local _obj_0 = require("export") 2965 local _obj_0 = require("export")
2369 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 2966 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
2370end 2967end
2968do
2969 local tostring <const> = tostring
2970 local concat <const> = table.concat
2971 print(concat({
2972 "a",
2973 tostring(1)
2974 }))
2975end
2976do
2977 local print <const> = print
2978 local math <const> = math
2979 print("hello")
2980 math.random(3)
2981end
2982do
2983 local print <const> = print
2984 print(FLAG)
2985 FLAG = 123
2986end
2371local _module_0 = { } 2987local _module_0 = { }
2372local a, b, c = 1, 2, 3 2988local a, b, c = 1, 2, 3
2373_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 2989_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -2547,6 +3163,59 @@ end
2547local two, four 3163local two, four
2548local _obj_0 = items 3164local _obj_0 = items
2549two, four = _obj_0[2], _obj_0[4] 3165two, four = _obj_0[2], _obj_0[4]
3166local orders = {
3167 "first",
3168 "second",
3169 "third",
3170 "fourth",
3171 "last"
3172}
3173local first, bulk, last = orders[1], (function()
3174 local _accum_0 = { }
3175 local _len_0 = 1
3176 local _max_0 = #orders + -2 + 1
3177 for _index_0 = 2, _max_0 do
3178 local _item_0 = orders[_index_0]
3179 _accum_0[_len_0] = _item_0
3180 _len_0 = _len_0 + 1
3181 end
3182 return _accum_0
3183end)(), orders[#orders]
3184print(first)
3185print(bulk)
3186print(last)
3187local first, rest
3188do
3189 local _obj_0 = orders
3190 first, rest = _obj_0[1], (function()
3191 local _accum_0 = { }
3192 local _len_0 = 1
3193 local _max_0 = #_obj_0
3194 for _index_0 = 2, _max_0 do
3195 local _item_0 = _obj_0[_index_0]
3196 _accum_0[_len_0] = _item_0
3197 _len_0 = _len_0 + 1
3198 end
3199 return _accum_0
3200 end)()
3201end
3202local start, last
3203do
3204 local _obj_0 = orders
3205 start, last = (function()
3206 local _accum_0 = { }
3207 local _len_0 = 1
3208 local _max_0 = #_obj_0 + -2 + 1
3209 for _index_0 = 1, _max_0 do
3210 local _item_0 = _obj_0[_index_0]
3211 _accum_0[_len_0] = _item_0
3212 _len_0 = _len_0 + 1
3213 end
3214 return _accum_0
3215 end)(), _obj_0[#_obj_0]
3216end
3217local _obj_0 = orders
3218first, last = _obj_0[1], _obj_0[#_obj_0]
2550local tuples = { 3219local tuples = {
2551 { 3220 {
2552 "hello", 3221 "hello",
@@ -2611,6 +3280,9 @@ end
2611 local first = select(1, ...) 3280 local first = select(1, ...)
2612 return print(ok, count, first) 3281 return print(ok, count, first)
2613end)(fn(true)) 3282end)(fn(true))
3283local a = 1
3284local b = 2
3285print(a + b)
2614Rx.Observable.fromRange(1, 8):filter(function(x) 3286Rx.Observable.fromRange(1, 8):filter(function(x)
2615 return x % 2 == 0 3287 return x % 2 == 0
2616end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) 3288end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -2648,6 +3320,56 @@ end)
2648if success then 3320if success then
2649 print(result) 3321 print(result)
2650end 3322end
3323local a, b, c
3324do
3325 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
3326 return func()
3327 end)
3328 if _ok_0 then
3329 a, b, c = _ret_0, _ret_1, _ret_2
3330 end
3331end
3332do
3333 local _exp_0 = ((function()
3334 return (function(_arg_0, ...)
3335 local _ok_0 = _arg_0
3336 if _ok_0 then
3337 return ...
3338 end
3339 end)(pcall(function()
3340 return func()
3341 end))
3342 end)())
3343 if _exp_0 ~= nil then
3344 a = _exp_0
3345 else
3346 a = "default"
3347 end
3348end
3349f((function()
3350 return (function(_arg_0, ...)
3351 local _ok_0 = _arg_0
3352 if _ok_0 then
3353 return ...
3354 end
3355 end)(pcall(function()
3356 return func()
3357 end))
3358end)())
3359f((function()
3360 return (function(_arg_0, ...)
3361 local _ok_0 = _arg_0
3362 if _ok_0 then
3363 return ...
3364 end
3365 end)(xpcall(function()
3366 print(123)
3367 return func()
3368 end, function(e)
3369 print(e)
3370 return e
3371 end))
3372end)())
2651local a <const> = 123 3373local a <const> = 123
2652local _ <close> = setmetatable({ }, { 3374local _ <close> = setmetatable({ }, {
2653 __close = function() 3375 __close = function()
@@ -2657,10 +3379,19 @@ local _ <close> = setmetatable({ }, {
2657local a, b, c, d 3379local a, b, c, d
2658local _obj_0 = tb 3380local _obj_0 = tb
2659a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2] 3381a, b, c, d = _obj_0.a, _obj_0.b, _obj_0[1], _obj_0[2]
3382Constant = 123
2660local some_string = "这是一个字符串\n 并包括一个换行。" 3383local some_string = "这是一个字符串\n 并包括一个换行。"
2661print("我有" .. tostring(math.random() * 100) .. "%的把握。") 3384print("我有" .. tostring(math.random() * 100) .. "%的把握。")
2662local integer = 1000000 3385local integer = 1000000
2663local hex = 0xEFBBBF 3386local hex = 0xEFBBBF
3387local binary = 19
3388local str = "key: value\nlist:\n - item1\n - " .. tostring(expr)
3389local fn
3390fn = function()
3391 local str = "foo:\n bar: baz"
3392 return str
3393end
3394local str = "path: \"C:\\Program Files\\App\"\nnote: 'He said: \"" .. tostring(Hello) .. "!\"'"
2664local my_function 3395local my_function
2665my_function = function() end 3396my_function = function() end
2666my_function() 3397my_function()
@@ -2749,6 +3480,96 @@ if func(1, 2, 3, "你好", "世界") then
2749 print("你好") 3480 print("你好")
2750 print("我在if内部") 3481 print("我在if内部")
2751end 3482end
3483local f1
3484f1 = function(_arg_0)
3485 local a, b, c
3486 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
3487 return print(a, b, c)
3488end
3489f1({
3490 a = 1,
3491 b = "2",
3492 c = { }
3493})
3494local f2
3495f2 = function(_arg_0, c)
3496 local a1, b
3497 a1, b = _arg_0.a, _arg_0.b
3498 if a1 == nil then
3499 a1 = 123
3500 end
3501 if b == nil then
3502 b = 'abc'
3503 end
3504 if c == nil then
3505 c = { }
3506 end
3507 return print(a1, b, c)
3508end
3509local arg1 = {
3510 a = 0
3511}
3512f2(arg1, arg2)
3513local findFirstEven
3514findFirstEven = function(list)
3515 for _index_0 = 1, #list do
3516 local item = list[_index_0]
3517 if type(item) == "table" then
3518 for _index_1 = 1, #item do
3519 local sub = item[_index_1]
3520 if sub % 2 == 0 then
3521 return sub
3522 end
3523 end
3524 end
3525 end
3526 return nil
3527end
3528local findFirstEven
3529findFirstEven = function(list)
3530 for _index_0 = 1, #list do
3531 local item = list[_index_0]
3532 if type(item) == "table" then
3533 for _index_1 = 1, #item do
3534 local sub = item[_index_1]
3535 if sub % 2 == 0 then
3536 return sub
3537 end
3538 end
3539 end
3540 end
3541 return nil
3542end
3543local f
3544f = function(...)
3545 local t = {
3546 n = select("#", ...),
3547 ...
3548 }
3549 print("参数个数:", t.n)
3550 print("表长度:", #t)
3551 for i = 1, t.n do
3552 print(t[i])
3553 end
3554end
3555f(1, 2, 3)
3556f("a", "b", "c", "d")
3557f()
3558local process
3559process = function(...)
3560 local args = {
3561 n = select("#", ...),
3562 ...
3563 }
3564 local sum = 0
3565 for i = 1, args.n do
3566 if args[i] ~= nil and type(args[i]) == "number" then
3567 sum = sum + args[i]
3568 end
3569 end
3570 return sum
3571end
3572process(1, nil, 3, nil, 5)
2752f(function() 3573f(function()
2753 return print("hello") 3574 return print("hello")
2754end) 3575end)
@@ -2874,6 +3695,28 @@ for _index_0 = 1, #_list_0 do
2874 _len_0 = _len_0 + 1 3695 _len_0 = _len_0 + 1
2875end 3696end
2876doubled = _accum_0 3697doubled = _accum_0
3698local data = {
3699 a = {
3700 1,
3701 2,
3702 3
3703 },
3704 b = {
3705 4,
3706 5,
3707 6
3708 }
3709}
3710local flat
3711local _accum_0 = { }
3712for k, v in pairs(data) do
3713 local _len_0 = #_accum_0 + 1
3714 for _index_0 = 1, #v do
3715 local _elm_0 = v[_index_0]
3716 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
3717 end
3718end
3719flat = _accum_0
2877local x_coords = { 3720local x_coords = {
2878 4, 3721 4,
2879 5, 3722 5,
@@ -2964,8 +3807,7 @@ local slice
2964local _accum_0 = { } 3807local _accum_0 = { }
2965local _len_0 = 1 3808local _len_0 = 1
2966local _list_0 = items 3809local _list_0 = items
2967local _max_0 = 5 3810for _index_0 = 1, 5 do
2968for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
2969 local item = _list_0[_index_0] 3811 local item = _list_0[_index_0]
2970 _accum_0[_len_0] = item 3812 _accum_0[_len_0] = item
2971 _len_0 = _len_0 + 1 3813 _len_0 = _len_0 + 1
@@ -2975,7 +3817,8 @@ local slice
2975local _accum_0 = { } 3817local _accum_0 = { }
2976local _len_0 = 1 3818local _len_0 = 1
2977local _list_0 = items 3819local _list_0 = items
2978for _index_0 = 2, #_list_0 do 3820local _max_0 = #_list_0
3821for _index_0 = 2, _max_0 do
2979 local item = _list_0[_index_0] 3822 local item = _list_0[_index_0]
2980 _accum_0[_len_0] = item 3823 _accum_0[_len_0] = item
2981 _len_0 = _len_0 + 1 3824 _len_0 = _len_0 + 1
@@ -2985,12 +3828,46 @@ local slice
2985local _accum_0 = { } 3828local _accum_0 = { }
2986local _len_0 = 1 3829local _len_0 = 1
2987local _list_0 = items 3830local _list_0 = items
2988for _index_0 = 1, #_list_0, 2 do 3831local _max_0 = #_list_0
3832for _index_0 = 1, _max_0, 2 do
2989 local item = _list_0[_index_0] 3833 local item = _list_0[_index_0]
2990 _accum_0[_len_0] = item 3834 _accum_0[_len_0] = item
2991 _len_0 = _len_0 + 1 3835 _len_0 = _len_0 + 1
2992end 3836end
2993slice = _accum_0 3837slice = _accum_0
3838local slice
3839local _accum_0 = { }
3840local _len_0 = 1
3841local _list_0 = items
3842local _min_0 = #_list_0 + -4 + 1
3843local _max_0 = #_list_0 + -1 + 1
3844for _index_0 = _min_0, _max_0 do
3845 local item = _list_0[_index_0]
3846 _accum_0[_len_0] = item
3847 _len_0 = _len_0 + 1
3848end
3849slice = _accum_0
3850local reverse_slice
3851local _accum_0 = { }
3852local _len_0 = 1
3853local _list_0 = items
3854local _min_0 = #_list_0 + -1 + 1
3855for _index_0 = _min_0, 1, -1 do
3856 local item = _list_0[_index_0]
3857 _accum_0[_len_0] = item
3858 _len_0 = _len_0 + 1
3859end
3860reverse_slice = _accum_0
3861local sub_list
3862local _accum_0 = { }
3863local _len_0 = 1
3864local _list_0 = items
3865for _index_0 = 2, 4 do
3866 local _item_0 = _list_0[_index_0]
3867 _accum_0[_len_0] = _item_0
3868 _len_0 = _len_0 + 1
3869end
3870sub_list = _accum_0
2994for i = 10, 20 do 3871for i = 10, 20 do
2995 print(i) 3872 print(i)
2996end 3873end
@@ -3001,8 +3878,7 @@ for key, value in pairs(object) do
3001 print(key, value) 3878 print(key, value)
3002end 3879end
3003local _list_0 = items 3880local _list_0 = items
3004local _max_0 = 4 3881for _index_0 = 2, 4 do
3005for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
3006 local item = _list_0[_index_0] 3882 local item = _list_0[_index_0]
3007 print(item) 3883 print(item)
3008end 3884end
@@ -3020,12 +3896,24 @@ local _len_0 = 1
3020for i = 1, 20 do 3896for i = 1, 20 do
3021 if i % 2 == 0 then 3897 if i % 2 == 0 then
3022 _accum_0[_len_0] = i * 2 3898 _accum_0[_len_0] = i * 2
3899 _len_0 = _len_0 + 1
3023 else 3900 else
3024 _accum_0[_len_0] = i 3901 _accum_0[_len_0] = i
3902 _len_0 = _len_0 + 1
3025 end 3903 end
3026 _len_0 = _len_0 + 1
3027end 3904end
3028doubled_evens = _accum_0 3905doubled_evens = _accum_0
3906local first_large
3907local _accum_0
3908local _list_0 = numbers
3909for _index_0 = 1, #_list_0 do
3910 local n = _list_0[_index_0]
3911 if n > 10 then
3912 _accum_0 = n
3913 break
3914 end
3915end
3916first_large = _accum_0
3029local func_a 3917local func_a
3030func_a = function() 3918func_a = function()
3031 for i = 1, 10 do 3919 for i = 1, 10 do
@@ -3174,7 +4062,7 @@ if "Robert" == name then
3174elseif "Dan" == name or "Daniel" == name then 4062elseif "Dan" == name or "Daniel" == name then
3175 print("你的名字是Dan") 4063 print("你的名字是Dan")
3176else 4064else
3177 print("我不知道你的名字") 4065 print("我不认识,你的名字" .. tostring(name))
3178end 4066end
3179local b = 1 4067local b = 1
3180local next_number 4068local next_number
@@ -3274,6 +4162,192 @@ if _tab_0 then
3274 end 4162 end
3275 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 4163 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
3276end 4164end
4165local _exp_0 = tb
4166local _type_0 = type(_exp_0)
4167local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4168local _match_0 = false
4169if _tab_0 then
4170 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
4171 _match_0 = true
4172 print("1, 2, 3")
4173 end
4174end
4175if not _match_0 then
4176 local _match_1 = false
4177 if _tab_0 then
4178 local b = _exp_0[2]
4179 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
4180 _match_1 = true
4181 print("1, " .. tostring(b) .. ", 3")
4182 end
4183 end
4184 if not _match_1 then
4185 if _tab_0 then
4186 local b = _exp_0[3]
4187 if b == nil then
4188 b = 3
4189 end
4190 if 1 == _exp_0[1] and 2 == _exp_0[2] then
4191 print("1, 2, " .. tostring(b))
4192 end
4193 end
4194 end
4195end
4196local _exp_0 = tb
4197local _type_0 = type(_exp_0)
4198local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4199local _match_0 = false
4200if _tab_0 then
4201 local result = _exp_0.result
4202 if true == _exp_0.success and result ~= nil then
4203 _match_0 = true
4204 print("成功", result)
4205 end
4206end
4207if not _match_0 then
4208 local _match_1 = false
4209 if _tab_0 then
4210 if false == _exp_0.success then
4211 _match_1 = true
4212 print("失败", result)
4213 end
4214 end
4215 if not _match_1 then
4216 print("无效值")
4217 end
4218end
4219local _exp_0 = tb
4220local _type_0 = type(_exp_0)
4221local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4222local _match_0 = false
4223if _tab_0 then
4224 local content
4225 do
4226 local _obj_0 = _exp_0.data
4227 local _type_1 = type(_obj_0)
4228 if "table" == _type_1 or "userdata" == _type_1 then
4229 content = _obj_0.content
4230 end
4231 end
4232 local _val_0
4233 do
4234 local _obj_0 = _exp_0.data
4235 if _obj_0 ~= nil then
4236 _val_0 = _obj_0.type
4237 end
4238 end
4239 if "success" == _val_0 and content ~= nil then
4240 _match_0 = true
4241 print("成功", content)
4242 end
4243end
4244if not _match_0 then
4245 local _match_1 = false
4246 if _tab_0 then
4247 local content
4248 do
4249 local _obj_0 = _exp_0.data
4250 local _type_1 = type(_obj_0)
4251 if "table" == _type_1 or "userdata" == _type_1 then
4252 content = _obj_0.content
4253 end
4254 end
4255 local _val_0
4256 do
4257 local _obj_0 = _exp_0.data
4258 if _obj_0 ~= nil then
4259 _val_0 = _obj_0.type
4260 end
4261 end
4262 if "error" == _val_0 and content ~= nil then
4263 _match_1 = true
4264 print("失败", content)
4265 end
4266 end
4267 if not _match_1 then
4268 print("无效值")
4269 end
4270end
4271local _exp_0 = tb
4272local _type_0 = type(_exp_0)
4273local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4274if _tab_0 then
4275 local fourth = _exp_0[4]
4276 local _val_0
4277 do
4278 local _obj_0 = _exp_0[1]
4279 if _obj_0 ~= nil then
4280 _val_0 = _obj_0.a
4281 end
4282 end
4283 local _val_1
4284 do
4285 local _obj_0 = _exp_0[1]
4286 if _obj_0 ~= nil then
4287 _val_1 = _obj_0.b
4288 end
4289 end
4290 local _val_2
4291 do
4292 local _obj_0 = _exp_0[2]
4293 if _obj_0 ~= nil then
4294 _val_2 = _obj_0.a
4295 end
4296 end
4297 local _val_3
4298 do
4299 local _obj_0 = _exp_0[2]
4300 if _obj_0 ~= nil then
4301 _val_3 = _obj_0.b
4302 end
4303 end
4304 local _val_4
4305 do
4306 local _obj_0 = _exp_0[3]
4307 if _obj_0 ~= nil then
4308 _val_4 = _obj_0.a
4309 end
4310 end
4311 local _val_5
4312 do
4313 local _obj_0 = _exp_0[3]
4314 if _obj_0 ~= nil then
4315 _val_5 = _obj_0.b
4316 end
4317 end
4318 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
4319 print("匹配成功", fourth)
4320 end
4321end
4322local segments = {
4323 "admin",
4324 "users",
4325 "logs",
4326 "view"
4327}
4328local _type_0 = type(segments)
4329local _tab_0 = "table" == _type_0 or "userdata" == _type_0
4330if _tab_0 then
4331 local groups
4332 do
4333 local _accum_0 = { }
4334 local _len_0 = 1
4335 local _max_0 = #segments + -3 + 1
4336 for _index_0 = 1, _max_0 do
4337 local _item_0 = segments[_index_0]
4338 _accum_0[_len_0] = _item_0
4339 _len_0 = _len_0 + 1
4340 end
4341 groups = _accum_0
4342 end
4343 local resource = segments[#segments - 1]
4344 local action = segments[#segments]
4345 if resource ~= nil and action ~= nil then
4346 print("Group:", groups)
4347 print("Resource:", resource)
4348 print("Action:", action)
4349 end
4350end
3277local Inventory 4351local Inventory
3278local _class_0 4352local _class_0
3279local _base_0 = { 4353local _base_0 = {
@@ -3930,6 +5004,10 @@ do
3930 _with_1["key-name"] = value 5004 _with_1["key-name"] = value
3931end 5005end
3932_with_0[#_with_0 + 1] = "abc" 5006_with_0[#_with_0 + 1] = "abc"
5007local _with_0 = obj
5008if _with_0 ~= nil then
5009 print(obj.name)
5010end
3933do 5011do
3934 local var = "hello" 5012 local var = "hello"
3935 print(var) 5013 print(var)
diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua
index 9a7c478..663bd44 100644
--- a/spec/outputs/comprehension.lua
+++ b/spec/outputs/comprehension.lua
@@ -243,8 +243,11 @@ end
243do 243do
244 local _accum_0 = { } 244 local _accum_0 = { }
245 local _len_0 = 1 245 local _len_0 = 1
246 local _min_0 = 1 + 2
246 local _max_0 = 3 + 4 247 local _max_0 = 3 + 4
247 for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do 248 _min_0 = _min_0 < 0 and #items + _min_0 + 1 or _min_0
249 _max_0 = _max_0 < 0 and #items + _max_0 + 1 or _max_0
250 for _index_0 = _min_0, _max_0 do
248 local item = items[_index_0] 251 local item = items[_index_0]
249 _accum_0[_len_0] = item 252 _accum_0[_len_0] = item
250 _len_0 = _len_0 + 1 253 _len_0 = _len_0 + 1
@@ -254,8 +257,11 @@ end
254do 257do
255 local _accum_0 = { } 258 local _accum_0 = { }
256 local _len_0 = 1 259 local _len_0 = 1
260 local _min_0 = hello() * 4
257 local _max_0 = 2 - thing[4] 261 local _max_0 = 2 - thing[4]
258 for _index_0 = hello() * 4, _max_0 < 0 and #items + _max_0 or _max_0 do 262 _min_0 = _min_0 < 0 and #items + _min_0 + 1 or _min_0
263 _max_0 = _max_0 < 0 and #items + _max_0 + 1 or _max_0
264 for _index_0 = _min_0, _max_0 do
259 local item = items[_index_0] 265 local item = items[_index_0]
260 _accum_0[_len_0] = item 266 _accum_0[_len_0] = item
261 _len_0 = _len_0 + 1 267 _len_0 = _len_0 + 1
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua
index 44da58b..4e19aca 100644
--- a/spec/outputs/destructure.lua
+++ b/spec/outputs/destructure.lua
@@ -621,4 +621,114 @@ do
621 print(meta_field, abc, def) 621 print(meta_field, abc, def)
622 end 622 end
623end 623end
624do
625 local clients = {
626 "VIP_Alice",
627 "User_Bob",
628 "User_Clara",
629 "VIP_Eva"
630 }
631 local vipStart, regulars, vipEnd = clients[1], (function()
632 local _accum_0 = { }
633 local _len_0 = 1
634 local _max_0 = #clients + -2 + 1
635 for _index_0 = 2, _max_0 do
636 local _item_0 = clients[_index_0]
637 _accum_0[_len_0] = _item_0
638 _len_0 = _len_0 + 1
639 end
640 return _accum_0
641 end)(), clients[#clients]
642 print(vipStart)
643 print(regulars)
644 print(vipEnd)
645end
646do
647 local setupMeeting
648 setupMeeting = function(participants)
649 local chair, secretary = participants[1], participants[#participants]
650 return print(chair, secretary)
651 end
652 setupMeeting({
653 "Alice",
654 "Bob",
655 "Charlie",
656 "David"
657 })
658end
659do
660 local getTransactions
661 getTransactions = function()
662 return {
663 {
664 id = "T1",
665 amount = 100
666 },
667 {
668 id = "T2",
669 amount = 200
670 },
671 {
672 id = "T3",
673 amount = 300
674 }
675 }
676 end
677 local id, amount
678 do
679 local _item_0 = getTransactions()
680 local _obj_0 = _item_0[#_item_0]
681 id, amount = _obj_0.id, _obj_0.amount
682 end
683 assert(id == "T3")
684 assert(amount == 300)
685end
686do
687 local middle
688 local _accum_0 = { }
689 local _len_0 = 1
690 local _list_0 = tb
691 local _max_0 = #_list_0 + -2 + 1
692 for _index_0 = 2, _max_0 do
693 local _item_0 = _list_0[_index_0]
694 _accum_0[_len_0] = _item_0
695 _len_0 = _len_0 + 1
696 end
697 middle = _accum_0
698end
699do
700 local a, abc, b, def, sub, d, e
701 local _obj_0 = tb
702 a, abc, b, def, sub, d, e = _obj_0[1], _obj_0.abc, _obj_0[2], _obj_0.def, (function()
703 local _accum_0 = { }
704 local _len_0 = 1
705 local _max_0 = #_obj_0 + -3 + 1
706 for _index_0 = 3, _max_0 do
707 local _item_0 = _obj_0[_index_0]
708 _accum_0[_len_0] = _item_0
709 _len_0 = _len_0 + 1
710 end
711 return _accum_0
712 end)(), _obj_0[#_obj_0 - 1], _obj_0[#_obj_0]
713end
714do
715 local _list_0 = items
716 for _index_0 = 1, #_list_0 do
717 local _des_0 = _list_0[_index_0]
718 local a, b = _des_0.a, _des_0.b
719 print(a, b)
720 end
721 local _list_1 = items
722 for _index_0 = 1, #_list_1 do
723 local _des_0 = _list_1[_index_0]
724 local a, b = _des_0.a, _des_0.b
725 print(a, b)
726 end
727 for _des_0 in pairs(data) do
728 local body = _des_0.body
729 if body then
730 print(body)
731 end
732 end
733end
624return nil 734return nil
diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua
index c1735c4..db7ed67 100644
--- a/spec/outputs/funcs.lua
+++ b/spec/outputs/funcs.lua
@@ -283,4 +283,157 @@ do
283 end 283 end
284 print(func()) 284 print(func())
285end 285end
286local _anon_func_0 = function(_arg_0)
287 local _accum_0 = { }
288 local _len_0 = 1
289 local _max_0 = #_arg_0
290 for _index_0 = 1, _max_0 do
291 local _item_0 = _arg_0[_index_0]
292 _accum_0[_len_0] = _item_0
293 _len_0 = _len_0 + 1
294 end
295 return _accum_0
296end
297do
298 local f
299 f = function(_arg_0)
300 local a, b, c
301 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
302 return print(a, b, c)
303 end
304 f = function(_arg_0)
305 local a, b, c
306 a, b, c = _arg_0.a, _arg_0.b, _arg_0.c
307 return print(a, b, c)
308 end
309 local g
310 g = function(x, _arg_0)
311 local y
312 y = _arg_0.y
313 return print(x, y)
314 end
315 local i
316 i = function(_arg_0)
317 local ax, by
318 ax, by = _arg_0.a, _arg_0.b
319 if ax == nil then
320 ax = 0
321 end
322 if by == nil then
323 by = 0
324 end
325 return print(ax, by)
326 end
327 j = function(name, _arg_0)
328 local uid, role
329 uid, role = _arg_0.id, _arg_0.role
330 if uid == nil then
331 uid = "n/a"
332 end
333 if role == nil then
334 role = "guest"
335 end
336 return print(name, uid, role)
337 end
338 local m
339 m = function(_arg_0)
340 local name, age, ver
341 name, age, ver = _arg_0.user.name, _arg_0.user.age, _arg_0.meta.ver
342 if ver == nil then
343 ver = 1
344 end
345 return print(name, age, ver)
346 end
347 local m1
348 m1 = function(_arg_0)
349 local name, age, meta
350 name, age, meta = _arg_0.user.name, _arg_0.user.age, _arg_0.meta
351 if meta == nil then
352 meta = { }
353 end
354 return print(name, age, meta and meta.ver or "nil")
355 end
356 local new
357 new = function(self, _arg_0)
358 local name, age
359 name, age = _arg_0.name, _arg_0.age
360 if name == nil then
361 name = "anon"
362 end
363 if age == nil then
364 age = 0
365 end
366 self.name = name
367 self.age = age
368 end
369 local set
370 set = function(self, _arg_0)
371 local name, age
372 name, age = _arg_0.name, _arg_0.age
373 if name == nil then
374 name = self.name
375 end
376 if age == nil then
377 age = self.age
378 end
379 self.name = name
380 self.age = age
381 end
382 local logKV
383 logKV = function(_arg_0, ...)
384 local k, v
385 k, v = _arg_0.k, _arg_0.v
386 print("kv:", k, v)
387 return print("rest count:", select("#", ...))
388 end
389 do
390 local foo
391 foo = function(_arg_0)
392 local a, b
393 a, b = _arg_0.a, _arg_0.b
394 if b == nil then
395 b = 0
396 end
397 return print(a, b)
398 end
399 end
400 local t1
401 t1 = function(_arg_0, x)
402 local a
403 a = _arg_0.a
404 return print(a, x)
405 end
406 local t2
407 t2 = function(_arg_0)
408 local a
409 a = _arg_0.a
410 return print(a)
411 end
412 local w
413 w = function(id, _arg_0, _arg_1)
414 local x, y
415 x, y = _arg_0.x, _arg_0.y
416 if x == nil then
417 x = 0
418 end
419 if y == nil then
420 y = 0
421 end
422 local flag
423 flag = _arg_1.flag
424 return print(id, x, y, flag)
425 end
426 local g1
427 g1 = function(_arg_0)
428 local a, ax
429 a, ax = _arg_0.a, _arg_0.a
430 return print(a, ax)
431 end
432 local g4
433 g4 = function(_arg_0)
434 local a, b, rest
435 a, b, rest = _arg_0.a, _arg_0.b, _anon_func_0(_arg_0)
436 return print(a, b)
437 end
438end
286return nil 439return nil
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua
index 54a21a9..3918f85 100644
--- a/spec/outputs/global.lua
+++ b/spec/outputs/global.lua
@@ -93,3 +93,28 @@ do
93 FooBar = "pascal case" 93 FooBar = "pascal case"
94 FOOBAR = "all uppercase" 94 FOOBAR = "all uppercase"
95end 95end
96do
97 do
98 local _class_0
99 local _base_0 = { }
100 if _base_0.__index == nil then
101 _base_0.__index = _base_0
102 end
103 _class_0 = setmetatable({
104 __init = function() end,
105 __base = _base_0,
106 __name = "A"
107 }, {
108 __index = _base_0,
109 __call = function(cls, ...)
110 local _self_0 = setmetatable({ }, _base_0)
111 cls.__init(_self_0, ...)
112 return _self_0
113 end
114 })
115 _base_0.__class = _class_0
116 A = _class_0
117 end
118 Flag = 1
119 const, x, y = "const", 1, 2
120end
diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua
index 83c99e2..7aa130f 100644
--- a/spec/outputs/import.lua
+++ b/spec/outputs/import.lua
@@ -166,3 +166,13 @@ do
166 local _obj_1 = require("m") 166 local _obj_1 = require("m")
167 g, i = _obj_1[1], getmetatable(_obj_1[2]).__close 167 g, i = _obj_1[1], getmetatable(_obj_1[2]).__close
168end 168end
169do
170 local require <const> = require
171 local stringlib <const> = string
172 local format <const> = string.format
173 local io_read <const> = io.read
174 local type
175 type = function() end
176 local tp <const> = _G.type
177 local yue <const> = _G["月"]
178end
diff --git a/spec/outputs/import_global.lua b/spec/outputs/import_global.lua
new file mode 100644
index 0000000..895daf9
--- /dev/null
+++ b/spec/outputs/import_global.lua
@@ -0,0 +1,131 @@
1do
2 local print <const> = print
3 local math <const> = math
4 print("hello")
5 math.random(10)
6end
7do
8 local print <const> = print
9 local value = 1
10 value = value + 2
11 print(value)
12end
13do
14 local print
15 print = function(msg)
16 return msg
17 end
18 do
19 local math <const> = math
20 print("local")
21 math.random(1)
22 end
23end
24do
25 local print <const> = print
26 local tostring
27 tostring = function(v)
28 return "local"
29 end
30 tostring("value")
31 print(tostring(123))
32end
33do
34 local func
35 func = function(x, y)
36 local type <const> = type
37 local tostring <const> = tostring
38 local print <const> = print
39 return type(x, tostring(y, print))
40 end
41 func(1, 2)
42end
43do
44 local xpcall <const> = xpcall
45 local func <const> = func
46 local world <const> = world
47 local tostring <const> = tostring
48 local print <const> = print
49 xpcall(function()
50 return func("hello " .. tostring(world))
51 end, function(err)
52 return print(err)
53 end)
54end
55do
56 local print <const> = print
57 print(FLAG)
58 FLAG = 123
59end
60do
61 local print <const> = print
62 Foo = 10
63 print(Foo)
64 Foo = Foo + 2
65end
66do
67 local print <const> = print
68 Bar = 1
69 Baz = 2
70 print(Bar, Baz)
71end
72do
73 local y <const> = y
74 x = 3434
75 if y then
76 x = 10
77 end
78end
79do
80 local lowercase <const> = lowercase
81 local tostring <const> = tostring
82 local Uppercase <const> = Uppercase
83 local foobar = "all " .. tostring(lowercase)
84 FooBar = "pascal case"
85 FOOBAR = "all " .. tostring(Uppercase)
86end
87do
88 local setmetatable <const> = setmetatable
89 local print <const> = print
90 do
91 local _class_0
92 local _base_0 = { }
93 if _base_0.__index == nil then
94 _base_0.__index = _base_0
95 end
96 _class_0 = setmetatable({
97 __init = function() end,
98 __base = _base_0,
99 __name = "A"
100 }, {
101 __index = _base_0,
102 __call = function(cls, ...)
103 local _self_0 = setmetatable({ }, _base_0)
104 cls.__init(_self_0, ...)
105 return _self_0
106 end
107 })
108 _base_0.__class = _class_0
109 A = _class_0
110 end
111 Flag = 1
112 const, x, y = "const", 1, 2
113 print(math, table)
114end
115do
116 local X <const> = X
117 X:func(1, 2, 3)
118 X.tag = "abc"
119end
120local _anon_func_0 = function(func)
121 return func
122end
123do
124 local func <const> = func
125 local pcall <const> = pcall
126 local f
127 f = function()
128 func()
129 return pcall(_anon_func_0, func)
130 end
131end
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua
index 48ec9c8..75f04fa 100644
--- a/spec/outputs/lists.lua
+++ b/spec/outputs/lists.lua
@@ -230,31 +230,36 @@ x = {
230 6, 230 6,
231 7 231 7
232} 232}
233local _max_0 = -5 233local _max_0 = #x + -5 + 1
234for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do 234for _index_0 = 2, _max_0, 2 do
235 local y = x[_index_0] 235 local y = x[_index_0]
236 print(y) 236 print(y)
237end 237end
238local _max_1 = 3 238for _index_0 = 1, 3 do
239for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do
240 local y = x[_index_0] 239 local y = x[_index_0]
241 print(y) 240 print(y)
242end 241end
243for _index_0 = 2, #x do 242local _max_1 = #x
243for _index_0 = 2, _max_1 do
244 local y = x[_index_0] 244 local y = x[_index_0]
245 print(y) 245 print(y)
246end 246end
247for _index_0 = 1, #x, 2 do 247local _max_2 = #x
248for _index_0 = 1, _max_2, 2 do
248 local y = x[_index_0] 249 local y = x[_index_0]
249 print(y) 250 print(y)
250end 251end
251for _index_0 = 2, #x, 2 do 252local _max_3 = #x
253for _index_0 = 2, _max_3, 2 do
252 local y = x[_index_0] 254 local y = x[_index_0]
253 print(y) 255 print(y)
254end 256end
255local a, b, c = 1, 5, 2 257local a, b, c = 1, 5, 2
256local _max_2 = b 258local _min_0 = a
257for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do 259local _max_4 = b
260_min_0 = _min_0 < 0 and #x + _min_0 + 1 or _min_0
261_max_4 = _max_4 < 0 and #x + _max_4 + 1 or _max_4
262for _index_0 = _min_0, _max_4, c do
258 local y = x[_index_0] 263 local y = x[_index_0]
259 print(y) 264 print(y)
260end 265end
@@ -287,7 +292,10 @@ do
287 a 292 a
288 }) 293 })
289 local _list_0 = f 294 local _list_0 = f
290 for _index_0 = a, #_list_0 do 295 local _min_1 = a
296 local _max_5 = #_list_0
297 _min_1 = _min_1 < 0 and #_list_0 + _min_1 + 1 or _min_1
298 for _index_0 = _min_1, _max_5 do
291 local v = _list_0[_index_0] 299 local v = _list_0[_index_0]
292 print(v) 300 print(v)
293 end 301 end
@@ -327,4 +335,570 @@ do
327 job = "jobless" 335 job = "jobless"
328 end 336 end
329end 337end
338do
339 local transactions = {
340 "T001",
341 "T002",
342 "T003",
343 "T004",
344 "T005"
345 }
346 local middleTransactions
347 do
348 local _accum_0 = { }
349 local _len_0 = 1
350 local _max_5 = #transactions + -2 + 1
351 for _index_0 = 2, _max_5 do
352 local _item_0 = transactions[_index_0]
353 _accum_0[_len_0] = _item_0
354 _len_0 = _len_0 + 1
355 end
356 middleTransactions = _accum_0
357 end
358 print(middleTransactions)
359end
360do
361 local logs = {
362 {
363 start = 0,
364 ["end"] = 100
365 },
366 {
367 start = 100,
368 ["end"] = 200
369 },
370 {
371 start = 200,
372 ["end"] = 123
373 }
374 }
375 print(logs[#logs]["end"])
376end
377do
378 local pendingOrders = {
379 "O001",
380 "O002",
381 "O003",
382 "O004"
383 }
384 print(pendingOrders[#pendingOrders - 1])
385end
386do
387 local getOrders
388 getOrders = function()
389 return {
390 {
391 id = "O1001",
392 status = "pending"
393 },
394 {
395 id = "O1002",
396 status = "processing"
397 },
398 {
399 id = "O1003",
400 status = "done"
401 }
402 }
403 end
404 local lastStatus
405 do
406 local _item_0 = getOrders()
407 lastStatus = _item_0[#_item_0].status
408 end
409 assert(lastStatus == "done")
410end
411do
412 local cloneList1
413 cloneList1 = function(list)
414 local _accum_0 = { }
415 local _len_0 = 1
416 local _max_5 = #list
417 for _index_0 = 1, _max_5 do
418 local _item_0 = list[_index_0]
419 _accum_0[_len_0] = _item_0
420 _len_0 = _len_0 + 1
421 end
422 return _accum_0
423 end
424 local cloneList2
425 cloneList2 = function(list)
426 local _tab_0 = { }
427 local _idx_0 = #_tab_0 + 1
428 for _index_0 = 1, #list do
429 local _value_0 = list[_index_0]
430 _tab_0[_idx_0] = _value_0
431 _idx_0 = _idx_0 + 1
432 end
433 return _tab_0
434 end
435 local cloneTable
436 cloneTable = function(tb)
437 local _tab_0 = { }
438 local _idx_0 = 1
439 for _key_0, _value_0 in pairs(tb) do
440 if _idx_0 == _key_0 then
441 _tab_0[#_tab_0 + 1] = _value_0
442 _idx_0 = _idx_0 + 1
443 else
444 _tab_0[_key_0] = _value_0
445 end
446 end
447 return _tab_0
448 end
449end
450do
451 print((function()
452 local _item_0 = globalTB
453 return _item_0[#_item_0]
454 end)(), (function()
455 local _item_0 = a.b.c
456 return _item_0[#_item_0 - 2]
457 end)(), (function()
458 if x ~= nil then
459 local _obj_0 = x.y
460 if _obj_0 ~= nil then
461 local _obj_1 = _obj_0(x).z
462 if _obj_1 ~= nil then
463 return _obj_1[#_obj_1 - 3]
464 end
465 return nil
466 end
467 return nil
468 end
469 return nil
470 end)())
471end
472local _anon_func_0 = function(globalTB)
473 local _call_0
474 do
475 local _item_0 = globalTB
476 _call_0 = _item_0[#_item_0]
477 end
478 return _call_0["end"](_call_0, 123)
479end
480local _anon_func_1 = function(a)
481 local _item_0
482 do
483 local _accum_0 = { }
484 local _len_0 = 1
485 local _list_0 = a.b.c
486 local _max_5 = #_list_0 + -5 + 1
487 for _index_0 = 5, _max_5 do
488 local _item_1 = _list_0[_index_0]
489 _accum_0[_len_0] = _item_1
490 _len_0 = _len_0 + 1
491 end
492 _item_0 = _accum_0
493 end
494 return _item_0[#_item_0 - 2]
495end
496local _anon_func_2 = function(x)
497 if x ~= nil then
498 local _obj_0 = x.y
499 if _obj_0 ~= nil then
500 local _obj_1 = _obj_0(x).z
501 if _obj_1 ~= nil then
502 local _obj_2 = _obj_1[#_obj_1 - 3]
503 if _obj_2 ~= nil then
504 local _accum_0 = { }
505 local _len_0 = 1
506 local _max_5 = #_obj_2 + -3 + 1
507 for _index_0 = 1, _max_5 do
508 local _item_0 = _obj_2[_index_0]
509 _accum_0[_len_0] = _item_0
510 _len_0 = _len_0 + 1
511 end
512 return _accum_0
513 end
514 return nil
515 end
516 return nil
517 end
518 return nil
519 end
520 return nil
521end
522do
523 local f
524 f = function()
525 return print(_anon_func_0(globalTB), _anon_func_1(a), _anon_func_2(x))
526 end
527end
528do
529 local tb = {
530 1,
531 2,
532 3
533 }
534 tb[#tb] = 40
535 tb[#tb - 1] = 20
536end
537do
538 a = "x"
539 b = a
540 c = a
541 local lst = { }
542 lst[#lst] = a
543 lst[#lst - 1] = b
544end
545do
546 local y, z
547 x, y, z = 1, 2, 3
548 local arr = { }
549 local head
550 arr[#arr], head = x, y
551 arr[#arr] = z
552end
553do
554 local triple = {
555 "keep",
556 "skip",
557 "tail"
558 }
559 local head, tailv = triple[1], triple[3]
560 local buf = { }
561 buf[#buf] = head
562 buf[#buf] = tailv
563end
564do
565 local src = {
566 "a",
567 "",
568 "c",
569 nil,
570 "d"
571 }
572 local collected = { }
573 for _index_0 = 1, #src do
574 local item = src[_index_0]
575 if item and #item > 0 then
576 collected[#collected] = item
577 end
578 end
579end
580do
581 local nums = {
582 1,
583 2,
584 3,
585 4,
586 5
587 }
588 local last_two
589 do
590 local _accum_0 = { }
591 local _len_0 = 1
592 for _index_0 = 1, #nums do
593 local v = nums[_index_0]
594 if v > 3 then
595 _accum_0[_len_0] = v
596 _len_0 = _len_0 + 1
597 end
598 end
599 last_two = _accum_0
600 end
601 nums[#nums] = last_two[1]
602 nums[#nums] = last_two[2]
603end
604do
605 local store = { }
606 store[#store] = {
607 meta = {
608 id = 1,
609 ok = true
610 },
611 payload = {
612 10,
613 20
614 }
615 }
616 store[#store] = {
617 meta = {
618 id = 1,
619 ok = false
620 },
621 payload = {
622 10,
623 20,
624 30
625 }
626 }
627end
628local _anon_func_3 = function(tb)
629 local _item_0 = tb.tmp
630 return _item_0[#_item_0]
631end
632do
633 local f
634 f = function()
635 local q = { }
636 do
637 local _accum_0 = { }
638 local _len_0 = 1
639 for n = 1, 4 do
640 _accum_0[_len_0] = n
641 _len_0 = _len_0 + 1
642 end
643 tb.tmp = _accum_0
644 end
645 if #tb.tmp >= 3 then
646 q[#q] = {
647 head = tb.tmp[1],
648 tail = _anon_func_3(tb)
649 }
650 end
651 end
652end
653do
654 local make_pair
655 make_pair = function(a, b)
656 return {
657 a,
658 b
659 }
660 end
661 local pairs = { }
662 local p1 = make_pair(7, 8)
663 pairs[#pairs] = p1
664 local k, v = "key", 42
665 pairs[#pairs] = {
666 k = k,
667 v = v
668 }
669end
670do
671 local cfg = {
672 mode = "safe",
673 tags = { }
674 }
675 if cfg.mode == "safe" then
676 cfg.mode = "fast"
677 local _obj_0 = cfg.tags
678 _obj_0[#_obj_0] = "newbie"
679 end
680end
681do
682 local mat = {
683 {
684 1,
685 2
686 },
687 {
688 3,
689 4
690 },
691 {
692 5,
693 6
694 }
695 }
696 local last_row = mat[#mat]
697 local rows = { }
698 rows[#rows] = last_row[1]
699end
700do
701 local kv = { }
702 kv[#kv] = {
703 k = "a",
704 v = 1
705 }
706 kv[#kv] = {
707 k = "b",
708 v = 2
709 }
710 local pair_last = kv[#kv]
711 local dict = { }
712 dict[pair_last.k] = pair_last.v
713 dict[pair_last.k] = 3
714end
715do
716 local base
717 do
718 local _accum_0 = { }
719 local _len_0 = 1
720 for i = 1, 4 do
721 _accum_0[_len_0] = i
722 _len_0 = _len_0 + 1
723 end
724 base = _accum_0
725 end
726 local pack = { }
727 pack[#pack] = {
728 base[1],
729 base[#base]
730 }
731 pack[#pack] = {
732 first = base[1],
733 last = base[#base]
734 }
735end
736do
737 local opts = {
738 limit = 10
739 }
740 local limit, offset = opts.limit, opts.offset
741 if offset == nil then
742 offset = 0
743 end
744 local pages = { }
745 pages[#pages] = {
746 limit = limit,
747 offset = offset
748 }
749end
750do
751 local chain = {
752 a = {
753 b = {
754 c = 0
755 }
756 },
757 list = {
758 {
759 x = 0
760 },
761 {
762 x = 0
763 }
764 }
765 }
766 chain.a.b.c = 1
767 chain.list[1].x = 10;
768 ((function()
769 local _item_0 = chain.list
770 return _item_0[#_item_0]
771 end)()).x = 20
772 local _obj_0 = chain.list
773 _obj_0[#_obj_0 - 1] = {
774 x = 30
775 }
776end
777do
778 local node = {
779 left = {
780 v = 0
781 },
782 right = {
783 v = 0
784 }
785 }
786 local bag = { }
787 local left, right = node.left, node.right
788 bag[#bag], left.v, right.v = "k", 1, 2
789end
790do
791 local a1, a2, a3 = 100, 200, 300
792 local mix = { }
793 local meta
794 mix[#mix], mix[#mix], meta = a1, a2, {
795 tag = "ok"
796 }
797end
798do
799 local cfg2 = {
800 limit = 5,
801 opts = {
802 flag = false
803 }
804 }
805 local lim, opt2 = cfg2.limit, cfg2.opts
806 local bucket = {
807 xs = { }
808 }
809 local _obj_0 = bucket.xs
810 _obj_0[#_obj_0] = lim
811 bucket.flag = true
812 local _obj_1 = opt2.flags
813 _obj_1[#_obj_1 + 1] = 123
814end
815do
816 local ret2
817 ret2 = function()
818 return 7, 8
819 end
820 local box = { }
821 local x1
822 box[#box], x1 = ret2()
823end
824do
825 local q = {
826 1,
827 2
828 }
829 local lastq = q[#q]
830 q[#q - 1] = lastq * 10
831end
832do
833 local mat2 = [[9,8], [7,6]]
834 local t = {
835 hold = nil
836 }
837 t.hold = mat2[#mat2][1]
838end
839do
840 local f
841 f = function()
842 local _obj_0
843 do
844 local _item_0 = globalTB
845 _obj_0 = _item_0[#_item_0]
846 end
847 _obj_0[#_obj_0] = 1
848 end
849 local f1
850 f1 = function()
851 do
852 local _item_0 = globalTB
853 do
854 local _item_1 = _item_0[#_item_0]
855 return _item_1[#_item_1 - 1]
856 end
857 end
858 end
859end
860do
861 do
862 local _obj_0 = tbA
863 local _len_0 = #_obj_0 + 1
864 local _list_0 = tbB
865 for _index_0 = 1, #_list_0 do
866 local _elm_0 = _list_0[_index_0]
867 _obj_0[_len_0], _len_0 = _elm_0, _len_0 + 1
868 end
869 end
870 a = 1
871 do
872 local _obj_0 = tb
873 local _len_0 = #_obj_0 + 1
874 for _index_0 = 1, #x do
875 local _elm_0 = x[_index_0]
876 _obj_0[_len_0], _len_0 = _elm_0, _len_0 + 1
877 end
878 end
879 b[#b + 1] = 3
880 c = 4
881 local data = {
882 a = {
883 1,
884 2,
885 3
886 },
887 b = {
888 4,
889 5,
890 6
891 }
892 }
893 local flat
894 local _accum_0 = { }
895 for k, v in pairs(data) do
896 local _len_0 = #_accum_0 + 1
897 for _index_0 = 1, #v do
898 local _elm_0 = v[_index_0]
899 _accum_0[_len_0], _len_0 = _elm_0, _len_0 + 1
900 end
901 end
902 flat = _accum_0
903end
330return nil 904return nil
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua
index 8624d49..6ab4bbb 100644
--- a/spec/outputs/loops.lua
+++ b/spec/outputs/loops.lua
@@ -60,8 +60,8 @@ do
60 local y = hello[_index_0] 60 local y = hello[_index_0]
61 if y % 2 == 0 then 61 if y % 2 == 0 then
62 _accum_0[_len_0] = y 62 _accum_0[_len_0] = y
63 _len_0 = _len_0 + 1
63 end 64 end
64 _len_0 = _len_0 + 1
65 end 65 end
66 x = _accum_0 66 x = _accum_0
67end 67end
@@ -132,13 +132,11 @@ do
132end 132end
133do 133do
134 local _accum_0 = { } 134 local _accum_0 = { }
135 local _len_0 = 1
136 local _list_2 = 3 135 local _list_2 = 3
137 for _index_0 = 1, #_list_2 do 136 for _index_0 = 1, #_list_2 do
138 local thing = _list_2[_index_0] 137 local thing = _list_2[_index_0]
139 y = "hello" 138 y = "hello"
140 break 139 break
141 _len_0 = _len_0 + 1
142 end 140 end
143 x = _accum_0 141 x = _accum_0
144end 142end
@@ -370,3 +368,131 @@ do
370 end 368 end
371 until false 369 until false
372end 370end
371local _anon_func_0 = function(i, tb)
372 local _accum_0 = { }
373 local _len_0 = 1
374 while tb[i] do
375 i = i + 1
376 _accum_0[_len_0] = i - 1
377 _len_0 = _len_0 + 1
378 end
379 return _accum_0
380end
381do
382 local index
383 do
384 local _accum_0
385 for i = 1, #tb do
386 if tb[i] then
387 _accum_0 = i
388 break
389 end
390 end
391 index = _accum_0
392 end
393 f((function()
394 local _accum_0
395 for i = 1, #tb do
396 if tb[i] then
397 _accum_0 = i
398 break
399 end
400 end
401 return _accum_0
402 end)())
403 f((function()
404 local _accum_0 = { }
405 local _len_0 = 1
406 for i = 1, #tb do
407 if tb[i] then
408 _accum_0[_len_0] = i
409 _len_0 = _len_0 + 1
410 end
411 end
412 return _accum_0
413 end)())
414 i = 1
415 local ids
416 do
417 local _accum_0 = { }
418 local _len_0 = 1
419 while tb[i] do
420 i = i + 1
421 _accum_0[_len_0] = i - 1
422 _len_0 = _len_0 + 1
423 end
424 ids = _accum_0
425 end
426 i = 1
427 local idx
428 do
429 local _accum_0
430 while tb[i] do
431 i = i + 1
432 _accum_0 = i - 1
433 break
434 end
435 idx = _accum_0
436 end
437 local f1
438 f1 = function()
439 i = 1
440 return f(_anon_func_0(i, tb))
441 end
442 i = 1
443 f((function()
444 local _accum_0
445 while tb[i] do
446 i = i + 1
447 _accum_0 = i - 1
448 break
449 end
450 return _accum_0
451 end)())
452 local _accum_0 = { }
453 local _len_0 = 1
454 local _list_3 = items
455 for _index_0 = 1, #_list_3 do
456 local item = _list_3[_index_0]
457 local _type_0 = type(item)
458 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
459 if _tab_0 then
460 local value = item.value
461 if "A" == item.type and value ~= nil then
462 if value > 5 then
463 _accum_0[_len_0] = item
464 _len_0 = _len_0 + 1
465 end
466 end
467 end
468 end
469 list = _accum_0
470end
471do
472 repeat
473 print(1)
474 until true
475 do
476 local _accum_0
477 repeat
478 a = func()
479 _accum_0 = a.x
480 break
481 until a.v
482 x = _accum_0
483 end
484 local items
485 local _accum_0 = { }
486 local _len_0 = 1
487 repeat
488 local item = getItem()
489 if not item then
490 break
491 end
492 if item.value > 0 then
493 _accum_0[_len_0] = item
494 _len_0 = _len_0 + 1
495 end
496 until false
497 items = _accum_0
498end
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua
index 4d31574..89c6e63 100644
--- a/spec/outputs/macro.lua
+++ b/spec/outputs/macro.lua
@@ -26,6 +26,10 @@ print({
26 123, 26 123,
27 'xyz' 27 'xyz'
28}) 28})
29print({
30 456,
31 'abc'
32})
29do 33do
30 assert(item == nil) 34 assert(item == nil)
31end 35end
@@ -213,6 +217,13 @@ function tb:func()
213end 217end
214end 218end
215print(x) 219print(x)
220local yue = require("yue")
221do
222local function f2(a)
223 return a + 1
224end
225x = x + f2(3)
226end
216local sel 227local sel
217sel = function(a, b, c) 228sel = function(a, b, c)
218 if a then 229 if a then
@@ -317,7 +328,7 @@ print((setmetatable({
317 return 998 328 return 998
318 end 329 end
319})) 330}))
320print("current line: " .. tostring(323)) 331print("current line: " .. tostring(349))
321do 332do
322 do 333 do
323-- TODO 334-- TODO
@@ -330,10 +341,8 @@ local _1
330_1 = function() 341_1 = function()
331 print(1) 342 print(1)
332 local _accum_0 = { } 343 local _accum_0 = { }
333 local _len_0 = 1
334 while false do 344 while false do
335 break 345 break
336 _len_0 = _len_0 + 1
337 end 346 end
338 return _accum_0 347 return _accum_0
339end 348end
diff --git a/spec/outputs/props.lua b/spec/outputs/props.lua
new file mode 100644
index 0000000..2c282e0
--- /dev/null
+++ b/spec/outputs/props.lua
@@ -0,0 +1,240 @@
1local Props
2do
3 local _class_0
4 local assignReadOnly
5 local _base_0 = {
6 __index = function(self, name)
7 local cls = getmetatable(self)
8 do
9 local item
10 do
11 local _obj_0 = cls.__getter
12 if _obj_0 ~= nil then
13 item = _obj_0[name]
14 end
15 end
16 if item then
17 return item(self)
18 else
19 item = rawget(cls, name)
20 if item then
21 return item
22 else
23 local c = cls
24 repeat
25 c = getmetatable(c)
26 if c then
27 local _obj_0 = c.__getter
28 if _obj_0 ~= nil then
29 item = _obj_0[name]
30 end
31 if item then
32 if cls.__getter == nil then
33 cls.__getter = { }
34 end
35 cls.__getter[name] = item
36 return item(self)
37 else
38 item = rawget(c, name)
39 if item then
40 rawset(cls, name, item)
41 return item
42 end
43 end
44 else
45 break
46 end
47 until false
48 end
49 end
50 end
51 return nil
52 end,
53 __newindex = function(self, name, value)
54 local cls = getmetatable(self)
55 local item
56 local _obj_0 = cls.__setter
57 if _obj_0 ~= nil then
58 item = _obj_0[name]
59 end
60 if item then
61 return item(self, value)
62 else
63 local c = cls
64 repeat
65 c = getmetatable(c)
66 if c then
67 local _obj_1 = c.__setter
68 if _obj_1 ~= nil then
69 item = _obj_1[name]
70 end
71 if item then
72 if cls.__setter == nil then
73 cls.__setter = { }
74 end
75 cls.__setter[name] = item
76 item(self, value)
77 return
78 end
79 else
80 break
81 end
82 until false
83 return rawset(self, name, value)
84 end
85 end,
86 prop = function(self, name, props)
87 local get, set = props.get, props.set
88 if set == nil then
89 set = assignReadOnly
90 end
91 do
92 local getter = rawget(self.__base, "__getter")
93 if getter then
94 getter[name] = get
95 else
96 rawset(self.__base, "__getter", {
97 [name] = get
98 })
99 end
100 end
101 local setter = rawget(self.__base, "__setter")
102 if setter then
103 setter[name] = set
104 else
105 return rawset(self.__base, "__setter", {
106 [name] = set
107 })
108 end
109 end
110 }
111 if _base_0.__index == nil then
112 _base_0.__index = _base_0
113 end
114 _class_0 = setmetatable({
115 __init = function() end,
116 __base = _base_0,
117 __name = "Props"
118 }, {
119 __index = _base_0,
120 __call = function(cls, ...)
121 local _self_0 = setmetatable({ }, _base_0)
122 cls.__init(_self_0, ...)
123 return _self_0
124 end
125 })
126 _base_0.__class = _class_0
127 local self = _class_0;
128 assignReadOnly = function()
129 return error("assigning a readonly property")
130 end
131 Props = _class_0
132end
133local A
134do
135 local _class_0
136 local _parent_0 = Props
137 local _base_0 = { }
138 for _key_0, _val_0 in pairs(_parent_0.__base) do
139 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
140 _base_0[_key_0] = _val_0
141 end
142 end
143 if _base_0.__index == nil then
144 _base_0.__index = _base_0
145 end
146 setmetatable(_base_0, _parent_0.__base)
147 _class_0 = setmetatable({
148 __init = function(self)
149 self._x = 0
150 end,
151 __base = _base_0,
152 __name = "A",
153 __parent = _parent_0
154 }, {
155 __index = function(cls, name)
156 local val = rawget(_base_0, name)
157 if val == nil then
158 local parent = rawget(cls, "__parent")
159 if parent then
160 return parent[name]
161 end
162 else
163 return val
164 end
165 end,
166 __call = function(cls, ...)
167 local _self_0 = setmetatable({ }, _base_0)
168 cls.__init(_self_0, ...)
169 return _self_0
170 end
171 })
172 _base_0.__class = _class_0
173 local self = _class_0;
174 self:prop('x', {
175 get = function(self)
176 return self._x + 1000
177 end,
178 set = function(self, v)
179 self._x = v
180 end
181 })
182 if _parent_0.__inherited then
183 _parent_0.__inherited(_parent_0, _class_0)
184 end
185 A = _class_0
186end
187local B
188do
189 local _class_0
190 local _parent_0 = A
191 local _base_0 = { }
192 for _key_0, _val_0 in pairs(_parent_0.__base) do
193 if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then
194 _base_0[_key_0] = _val_0
195 end
196 end
197 if _base_0.__index == nil then
198 _base_0.__index = _base_0
199 end
200 setmetatable(_base_0, _parent_0.__base)
201 _class_0 = setmetatable({
202 __init = function(self, ...)
203 return _class_0.__parent.__init(self, ...)
204 end,
205 __base = _base_0,
206 __name = "B",
207 __parent = _parent_0
208 }, {
209 __index = function(cls, name)
210 local val = rawget(_base_0, name)
211 if val == nil then
212 local parent = rawget(cls, "__parent")
213 if parent then
214 return parent[name]
215 end
216 else
217 return val
218 end
219 end,
220 __call = function(cls, ...)
221 local _self_0 = setmetatable({ }, _base_0)
222 cls.__init(_self_0, ...)
223 return _self_0
224 end
225 })
226 _base_0.__class = _class_0
227 local self = _class_0;
228 self:prop('abc', {
229 get = function(self)
230 return "hello"
231 end
232 })
233 if _parent_0.__inherited then
234 _parent_0.__inherited(_parent_0, _class_0)
235 end
236 B = _class_0
237end
238local b = B()
239b.x = 999
240return print(b.x, b.abc)
diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua
index febea62..bdfd676 100644
--- a/spec/outputs/string.lua
+++ b/spec/outputs/string.lua
@@ -1,3 +1,4 @@
1local _module_0 = { }
1local hi = "hello" 2local hi = "hello"
2local hello = "what the heckyes" 3local hello = "what the heckyes"
3print(hi) 4print(hi)
@@ -41,4 +42,42 @@ local _ = "hello";
41("hello"):format().hello(1, 2, 3); 42("hello"):format().hello(1, 2, 3);
42("hello"):format(1, 2, 3) 43("hello"):format(1, 2, 3)
43something("hello"):world() 44something("hello"):world()
44return something(("hello"):world()) 45something(("hello"):world())
46do
47 local str = "key: value"
48 str = "config:\n\tenabled: true\n\tlevel: 5"
49 str = "header: start\nfooter: end"
50 str = "name: " .. tostring(username)
51 str = "count: " .. tostring(total) .. " items"
52 str = "user: " .. tostring(name) .. "\nid: " .. tostring(id)
53 str = "path: \"C:\\\\Program Files\\\\App\"\ndesc: 'single \"quote\" test'"
54 str = "key: value \nnext: 123 "
55 str = "list:\n\t- \"one\"\n\t- \"two\""
56 str = "-- comment\ncontent text\n-- comment"
57 str = tostring(1 + 2) .. '\n' .. tostring(2 + 3) .. '\n' .. tostring("a" .. "b")
58 local obj = {
59 settings = "mode: " .. tostring(mode) .. "\nflags:\n\t- " .. tostring(flag1) .. "\n\t- default"
60 }
61 local fn
62 fn = function()
63 return "Hello\nname: " .. tostring(userName)
64 end
65 str = "result:\n\tstatus: " .. tostring((function()
66 if ok then
67 return "pass"
68 else
69 return "fail"
70 end
71 end)()) .. "\n\tcode: " .. tostring(code)
72 local summary = "date: " .. tostring(os.date()) .. "\nvalues:\n\t-\n\t\ta: " .. tostring(aVal) .. "\n\t\tb: " .. tostring(bVal or defaultB)
73 local msg = send("Hello, " .. tostring(user) .. "!\nToday is " .. tostring(os.date("%A")) .. ".")
74 local desc
75 do
76 local prefix = "Result"
77 desc = tostring(prefix) .. ":\nvalue: " .. tostring(compute())
78 end
79 print(("1\n2\n3"))
80end
81local yaml = "version: " .. tostring(ver) .. "\nok: true"
82_module_0["yaml"] = yaml
83return _module_0
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua
index e4dedc9..7c1004b 100644
--- a/spec/outputs/switch.lua
+++ b/spec/outputs/switch.lua
@@ -415,4 +415,366 @@ do
415 end 415 end
416 end 416 end
417end 417end
418do
419 local _exp_0 = tb
420 local _type_0 = type(_exp_0)
421 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
422 local _match_0 = false
423 if _tab_0 then
424 if 1 == _exp_0[1] and 2 == _exp_0[2] and 3 == _exp_0[3] then
425 _match_0 = true
426 print("1, 2, 3")
427 end
428 end
429 if not _match_0 then
430 local _match_1 = false
431 if _tab_0 then
432 local b = _exp_0[2]
433 if 1 == _exp_0[1] and b ~= nil and 3 == _exp_0[3] then
434 _match_1 = true
435 print("1, " .. tostring(b) .. ", 3")
436 end
437 end
438 if not _match_1 then
439 if _tab_0 then
440 local b = _exp_0[3]
441 if b == nil then
442 b = 3
443 end
444 if 1 == _exp_0[1] and 2 == _exp_0[2] then
445 print("1, 2, " .. tostring(b))
446 end
447 end
448 end
449 end
450end
451do
452 local _exp_0 = tb
453 local _type_0 = type(_exp_0)
454 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
455 local _match_0 = false
456 if _tab_0 then
457 local result = _exp_0.result
458 if true == _exp_0.success and result ~= nil then
459 _match_0 = true
460 print("success", result)
461 end
462 end
463 if not _match_0 then
464 local _match_1 = false
465 if _tab_0 then
466 if false == _exp_0.success then
467 _match_1 = true
468 print("failed", result)
469 end
470 end
471 if not _match_1 then
472 print("invalid")
473 end
474 end
475end
476do
477 local _exp_0 = tb
478 local _type_0 = type(_exp_0)
479 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
480 local _match_0 = false
481 if _tab_0 then
482 local content = _exp_0.content
483 if "success" == _exp_0.type and content ~= nil then
484 _match_0 = true
485 print("success", content)
486 end
487 end
488 if not _match_0 then
489 local _match_1 = false
490 if _tab_0 then
491 local content = _exp_0.content
492 if "error" == _exp_0.type and content ~= nil then
493 _match_1 = true
494 print("failed", content)
495 end
496 end
497 if not _match_1 then
498 print("invalid")
499 end
500 end
501end
502do
503 do
504 local _exp_0 = tb
505 local _type_0 = type(_exp_0)
506 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
507 if _tab_0 then
508 local fourth = _exp_0[4]
509 local _val_0
510 do
511 local _obj_0 = _exp_0[1]
512 if _obj_0 ~= nil then
513 _val_0 = _obj_0.a
514 end
515 end
516 local _val_1
517 do
518 local _obj_0 = _exp_0[1]
519 if _obj_0 ~= nil then
520 _val_1 = _obj_0.b
521 end
522 end
523 local _val_2
524 do
525 local _obj_0 = _exp_0[2]
526 if _obj_0 ~= nil then
527 _val_2 = _obj_0.a
528 end
529 end
530 local _val_3
531 do
532 local _obj_0 = _exp_0[2]
533 if _obj_0 ~= nil then
534 _val_3 = _obj_0.b
535 end
536 end
537 local _val_4
538 do
539 local _obj_0 = _exp_0[3]
540 if _obj_0 ~= nil then
541 _val_4 = _obj_0.a
542 end
543 end
544 local _val_5
545 do
546 local _obj_0 = _exp_0[3]
547 if _obj_0 ~= nil then
548 _val_5 = _obj_0.b
549 end
550 end
551 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and fourth ~= nil then
552 print("matched", fourth)
553 end
554 end
555 end
556 local _exp_0 = tb
557 local _type_0 = type(_exp_0)
558 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
559 local _match_0 = false
560 if _tab_0 then
561 local _val_0
562 do
563 local _obj_0 = _exp_0[1]
564 if _obj_0 ~= nil then
565 _val_0 = _obj_0.c
566 end
567 end
568 local _val_1
569 do
570 local _obj_0 = _exp_0[1]
571 if _obj_0 ~= nil then
572 _val_1 = _obj_0.d
573 end
574 end
575 local _val_2
576 do
577 local _obj_0 = _exp_0[2]
578 if _obj_0 ~= nil then
579 _val_2 = _obj_0.c
580 end
581 end
582 local _val_3
583 do
584 local _obj_0 = _exp_0[2]
585 if _obj_0 ~= nil then
586 _val_3 = _obj_0.d
587 end
588 end
589 local _val_4
590 do
591 local _obj_0 = _exp_0[3]
592 if _obj_0 ~= nil then
593 _val_4 = _obj_0.c
594 end
595 end
596 local _val_5
597 do
598 local _obj_0 = _exp_0[3]
599 if _obj_0 ~= nil then
600 _val_5 = _obj_0.d
601 end
602 end
603 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 then
604 _match_0 = true
605 print("OK")
606 end
607 end
608 if not _match_0 then
609 if _tab_0 then
610 local sixth = _exp_0[6]
611 local _val_0
612 do
613 local _obj_0 = _exp_0[3]
614 if _obj_0 ~= nil then
615 _val_0 = _obj_0.a
616 end
617 end
618 local _val_1
619 do
620 local _obj_0 = _exp_0[3]
621 if _obj_0 ~= nil then
622 _val_1 = _obj_0.b
623 end
624 end
625 local _val_2
626 do
627 local _obj_0 = _exp_0[4]
628 if _obj_0 ~= nil then
629 _val_2 = _obj_0.a
630 end
631 end
632 local _val_3
633 do
634 local _obj_0 = _exp_0[4]
635 if _obj_0 ~= nil then
636 _val_3 = _obj_0.b
637 end
638 end
639 local _val_4
640 do
641 local _obj_0 = _exp_0[5]
642 if _obj_0 ~= nil then
643 _val_4 = _obj_0.a
644 end
645 end
646 local _val_5
647 do
648 local _obj_0 = _exp_0[5]
649 if _obj_0 ~= nil then
650 _val_5 = _obj_0.b
651 end
652 end
653 if 1 == _val_0 and 2 == _val_1 and 3 == _val_2 and 4 == _val_3 and 5 == _val_4 and 6 == _val_5 and sixth ~= nil then
654 print("matched", sixth)
655 end
656 end
657 end
658end
659do
660 local v = "hello"
661 if "hello" == v then
662 print("matched hello")
663 else
664 print("not matched")
665 end
666end
667do
668 local f
669 f = function()
670 return "ok"
671 end
672 local val = f()
673 if "ok" == val then
674 print("it's ok")
675 end
676end
677do
678 local g
679 g = function()
680 return 42
681 end
682 local result = g()
683 if 1 == result or 2 == result then
684 print("small")
685 elseif 42 == result then
686 print("life universe everything")
687 else
688 print("other " .. tostring(result))
689 end
690end
691do
692 local check
693 check = function()
694 if true then
695 return "yes"
696 else
697 return "no"
698 end
699 end
700 local x = check()
701 if "yes" == x then
702 print("affirmative")
703 else
704 print("negative")
705 end
706end
707do
708 local t
709 t = function()
710 local tb = {
711 a = 1
712 }
713 tb.a = 2
714 return tb
715 end
716 local data = t()
717 local _type_0 = type(data)
718 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
719 local _match_0 = false
720 if _tab_0 then
721 if 2 == data.a then
722 _match_0 = true
723 print("matched")
724 end
725 end
726 if not _match_0 then
727 print("not matched")
728 end
729end
730do
731 local clientData = {
732 "Meta",
733 "CUST_1001",
734 "CHK123"
735 }
736 local _type_0 = type(clientData)
737 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
738 if _tab_0 then
739 local metadata
740 do
741 local _accum_0 = { }
742 local _len_0 = 1
743 local _max_0 = #clientData + -3 + 1
744 for _index_0 = 1, _max_0 do
745 local _item_0 = clientData[_index_0]
746 _accum_0[_len_0] = _item_0
747 _len_0 = _len_0 + 1
748 end
749 metadata = _accum_0
750 end
751 local customerId = clientData[#clientData - 1]
752 local checksum = clientData[#clientData]
753 if customerId ~= nil and checksum ~= nil then
754 print(metadata)
755 print(customerId)
756 print(checksum)
757 end
758 end
759end
760do
761 local handlePath
762 handlePath = function(segments)
763 local _type_0 = type(segments)
764 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
765 if _tab_0 then
766 local resource = segments[#segments - 1]
767 local action = segments[#segments]
768 if resource ~= nil and action ~= nil then
769 print("Resource:", resource)
770 return print("Action:", action)
771 end
772 end
773 end
774 handlePath({
775 "admin",
776 "logs",
777 "view"
778 })
779end
418return nil 780return nil
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua
index 040a325..eb4543c 100644
--- a/spec/outputs/syntax.lua
+++ b/spec/outputs/syntax.lua
@@ -5,9 +5,9 @@ func(arg1, arg2, another, arg3)
5local we 5local we
6here, we = function() end, yeah 6here, we = function() end, yeah
7local the, different 7local the, different
8the, different = function() 8the, different = (function()
9 return approach 9 return approach
10end, yeah 10end), yeah
11dad() 11dad()
12dad(lord) 12dad(lord)
13hello(one, two)(); 13hello(one, two)();
@@ -430,4 +430,94 @@ do
430 local f2 430 local f2
431 f2 = function() end 431 f2 = function() end
432end 432end
433do
434 if res ~= "" then
435 return res
436 end
437end
438do
439 return res((function()
440 if res ~= "" then
441 end
442 end)())
443end
444do
445 x = 1
446 y = 2
447 i = i + 1
448 j = j + 1
449 if condition then
450 setup()
451 run()
452 cleanup()
453 end
454 a = 1
455 local b = 2
456 local c = a + b
457 print(a)
458 print(b)
459 print(c)
460 f = function()
461 a = 1
462 b = 2
463 return a + b
464 end
465 a = 1
466 b = 2
467 local success, result = pcall(function()
468 return func()
469 end)
470 if success then
471 print(result)
472 end
473 local value = "foo"
474 print(value)
475 value = value .. "bar"
476 print(value)
477 do
478 if ok then
479 print("ok!")
480 end
481 return 42
482 end
483 for i = 1, 3 do
484 print(i)
485 goto _continue_0
486 ::_continue_0::
487 end
488 local n = 0
489 while n < 2 do
490 print("n=", n)
491 n = n + 1
492 end
493 local obj = { }
494 obj:set(10)
495 obj:get()
496 print("done")
497 do
498 local _with_0 = tbl
499 _with_0:push(1)
500 print("push")
501 end
502 a = 5
503 if a > 3 then
504 print("big")
505 b = a * 2
506 print(b)
507 else
508 print("small")
509 b = a
510 end
511 xpcall(function()
512 x = 1
513 y = 2
514 return print(x + y)
515 end, function(err)
516 return print("error:", err)
517 end)
518end
519local q = 1
520local w = 2
521local e = 3
522print(q, w, e)
433return nil 523return nil
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua
index f358811..3f851de 100644
--- a/spec/outputs/tables.lua
+++ b/spec/outputs/tables.lua
@@ -366,6 +366,28 @@ local menus = {
366 } 366 }
367 } 367 }
368} 368}
369_ = {
370 boolean = {
371 true,
372 false
373 },
374 float = {
375 3.14,
376 -6.8523015e+5
377 },
378 int = {
379 123,
380 -685230
381 },
382 null = {
383 nodeName = 'node',
384 parent = nil
385 },
386 string = {
387 'Hello world',
388 "newline\nnewline2"
389 }
390}
369local tb 391local tb
370do 392do
371 local _tab_0 = { } 393 local _tab_0 = { }
diff --git a/spec/outputs/test/format_spec.lua b/spec/outputs/test/format_spec.lua
index ed0fbee..7aa85cd 100644
--- a/spec/outputs/test/format_spec.lua
+++ b/spec/outputs/test/format_spec.lua
@@ -122,7 +122,7 @@ return describe("format", function()
122 local original_ast = yue.to_ast(code) 122 local original_ast = yue.to_ast(code)
123 assert.is_not_nil(original_ast) 123 assert.is_not_nil(original_ast)
124 rewriteLineCol(original_ast) 124 rewriteLineCol(original_ast)
125 local formated = yue.format(code) 125 local formated = yue.format(code, 0, false)
126 local ast = yue.to_ast(formated) 126 local ast = yue.to_ast(formated)
127 assert.is_not_nil(ast) 127 assert.is_not_nil(ast)
128 rewriteLineCol(ast) 128 rewriteLineCol(ast)
diff --git a/spec/outputs/try_catch.lua b/spec/outputs/try_catch.lua
index efd92c6..edb2341 100644
--- a/spec/outputs/try_catch.lua
+++ b/spec/outputs/try_catch.lua
@@ -22,6 +22,44 @@ end
22local _anon_func_7 = function(a, b, c, tb) 22local _anon_func_7 = function(a, b, c, tb)
23 return tb.f(a, b, c) 23 return tb.f(a, b, c)
24end 24end
25local _anon_func_8 = function(_arg_0, ...)
26 local ok = _arg_0
27 return ...
28end
29local _anon_func_10 = function(_arg_0, ...)
30 local _ok_0 = _arg_0
31 if _ok_0 then
32 return ...
33 end
34end
35local _anon_func_9 = function(func, pcall)
36 return _anon_func_10(pcall(func))
37end
38local _anon_func_12 = function(_arg_0, ...)
39 local _ok_0 = _arg_0
40 if _ok_0 then
41 return ...
42 end
43end
44local _anon_func_11 = function(func, pcall)
45 return _anon_func_12(pcall(func))
46end
47local _anon_func_14 = function(_arg_0, ...)
48 local _ok_0 = _arg_0
49 if _ok_0 then
50 return ...
51 end
52end
53local _anon_func_15 = function(func, print)
54 print(123)
55 return func()
56end
57local _anon_func_13 = function(func, print, xpcall)
58 return _anon_func_14(xpcall(_anon_func_15, function(e)
59 print(e)
60 return e
61 end, func, print))
62end
25local f 63local f
26f = function() 64f = function()
27 xpcall(function() 65 xpcall(function()
@@ -104,10 +142,236 @@ f = function()
104 do 142 do
105 x(function() 143 x(function()
106 local tb, a, b, c 144 local tb, a, b, c
107 f = function() 145 local f1
146 f1 = function()
108 return pcall(_anon_func_7, a, b, c, tb) 147 return pcall(_anon_func_7, a, b, c, tb)
109 end 148 end
110 end) 149 end)
111 end 150 end
151 do
152 local f1
153 f1 = function()
154 do
155 return _anon_func_8(pcall(function()
156 return func()
157 end))
158 end
159 end
160 end
161 do
162 local func
163 local a, b, c
164 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
165 if _ok_0 then
166 a, b, c = _ret_0, _ret_1, _ret_2
167 end
168 end
169 do
170 local a, b, c
171 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
172 return func()
173 end)
174 if _ok_0 then
175 a, b, c = _ret_0, _ret_1, _ret_2
176 end
177 end
178 do
179 local a
180 local _exp_0 = (_anon_func_9(func, pcall))
181 if _exp_0 ~= nil then
182 a = _exp_0
183 else
184 a = "default"
185 end
186 end
187 do
188 f(_anon_func_11(func, pcall))
189 end
190 do
191 f(_anon_func_13(func, print, xpcall))
192 end
112 return nil 193 return nil
113end 194end
195local _anon_func_16 = function(a, b, c, tb)
196 return tb.f(a, b, c)
197end
198local _anon_func_17 = function(_arg_0, ...)
199 local ok = _arg_0
200 return ...
201end
202do
203 xpcall(function()
204 return func(1, 2, 3)
205 end, function(err)
206 return print(err)
207 end)
208 xpcall(function()
209 return func(1, 2, 3)
210 end, function(err)
211 return print(err)
212 end)
213 pcall(function()
214 print("trying")
215 return func(1, 2, 3)
216 end)
217 do
218 local success, result = xpcall(function()
219 return func(1, 2, 3)
220 end, function(err)
221 return print(err)
222 end)
223 success, result = pcall(function()
224 return func(1, 2, 3)
225 end)
226 end
227 local tb = { }
228 pcall(function()
229 return tb.func
230 end)
231 pcall(function()
232 return tb.func()
233 end)
234 pcall(function()
235 return tb.func()
236 end)
237 pcall(function()
238 return (tb.func())
239 end)
240 pcall(function()
241 return (tb:func(1, 2, 3))
242 end)
243 pcall(function()
244 return tb.func(1)
245 end)
246 pcall(function()
247 return tb.func(1)
248 end)
249 if (xpcall(function()
250 return func(1)
251 end, function(err)
252 return print(err)
253 end)) then
254 print("OK")
255 end
256 if xpcall(function()
257 return (func(1))
258 end, function(err)
259 return print(err)
260 end) then
261 print("OK")
262 end
263 do
264 do
265 local success, result = pcall(function()
266 return func("abc", 123)
267 end)
268 if success then
269 print(result)
270 end
271 end
272 local success, result = xpcall(function()
273 return func("abc", 123)
274 end, function(err)
275 return print(err)
276 end)
277 success, result = xpcall(function()
278 return func("abc", 123)
279 end, function(err)
280 return print(err)
281 end)
282 if success then
283 print(result)
284 end
285 end
286 do
287 pcall(function()
288 return func(1, 2, 3)
289 end)
290 pcall(function()
291 return func(1, 2, 3)
292 end)
293 end
294 do
295 x(function()
296 local tb, a, b, c
297 local f1
298 f1 = function()
299 return pcall(_anon_func_16, a, b, c, tb)
300 end
301 end)
302 end
303 do
304 local f1
305 f1 = function()
306 do
307 return _anon_func_17(pcall(function()
308 return func()
309 end))
310 end
311 end
312 end
313 do
314 local func
315 local a, b, c
316 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(func)
317 if _ok_0 then
318 a, b, c = _ret_0, _ret_1, _ret_2
319 end
320 end
321 do
322 local a, b, c
323 local _ok_0, _ret_0, _ret_1, _ret_2 = pcall(function()
324 return func()
325 end)
326 if _ok_0 then
327 a, b, c = _ret_0, _ret_1, _ret_2
328 end
329 end
330 do
331 local a
332 local _exp_0 = ((function()
333 return (function(_arg_0, ...)
334 local _ok_0 = _arg_0
335 if _ok_0 then
336 return ...
337 end
338 end)(pcall(function()
339 return func()
340 end))
341 end)())
342 if _exp_0 ~= nil then
343 a = _exp_0
344 else
345 a = "default"
346 end
347 end
348 do
349 f((function()
350 return (function(_arg_0, ...)
351 local _ok_0 = _arg_0
352 if _ok_0 then
353 return ...
354 end
355 end)(pcall(function()
356 return func()
357 end))
358 end)())
359 end
360 do
361 f((function()
362 return (function(_arg_0, ...)
363 local _ok_0 = _arg_0
364 if _ok_0 then
365 return ...
366 end
367 end)(xpcall(function()
368 print(123)
369 return func()
370 end, function(e)
371 print(e)
372 return e
373 end))
374 end)())
375 end
376end
377return nil
diff --git a/spec/outputs/unicode/assign.lua b/spec/outputs/unicode/assign.lua
index d4ad56a..e00d016 100644
--- a/spec/outputs/unicode/assign.lua
+++ b/spec/outputs/unicode/assign.lua
@@ -43,10 +43,8 @@ do
43 end 43 end
44end 44end
45local _anon_func_0 = function(_u6253_u5370) 45local _anon_func_0 = function(_u6253_u5370)
46 do 46 _u6253_u5370(123)
47 _u6253_u5370(123) 47 return { }
48 return { }
49 end
50end 48end
51return __u65e0_u6548_u53d8_u91cf(function() 49return __u65e0_u6548_u53d8_u91cf(function()
52 setmetatable(a_u53d8_u91cf, _anon_func_0(_u6253_u5370)) 50 setmetatable(a_u53d8_u91cf, _anon_func_0(_u6253_u5370))
diff --git a/spec/outputs/unicode/comprehension.lua b/spec/outputs/unicode/comprehension.lua
index 60e490f..92bce69 100644
--- a/spec/outputs/unicode/comprehension.lua
+++ b/spec/outputs/unicode/comprehension.lua
@@ -243,8 +243,11 @@ end
243do 243do
244 local _accum_0 = { } 244 local _accum_0 = { }
245 local _len_0 = 1 245 local _len_0 = 1
246 local _min_0 = 1 + 2
246 local _max_0 = 3 + 4 247 local _max_0 = 3 + 4
247 for _index_0 = 1 + 2, _max_0 < 0 and #_u5217_u8868 + _max_0 or _max_0 do 248 _min_0 = _min_0 < 0 and #_u5217_u8868 + _min_0 + 1 or _min_0
249 _max_0 = _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0
250 for _index_0 = _min_0, _max_0 do
248 local _u9879_u76ee = _u5217_u8868[_index_0] 251 local _u9879_u76ee = _u5217_u8868[_index_0]
249 _accum_0[_len_0] = _u9879_u76ee 252 _accum_0[_len_0] = _u9879_u76ee
250 _len_0 = _len_0 + 1 253 _len_0 = _len_0 + 1
@@ -254,8 +257,11 @@ end
254do 257do
255 local _accum_0 = { } 258 local _accum_0 = { }
256 local _len_0 = 1 259 local _len_0 = 1
260 local _min_0 = _u4f60_u597d() * 4
257 local _max_0 = 2 - _u4e1c_u897f[4] 261 local _max_0 = 2 - _u4e1c_u897f[4]
258 for _index_0 = _u4f60_u597d() * 4, _max_0 < 0 and #_u5217_u8868 + _max_0 or _max_0 do 262 _min_0 = _min_0 < 0 and #_u5217_u8868 + _min_0 + 1 or _min_0
263 _max_0 = _max_0 < 0 and #_u5217_u8868 + _max_0 + 1 or _max_0
264 for _index_0 = _min_0, _max_0 do
259 local _u9879_u76ee = _u5217_u8868[_index_0] 265 local _u9879_u76ee = _u5217_u8868[_index_0]
260 _accum_0[_len_0] = _u9879_u76ee 266 _accum_0[_len_0] = _u9879_u76ee
261 _len_0 = _len_0 + 1 267 _len_0 = _len_0 + 1
diff --git a/spec/outputs/unicode/funcs.lua b/spec/outputs/unicode/funcs.lua
index 6e94587..06b24b1 100644
--- a/spec/outputs/unicode/funcs.lua
+++ b/spec/outputs/unicode/funcs.lua
@@ -24,7 +24,7 @@ _u5f00(function()
24end) 24end)
25local _u53d8_u91cfh 25local _u53d8_u91cfh
26_u53d8_u91cfh = function() 26_u53d8_u91cfh = function()
27 return _ud83d_udc4b 27 return _u1f44b
28end 28end
29_u5403(function() end, _u4e16_u754c); 29_u5403(function() end, _u4e16_u754c);
30(function() end)() 30(function() end)()
diff --git a/spec/outputs/unicode/import.lua b/spec/outputs/unicode/import.lua
index 7c31ceb..e055c81 100644
--- a/spec/outputs/unicode/import.lua
+++ b/spec/outputs/unicode/import.lua
@@ -11,10 +11,10 @@ local _u5b57_u6bb5x, _u5b57_u6bb5y, _u5b57_u6bb5z = _u9053_u5177_u7ec4["字段x"
11 return _fn_0(_base_0, ...) 11 return _fn_0(_base_0, ...)
12 end 12 end
13end)(), _u9053_u5177_u7ec4["字段z"] 13end)(), _u9053_u5177_u7ec4["字段z"]
14local _u9886_u4e3b, _ud83d_udc7b 14local _u9886_u4e3b, _u1f47b
15do 15do
16 local _obj_1 = _u627e_u5230("我的表") 16 local _obj_1 = _u627e_u5230("我的表")
17 _u9886_u4e3b, _ud83d_udc7b = _obj_1["领主"], (function() 17 _u9886_u4e3b, _u1f47b = _obj_1["领主"], (function()
18 local _base_0 = _obj_1 18 local _base_0 = _obj_1
19 local _fn_0 = _base_0["👻"] 19 local _fn_0 = _base_0["👻"]
20 return _fn_0 and function(...) 20 return _fn_0 and function(...)
diff --git a/spec/outputs/unicode/lists.lua b/spec/outputs/unicode/lists.lua
index aafd516..3bf6f50 100644
--- a/spec/outputs/unicode/lists.lua
+++ b/spec/outputs/unicode/lists.lua
@@ -229,31 +229,36 @@ _u53d8_u91cfx = {
229 6, 229 6,
230 7 230 7
231} 231}
232local _max_0 = -5 232local _max_0 = #_u53d8_u91cfx + -5 + 1
233for _index_0 = 2, _max_0 < 0 and #_u53d8_u91cfx + _max_0 or _max_0, 2 do 233for _index_0 = 2, _max_0, 2 do
234 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 234 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
235 _u6253_u5370(_u53d8_u91cfy) 235 _u6253_u5370(_u53d8_u91cfy)
236end 236end
237local _max_1 = 3 237for _index_0 = 1, 3 do
238for _index_0 = 1, _max_1 < 0 and #_u53d8_u91cfx + _max_1 or _max_1 do
239 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 238 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
240 _u6253_u5370(_u53d8_u91cfy) 239 _u6253_u5370(_u53d8_u91cfy)
241end 240end
242for _index_0 = 2, #_u53d8_u91cfx do 241local _max_1 = #_u53d8_u91cfx
242for _index_0 = 2, _max_1 do
243 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 243 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
244 _u6253_u5370(_u53d8_u91cfy) 244 _u6253_u5370(_u53d8_u91cfy)
245end 245end
246for _index_0 = 1, #_u53d8_u91cfx, 2 do 246local _max_2 = #_u53d8_u91cfx
247for _index_0 = 1, _max_2, 2 do
247 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 248 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
248 _u6253_u5370(_u53d8_u91cfy) 249 _u6253_u5370(_u53d8_u91cfy)
249end 250end
250for _index_0 = 2, #_u53d8_u91cfx, 2 do 251local _max_3 = #_u53d8_u91cfx
252for _index_0 = 2, _max_3, 2 do
251 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 253 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
252 _u6253_u5370(_u53d8_u91cfy) 254 _u6253_u5370(_u53d8_u91cfy)
253end 255end
254local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2 256local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = 1, 5, 2
255local _max_2 = _u53d8_u91cfb 257local _min_0 = _u53d8_u91cfa
256for _index_0 = _u53d8_u91cfa, _max_2 < 0 and #_u53d8_u91cfx + _max_2 or _max_2, _u53d8_u91cfc do 258local _max_4 = _u53d8_u91cfb
259_min_0 = _min_0 < 0 and #_u53d8_u91cfx + _min_0 + 1 or _min_0
260_max_4 = _max_4 < 0 and #_u53d8_u91cfx + _max_4 + 1 or _max_4
261for _index_0 = _min_0, _max_4, _u53d8_u91cfc do
257 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0] 262 local _u53d8_u91cfy = _u53d8_u91cfx[_index_0]
258 _u6253_u5370(_u53d8_u91cfy) 263 _u6253_u5370(_u53d8_u91cfy)
259end 264end
diff --git a/spec/outputs/unicode/loops.lua b/spec/outputs/unicode/loops.lua
index 8379993..27bbe2e 100644
--- a/spec/outputs/unicode/loops.lua
+++ b/spec/outputs/unicode/loops.lua
@@ -60,8 +60,8 @@ do
60 local _u53d8_u91cfy = _u4f60_u597d[_index_0] 60 local _u53d8_u91cfy = _u4f60_u597d[_index_0]
61 if _u53d8_u91cfy % 2 == 0 then 61 if _u53d8_u91cfy % 2 == 0 then
62 _accum_0[_len_0] = _u53d8_u91cfy 62 _accum_0[_len_0] = _u53d8_u91cfy
63 _len_0 = _len_0 + 1
63 end 64 end
64 _len_0 = _len_0 + 1
65 end 65 end
66 _u53d8_u91cfx = _accum_0 66 _u53d8_u91cfx = _accum_0
67end 67end
@@ -132,13 +132,11 @@ do
132end 132end
133do 133do
134 local _accum_0 = { } 134 local _accum_0 = { }
135 local _len_0 = 1
136 local _list_2 = 3 135 local _list_2 = 3
137 for _index_0 = 1, #_list_2 do 136 for _index_0 = 1, #_list_2 do
138 local _u4e1c_u897f = _list_2[_index_0] 137 local _u4e1c_u897f = _list_2[_index_0]
139 _u53d8_u91cfy = "你好" 138 _u53d8_u91cfy = "你好"
140 break 139 break
141 _len_0 = _len_0 + 1
142 end 140 end
143 _u53d8_u91cfx = _accum_0 141 _u53d8_u91cfx = _accum_0
144end 142end
diff --git a/spec/outputs/unicode/macro.lua b/spec/outputs/unicode/macro.lua
index b14f571..b4e78cd 100644
--- a/spec/outputs/unicode/macro.lua
+++ b/spec/outputs/unicode/macro.lua
@@ -216,17 +216,15 @@ do
216end 216end
217local _ = require('下划线') 217local _ = require('下划线')
218local _anon_func_0 = function(_) 218local _anon_func_0 = function(_)
219 do 219 local _call_0 = (_({
220 local _call_0 = (_({ 220 1,
221 1, 221 2,
222 2, 222 3,
223 3, 223 4,
224 4, 224 -2,
225 -2, 225 3
226 3 226 }))
227 })) 227 return _call_0["链"](_call_0)
228 return _call_0["链"](_call_0)
229 end
230end 228end
231local _call_0 = ((function() 229local _call_0 = ((function()
232 local _call_0 = ((function() 230 local _call_0 = ((function()
@@ -241,17 +239,15 @@ local _call_0 = ((function()
241end)()) 239end)())
242local _u7ed3_u679ca = _call_0["取值"](_call_0) 240local _u7ed3_u679ca = _call_0["取值"](_call_0)
243local _anon_func_1 = function(_) 241local _anon_func_1 = function(_)
244 do 242 local _call_1 = (_({
245 local _call_1 = (_({ 243 1,
246 1, 244 2,
247 2, 245 3,
248 3, 246 4,
249 4, 247 -2,
250 -2, 248 3
251 3 249 }))
252 })) 250 return _call_1["链"](_call_1)
253 return _call_1["链"](_call_1)
254 end
255end 251end
256do 252do
257 local _call_1 = ((function() 253 local _call_1 = ((function()
@@ -270,10 +266,8 @@ do
270 end) 266 end)
271end 267end
272local _anon_func_2 = function(_u539f_u70b9) 268local _anon_func_2 = function(_u539f_u70b9)
273 do 269 local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"]
274 local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] 270 return _call_1["父节点"](_call_1)
275 return _call_1["父节点"](_call_1)
276 end
277end 271end
278local _call_1 = ((function() 272local _call_1 = ((function()
279 local _call_1 = ((function() 273 local _call_1 = ((function()
@@ -365,10 +359,8 @@ local _1
365_1 = function() 359_1 = function()
366 _u6253_u5370(1) 360 _u6253_u5370(1)
367 local _accum_0 = { } 361 local _accum_0 = { }
368 local _len_0 = 1
369 while false do 362 while false do
370 break 363 break
371 _len_0 = _len_0 + 1
372 end 364 end
373 return _accum_0 365 return _accum_0
374end 366end
diff --git a/spec/outputs/unicode/multiline_chain.lua b/spec/outputs/unicode/multiline_chain.lua
index c1da13f..61e7057 100644
--- a/spec/outputs/unicode/multiline_chain.lua
+++ b/spec/outputs/unicode/multiline_chain.lua
@@ -59,10 +59,8 @@ _u51fd_u6570 = function()
59 return _accum_0 59 return _accum_0
60end 60end
61local _anon_func_0 = function(_u53d8_u91cfa) 61local _anon_func_0 = function(_u53d8_u91cfa)
62 do 62 local _call_1 = _u53d8_u91cfa
63 local _call_1 = _u53d8_u91cfa 63 return (_call_1["变量b"](_call_1, 123))["变量c"]("abc")
64 return (_call_1["变量b"](_call_1, 123))["变量c"]("abc")
65 end
66end 64end
67local _u51fd_u65701 65local _u51fd_u65701
68_u51fd_u65701 = function() 66_u51fd_u65701 = function()
diff --git a/spec/outputs/unicode/syntax.lua b/spec/outputs/unicode/syntax.lua
index 1984f40..f5d5d8a 100644
--- a/spec/outputs/unicode/syntax.lua
+++ b/spec/outputs/unicode/syntax.lua
@@ -5,9 +5,9 @@ _u51fd_u6570(_u53c2_u65701, _u53c2_u65702, _u53e6_u5916, _u53c2_u65703)
5local _u6211_u4eec 5local _u6211_u4eec
6_u8fd9_u91cc, _u6211_u4eec = function() end, _u662f_u7684 6_u8fd9_u91cc, _u6211_u4eec = function() end, _u662f_u7684
7local _u8fd9_u4e2a, _u4e0d_u540c 7local _u8fd9_u4e2a, _u4e0d_u540c
8_u8fd9_u4e2a, _u4e0d_u540c = function() 8_u8fd9_u4e2a, _u4e0d_u540c = (function()
9 return _u65b9_u6cd5 9 return _u65b9_u6cd5
10end, _u662f_u7684 10end), _u662f_u7684
11_u7238_u7238() 11_u7238_u7238()
12_u7238_u7238(_u4e3b) 12_u7238_u7238(_u4e3b)
13_u4f60_u597d(_u4e00, _u4e8c)(); 13_u4f60_u597d(_u4e00, _u4e8c)();
@@ -286,10 +286,8 @@ _ = 5 - _u4ec0_u4e48(_u65e0_u804a)
286_u4ec0_u4e48(_u65e0_u804a - 5) 286_u4ec0_u4e48(_u65e0_u804a - 5)
287_u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269 287_u53d8_u91cfx = _u4f60_u597d - _u4e16_u754c - _u67d0_u7269
288local _anon_func_0 = function(_u4ec0_u4e48) 288local _anon_func_0 = function(_u4ec0_u4e48)
289 do 289 local _call_8 = _u4ec0_u4e48
290 local _call_8 = _u4ec0_u4e48 290 return _call_8["酷"](_call_8, 100)
291 return _call_8["酷"](_call_8, 100)
292 end
293end 291end
294(function(_u67d0_u7269) 292(function(_u67d0_u7269)
295 if _u67d0_u7269 == nil then 293 if _u67d0_u7269 == nil then
diff --git a/spec/outputs/unicode/vararg.lua b/spec/outputs/unicode/vararg.lua
index b837006..fc894ff 100644
--- a/spec/outputs/unicode/vararg.lua
+++ b/spec/outputs/unicode/vararg.lua
@@ -125,14 +125,10 @@ local _anon_func_11 = function(_u9879_u76ee, ...)
125 return _tbl_0 125 return _tbl_0
126end 126end
127local _anon_func_12 = function(_u51fd_u6570) 127local _anon_func_12 = function(_u51fd_u6570)
128 do 128 return _u51fd_u6570()
129 return _u51fd_u6570()
130 end
131end 129end
132local _anon_func_13 = function(_u51fd_u6570, ...) 130local _anon_func_13 = function(_u51fd_u6570, ...)
133 do 131 return _u51fd_u6570(...)
134 return _u51fd_u6570(...)
135 end
136end 132end
137local _anon_func_14 = function(_u51fd_u6570) 133local _anon_func_14 = function(_u51fd_u6570)
138 local _accum_0 = { } 134 local _accum_0 = { }
@@ -195,15 +191,11 @@ local _anon_func_23 = function(_u51fd_u6570, ...)
195 return nil 191 return nil
196end 192end
197local _anon_func_24 = function(_u6253_u5370, select, ...) 193local _anon_func_24 = function(_u6253_u5370, select, ...)
198 do 194 _u6253_u5370(select("#", ...))
199 _u6253_u5370(select("#", ...)) 195 return _u6253_u5370(...)
200 return _u6253_u5370(...)
201 end
202end 196end
203local _anon_func_25 = function(_u6253_u5370, ...) 197local _anon_func_25 = function(_u6253_u5370, ...)
204 do 198 return _u6253_u5370(...)
205 return _u6253_u5370(...)
206 end
207end 199end
208local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682) 200local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682)
209 if 1 == _u53d8_u91cfx then 201 if 1 == _u53d8_u91cfx then
@@ -214,9 +206,7 @@ local _anon_func_26 = function(_u53d8_u91cfx, _u8868, _u88682)
214 end 206 end
215end 207end
216local _anon_func_27 = function(_u6253_u5370, ...) 208local _anon_func_27 = function(_u6253_u5370, ...)
217 do 209 return _u6253_u5370(...)
218 return _u6253_u5370(...)
219 end
220end 210end
221local _anon_func_28 = function(_u6761_u4ef6) 211local _anon_func_28 = function(_u6761_u4ef6)
222 if _u6761_u4ef6 then 212 if _u6761_u4ef6 then
@@ -224,10 +214,8 @@ local _anon_func_28 = function(_u6761_u4ef6)
224 end 214 end
225end 215end
226local _anon_func_29 = function(_u6253_u5370, _arg_0, ...) 216local _anon_func_29 = function(_u6253_u5370, _arg_0, ...)
227 do 217 local _u8868 = _arg_0
228 local _u8868 = _arg_0 218 return _u6253_u5370(...)
229 return _u6253_u5370(...)
230 end
231end 219end
232local _u8fde_u63a5 220local _u8fde_u63a5
233_u8fde_u63a5 = function(...) 221_u8fde_u63a5 = function(...)
diff --git a/spec/outputs/unicode/whitespace.lua b/spec/outputs/unicode/whitespace.lua
index d026abb..7a83d9f 100644
--- a/spec/outputs/unicode/whitespace.lua
+++ b/spec/outputs/unicode/whitespace.lua
@@ -82,12 +82,12 @@ v = function()
82 return _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc 82 return _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc
83end 83end
84local v1, v2, v3 84local v1, v2, v3
85v1, v2, v3 = function() 85v1, v2, v3 = (function()
86 return _u53d8_u91cfa 86 return _u53d8_u91cfa
87end, _u53d8_u91cfb, _u53d8_u91cfc 87end), _u53d8_u91cfb, _u53d8_u91cfc
88local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc, _u53d8_u91cfd, _u53d8_u91cfe, _u53d8_u91cff = 1, f2({ 88local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc, _u53d8_u91cfd, _u53d8_u91cfe, _u53d8_u91cff = 1, (f2({
89 abc = abc 89 abc = abc
90}), 3, 4, _u51fd_u65705(abc), 6 90})), 3, 4, _u51fd_u65705(abc), 6
91for _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc in pairs(_u5bf9_u8c61tb) do 91for _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc in pairs(_u5bf9_u8c61tb) do
92 _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc) 92 _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc)
93end 93end
diff --git a/spec/outputs/upvalue_func.lua b/spec/outputs/upvalue_func.lua
index 3181adf..3e088be 100644
--- a/spec/outputs/upvalue_func.lua
+++ b/spec/outputs/upvalue_func.lua
@@ -214,10 +214,8 @@ local _anon_func_1 = function(valueB)
214 end 214 end
215end 215end
216local _anon_func_2 = function(print, select, _arg_0, ...) 216local _anon_func_2 = function(print, select, _arg_0, ...)
217 do 217 local ok = _arg_0
218 local ok = _arg_0 218 return print(select(3, ...))
219 return print(select(3, ...))
220 end
221end 219end
222local _anon_func_3 = function(tb) 220local _anon_func_3 = function(tb)
223 if tb ~= nil then 221 if tb ~= nil then
@@ -242,11 +240,9 @@ local _anon_func_5 = function(getmetatable, tb)
242 return _obj_0[1 + 1](_obj_0, "abc") 240 return _obj_0[1 + 1](_obj_0, "abc")
243end 241end
244local _anon_func_6 = function(tb) 242local _anon_func_6 = function(tb)
245 do 243 local _call_0 = tb
246 local _call_0 = tb 244 local _call_1 = _call_0["end"](_call_0)
247 local _call_1 = _call_0["end"](_call_0) 245 return _call_1["🤣"](_call_1, 123)
248 return _call_1["🤣"](_call_1, 123)
249 end
250end 246end
251local _anon_func_7 = function(itemA, listA) 247local _anon_func_7 = function(itemA, listA)
252 for _index_0 = 1, #listA do 248 for _index_0 = 1, #listA do
@@ -354,17 +350,13 @@ local _anon_func_16 = function(pairs, tb, tostring)
354 return _tbl_0 350 return _tbl_0
355end 351end
356local _anon_func_17 = function(print) 352local _anon_func_17 = function(print)
357 do 353 print(123)
358 print(123) 354 return "abc"
359 return "abc"
360 end
361end 355end
362local _anon_func_18 = function(print, select, _arg_0, ...) 356local _anon_func_18 = function(print, select, _arg_0, ...)
363 do 357 local success = _arg_0
364 local success = _arg_0 358 if success then
365 if success then 359 return print(select('#', ...))
366 return print(select('#', ...))
367 end
368 end 360 end
369end 361end
370local _anon_func_19 = function(cond, i) 362local _anon_func_19 = function(cond, i)
@@ -459,11 +451,9 @@ local _anon_func_25 = function(itemA, listA)
459 return false 451 return false
460end 452end
461local _anon_func_24 = function(itemA, listA, tb) 453local _anon_func_24 = function(itemA, listA, tb)
462 do 454 local _call_0 = tb
463 local _call_0 = tb 455 local _call_1 = _call_0["end"](_call_0)
464 local _call_1 = _call_0["end"](_call_0) 456 return _call_1["🤣"](_call_1, 123 and (#listA > 0 and _anon_func_25(itemA, listA)))
465 return _call_1["🤣"](_call_1, 123 and (#listA > 0 and _anon_func_25(itemA, listA)))
466 end
467end 457end
468GameEngine:onEvent("SomeEvent", function() 458GameEngine:onEvent("SomeEvent", function()
469 return func(value + (_anon_func_21(cond)) + (_anon_func_22(valueB)) > _anon_func_23(tb) + _anon_func_24(itemA, listA, tb)) 459 return func(value + (_anon_func_21(cond)) + (_anon_func_22(valueB)) > _anon_func_23(tb) + _anon_func_24(itemA, listA, tb))
@@ -503,13 +493,11 @@ local _anon_func_27 = function(char)
503 return nil 493 return nil
504end 494end
505local _anon_func_28 = function(os, _arg_0, ...) 495local _anon_func_28 = function(os, _arg_0, ...)
506 do 496 local ok = _arg_0
507 local ok = _arg_0 497 if ok then
508 if ok then 498 return ...
509 return ... 499 else
510 else 500 return os.exit(1)
511 return os.exit(1)
512 end
513 end 501 end
514end 502end
515local _anon_func_29 = function(debug_env_after, debug_env_before, env, func) 503local _anon_func_29 = function(debug_env_after, debug_env_before, env, func)
diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua
index dabba44..9f97681 100644
--- a/spec/outputs/vararg.lua
+++ b/spec/outputs/vararg.lua
@@ -125,14 +125,10 @@ local _anon_func_11 = function(items, ...)
125 return _tbl_0 125 return _tbl_0
126end 126end
127local _anon_func_12 = function(func) 127local _anon_func_12 = function(func)
128 do 128 return func()
129 return func()
130 end
131end 129end
132local _anon_func_13 = function(func, ...) 130local _anon_func_13 = function(func, ...)
133 do 131 return func(...)
134 return func(...)
135 end
136end 132end
137local _anon_func_14 = function(func) 133local _anon_func_14 = function(func)
138 local _accum_0 = { } 134 local _accum_0 = { }
@@ -195,15 +191,11 @@ local _anon_func_23 = function(func, ...)
195 return nil 191 return nil
196end 192end
197local _anon_func_24 = function(print, select, ...) 193local _anon_func_24 = function(print, select, ...)
198 do 194 print(select("#", ...))
199 print(select("#", ...)) 195 return print(...)
200 return print(...)
201 end
202end 196end
203local _anon_func_25 = function(print, ...) 197local _anon_func_25 = function(print, ...)
204 do 198 return print(...)
205 return print(...)
206 end
207end 199end
208local _anon_func_26 = function(tb, tb2, x) 200local _anon_func_26 = function(tb, tb2, x)
209 if 1 == x then 201 if 1 == x then
@@ -214,9 +206,7 @@ local _anon_func_26 = function(tb, tb2, x)
214 end 206 end
215end 207end
216local _anon_func_27 = function(print, ...) 208local _anon_func_27 = function(print, ...)
217 do 209 return print(...)
218 return print(...)
219 end
220end 210end
221local _anon_func_28 = function(cond) 211local _anon_func_28 = function(cond)
222 if cond then 212 if cond then
@@ -224,10 +214,8 @@ local _anon_func_28 = function(cond)
224 end 214 end
225end 215end
226local _anon_func_29 = function(print, _arg_0, ...) 216local _anon_func_29 = function(print, _arg_0, ...)
227 do 217 local tb = _arg_0
228 local tb = _arg_0 218 return print(...)
229 return print(...)
230 end
231end 219end
232local join 220local join
233join = function(...) 221join = function(...)
@@ -306,3 +294,75 @@ join = function(...)
306 end 294 end
307 return nil 295 return nil
308end 296end
297do
298 local f1
299 f1 = function(...)
300 local t = {
301 n = select("#", ...),
302 ...
303 }
304 print(t.n)
305 print(#t)
306 for i = 1, t.n do
307 print(t[i])
308 end
309 end
310 f1(1, 2, 3)
311 f1("a", "b", "c", "d")
312 f1()
313 local f2
314 f2 = function(...)
315 local args = {
316 n = select("#", ...),
317 ...
318 }
319 print("args count:", args.n)
320 print("args length:", #args)
321 for i = 1, args.n do
322 if args[i] == nil then
323 print("position", i, "is nil")
324 else
325 print("position", i, ":", args[i])
326 end
327 end
328 end
329 f2(1, nil, 3, nil, 5)
330 local f3
331 f3 = function(prefix, ...)
332 local items = {
333 n = select("#", ...),
334 ...
335 }
336 local result = { }
337 for i = 1, items.n do
338 result[i] = prefix .. tostring(items[i])
339 end
340 return result
341 end
342 f3("item_", 1, 2, 3)
343 local f4
344 f4 = function(...)
345 local empty = {
346 n = select("#", ...),
347 ...
348 }
349 print("empty count:", empty.n)
350 return print("empty length:", #empty)
351 end
352 f4()
353 local process
354 process = function(...)
355 local data = {
356 n = select("#", ...),
357 ...
358 }
359 local sum = 0
360 for i = 1, data.n do
361 if type(data[i]) == "number" then
362 sum = sum + data[i]
363 end
364 end
365 return sum
366 end
367 return process(1, 2, 3, "skip", 5)
368end
diff --git a/spec/outputs/whitespace.lua b/spec/outputs/whitespace.lua
index 0251968..864f085 100644
--- a/spec/outputs/whitespace.lua
+++ b/spec/outputs/whitespace.lua
@@ -94,12 +94,12 @@ v = function()
94 return a, b, c 94 return a, b, c
95end 95end
96local v1, v2, v3 96local v1, v2, v3
97v1, v2, v3 = function() 97v1, v2, v3 = (function()
98 return a 98 return a
99end, b, c 99end), b, c
100local a, b, c, d, e, f = 1, f2({ 100local a, b, c, d, e, f = 1, (f2({
101 abc = abc 101 abc = abc
102}), 3, 4, f5(abc), 6 102})), 3, 4, f5(abc), 6
103for a, b, c in pairs(tb) do 103for a, b, c in pairs(tb) do
104 print(a, b, c) 104 print(a, b, c)
105end 105end
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua
index 1a795c1..530915e 100644
--- a/spec/outputs/with.lua
+++ b/spec/outputs/with.lua
@@ -187,4 +187,66 @@ do
187 return _with_0[123] 187 return _with_0[123]
188 end 188 end
189end 189end
190do
191 f((function()
192 local _with_0 = item
193 do
194 local _accum_0
195 repeat
196 if _with_0.id > 0 then
197 _accum_0 = _with_0.content
198 break
199 end
200 until true
201 _with_0 = _accum_0
202 end
203 return _with_0
204 end)())
205 local a
206 do
207 local _with_0 = tb
208 do
209 local _accum_0
210 repeat
211 if _with_0.v then
212 _accum_0 = _with_0.a
213 break
214 end
215 until true
216 _with_0 = _accum_0
217 end
218 a = _with_0
219 end
220 local _accum_0
221 while true do
222 local _with_0 = tb
223 local _accum_1
224 repeat
225 if _with_0 ~= nil then
226 _accum_1 = 1
227 break
228 end
229 until true
230 _with_0 = _accum_1
231 _accum_0 = _with_0
232 break
233 end
234 a = _accum_0
235end
236do
237 local a
238 local _accum_0
239 for i = 1, 100 do
240 local x = tb[i]
241 if x ~= nil then
242 local _des_0 = 1
243 if _des_0 then
244 x.id = _des_0
245 _accum_0 = x
246 break
247 end
248 end
249 end
250 a = _accum_0
251end
190return nil 252return nil