diff options
author | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
commit | 60a979e224f26117f5be82bfca757a2483cef0fd (patch) | |
tree | 7c6af44f6dcada1f23979b820ba830251997b161 /spec/outputs/destructure.lua | |
parent | a19b242cbaf53721b20a3163dd06f43e9ef2b487 (diff) | |
download | yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.gz yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.bz2 yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.zip |
fix test.
Diffstat (limited to 'spec/outputs/destructure.lua')
-rw-r--r-- | spec/outputs/destructure.lua | 357 |
1 files changed, 357 insertions, 0 deletions
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua new file mode 100644 index 0000000..9ca13c8 --- /dev/null +++ b/spec/outputs/destructure.lua | |||
@@ -0,0 +1,357 @@ | |||
1 | do | ||
2 | local a, b | ||
3 | do | ||
4 | local _obj_0 = hello | ||
5 | a, b = _obj_0[1], _obj_0[2] | ||
6 | end | ||
7 | local c | ||
8 | do | ||
9 | local _obj_0 = hello | ||
10 | a, b, c = _obj_0[1][1], _obj_0[2], _obj_0[3][1] | ||
11 | end | ||
12 | local hello, world | ||
13 | do | ||
14 | local _obj_0 = value | ||
15 | hello, world = _obj_0.hello, _obj_0.world | ||
16 | end | ||
17 | end | ||
18 | do | ||
19 | local no, thing | ||
20 | do | ||
21 | local _obj_0 = world | ||
22 | no, thing = _obj_0.yes, _obj_0[1] | ||
23 | end | ||
24 | local a, b, c, d | ||
25 | do | ||
26 | local _obj_0 = yeah | ||
27 | a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d | ||
28 | end | ||
29 | local _ = two | ||
30 | a = one[1] | ||
31 | c = nil | ||
32 | b = one[1] | ||
33 | local e = two | ||
34 | d = one[1] | ||
35 | local x = one | ||
36 | local y = two[1] | ||
37 | local xx, yy = 1, 2 | ||
38 | do | ||
39 | local _obj_0 = { | ||
40 | xx, | ||
41 | yy | ||
42 | } | ||
43 | yy, xx = _obj_0[1], _obj_0[2] | ||
44 | end | ||
45 | local f, g | ||
46 | do | ||
47 | local _obj_0 = tbl | ||
48 | a, b, c, d, e, f, g = _obj_0[1], _obj_0.b, _obj_0[2], _obj_0.d, _obj_0[3], _obj_0.f, _obj_0[4] | ||
49 | end | ||
50 | do | ||
51 | c = nil | ||
52 | do | ||
53 | local _obj_0 = tbl | ||
54 | a, b = _obj_0.a, _obj_0.b | ||
55 | end | ||
56 | end | ||
57 | do | ||
58 | a = tbl | ||
59 | b, c = _.b, _.c | ||
60 | end | ||
61 | do | ||
62 | b = _ | ||
63 | a = tbl.a | ||
64 | c = _.c | ||
65 | end | ||
66 | end | ||
67 | do | ||
68 | local futurists = { | ||
69 | sculptor = "Umberto Boccioni", | ||
70 | painter = "Vladimir Burliuk", | ||
71 | poet = { | ||
72 | name = "F.T. Marinetti", | ||
73 | address = { | ||
74 | "Via Roma 42R", | ||
75 | "Bellagio, Italy 22021" | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | do | ||
80 | local name, street, city = futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2] | ||
81 | end | ||
82 | do | ||
83 | local sculptor, painter, name, street, city = futurists.sculptor, futurists.painter, futurists.poet.name, futurists.poet.address[1], futurists.poet.address[2] | ||
84 | end | ||
85 | end | ||
86 | do | ||
87 | local c, e | ||
88 | do | ||
89 | local _obj_0 = tb | ||
90 | c, e = _obj_0.a.b, _obj_0.a.d | ||
91 | end | ||
92 | end | ||
93 | do | ||
94 | local c, e, f | ||
95 | do | ||
96 | local _obj_0 = tb | ||
97 | c, e, f = _obj_0.a[1].b, _obj_0.a[2].d, _obj_0.a[3] | ||
98 | end | ||
99 | end | ||
100 | do | ||
101 | self.world = x[1] | ||
102 | do | ||
103 | local _obj_0 = x | ||
104 | a.b, c.y, func().z = _obj_0[1], _obj_0[2], _obj_0[3] | ||
105 | end | ||
106 | self.world = x.world | ||
107 | end | ||
108 | do | ||
109 | local thing = { | ||
110 | { | ||
111 | 1, | ||
112 | 2 | ||
113 | }, | ||
114 | { | ||
115 | 3, | ||
116 | 4 | ||
117 | } | ||
118 | } | ||
119 | for _index_0 = 1, #thing do | ||
120 | local _des_0 = thing[_index_0] | ||
121 | local x, y = _des_0[1], _des_0[2] | ||
122 | print(x, y) | ||
123 | end | ||
124 | end | ||
125 | do | ||
126 | do | ||
127 | local _with_0 = thing | ||
128 | local a, b = _with_0[1], _with_0[2] | ||
129 | print(a, b) | ||
130 | end | ||
131 | end | ||
132 | do | ||
133 | local thing = nil | ||
134 | if thing then | ||
135 | local a = thing[1] | ||
136 | print(a) | ||
137 | else | ||
138 | print("nothing") | ||
139 | end | ||
140 | local thang = { | ||
141 | 1, | ||
142 | 2 | ||
143 | } | ||
144 | if thang then | ||
145 | local a, b = thang[1], thang[2] | ||
146 | print(a, b) | ||
147 | end | ||
148 | if thing then | ||
149 | local a, b = thing[1], thing[2] | ||
150 | print(a, b) | ||
151 | else | ||
152 | if thang then | ||
153 | local c, d = thang[1], thang[2] | ||
154 | print(c, d) | ||
155 | else | ||
156 | print("NO") | ||
157 | end | ||
158 | end | ||
159 | end | ||
160 | do | ||
161 | local z = "yeah" | ||
162 | local a, b, c = z[1], z[2], z[3] | ||
163 | end | ||
164 | do | ||
165 | local a, b, c | ||
166 | do | ||
167 | local _obj_0 = z | ||
168 | a, b, c = _obj_0[1], _obj_0[2], _obj_0[3] | ||
169 | end | ||
170 | end | ||
171 | local _ | ||
172 | _ = function(z) | ||
173 | local a, b, c = z[1], z[2], z[3] | ||
174 | end | ||
175 | do | ||
176 | local z = "oo" | ||
177 | _ = function(k) | ||
178 | local a, b, c = z[1], z[2], z[3] | ||
179 | end | ||
180 | end | ||
181 | do | ||
182 | local endVar = thing["function"]["end"] | ||
183 | end | ||
184 | do | ||
185 | local a, b, c | ||
186 | do | ||
187 | local _obj_0 = thing | ||
188 | a, b, c = _obj_0["if"][1], _obj_0["if"][2], _obj_0["if"][3] | ||
189 | end | ||
190 | end | ||
191 | do | ||
192 | local a, b | ||
193 | if true then | ||
194 | do | ||
195 | local _obj_0 = { | ||
196 | a = "Hello", | ||
197 | b = "World" | ||
198 | } | ||
199 | a, b = _obj_0.a, _obj_0.b | ||
200 | end | ||
201 | end | ||
202 | local days, hours, mins, secs | ||
203 | do | ||
204 | local _accum_0 = { } | ||
205 | local _len_0 = 1 | ||
206 | local _list_0 = { | ||
207 | string.match("1 2 3 4", "(.+)%s(.+)%s(.+)%s(.+)") | ||
208 | } | ||
209 | for _index_0 = 1, #_list_0 do | ||
210 | local a = _list_0[_index_0] | ||
211 | _accum_0[_len_0] = tonumber(a) | ||
212 | _len_0 = _len_0 + 1 | ||
213 | end | ||
214 | days, hours, mins, secs = _accum_0[1], _accum_0[2], _accum_0[3], _accum_0[4] | ||
215 | end | ||
216 | local one, two, three | ||
217 | do | ||
218 | local _tbl_0 = { } | ||
219 | for w in foo:gmatch("%S+") do | ||
220 | _tbl_0[w] = true | ||
221 | end | ||
222 | one, two, three = _tbl_0.one, _tbl_0.two, _tbl_0.three | ||
223 | end | ||
224 | b = 123 | ||
225 | a = (a["if"](a, 123) + t).a | ||
226 | end | ||
227 | do | ||
228 | local name, job | ||
229 | do | ||
230 | local _obj_0 = person | ||
231 | name, job = _obj_0.name, _obj_0.job | ||
232 | end | ||
233 | if name == nil then | ||
234 | name = "nameless" | ||
235 | end | ||
236 | if job == nil then | ||
237 | job = "jobless" | ||
238 | end | ||
239 | local request | ||
240 | request = function(url, options) | ||
241 | if options == nil then | ||
242 | options = { } | ||
243 | end | ||
244 | local method, headers, parameters, payload, ok, err, final = options.method, options.headers, options.parameters, options.payload, options.ok, options.err, options.final | ||
245 | if method == nil then | ||
246 | method = "GET" | ||
247 | end | ||
248 | if headers == nil then | ||
249 | headers = { } | ||
250 | end | ||
251 | if parameters == nil then | ||
252 | parameters = { } | ||
253 | end | ||
254 | if payload == nil then | ||
255 | payload = "" | ||
256 | end | ||
257 | local res = makeRequest(url, method, parameters, payload, ok, err, final) | ||
258 | return res | ||
259 | end | ||
260 | local value1, key3 | ||
261 | do | ||
262 | local _obj_0 = tb | ||
263 | value1, key3 = _obj_0.key1.key2, _obj_0.key3 | ||
264 | end | ||
265 | if value1 == nil then | ||
266 | value1 = 123 | ||
267 | end | ||
268 | if key3 == nil then | ||
269 | key3 = "abc" | ||
270 | end | ||
271 | local mt, call, add | ||
272 | do | ||
273 | local _obj_0 = getmetatable(tb) | ||
274 | mt, call, add = _obj_0, getmetatable(_obj_0).__call, getmetatable(_obj_0).__add | ||
275 | end | ||
276 | if mt == nil then | ||
277 | mt = { | ||
278 | __index = { | ||
279 | abc = 123 | ||
280 | } | ||
281 | } | ||
282 | end | ||
283 | if call == nil then | ||
284 | call = (function() | ||
285 | return { } | ||
286 | end) | ||
287 | end | ||
288 | local _obj_0 = tb | ||
289 | local mtx, y, zItem = getmetatable(_obj_0.x), _obj_0.y, _obj_0.z | ||
290 | if mtx == nil then | ||
291 | mtx = { } | ||
292 | end | ||
293 | local index = getmetatable(_obj_0).__index | ||
294 | if index == nil then | ||
295 | index = function() | ||
296 | return nil | ||
297 | end | ||
298 | end | ||
299 | local _obj_1 = getmetatable(tb).func | ||
300 | if _obj_1 == nil then | ||
301 | if item ~= nil then | ||
302 | _obj_1 = item.defVal | ||
303 | end | ||
304 | end | ||
305 | a.b(function() | ||
306 | return 123 | ||
307 | end).c = _obj_1 | ||
308 | end | ||
309 | do | ||
310 | local mt, subFunc | ||
311 | do | ||
312 | local _obj_0 = getmetatable(tb.x) | ||
313 | mt, subFunc = _obj_0, _obj_0.__sub | ||
314 | end | ||
315 | if mt == nil then | ||
316 | mt = { } | ||
317 | end | ||
318 | end | ||
319 | do | ||
320 | local mt, subFunc | ||
321 | do | ||
322 | local _obj_0 = tb | ||
323 | mt, subFunc = getmetatable(_obj_0.x), getmetatable(_obj_0.x).__sub | ||
324 | end | ||
325 | if mt == nil then | ||
326 | mt = { } | ||
327 | end | ||
328 | end | ||
329 | do | ||
330 | local a, b, _obj_0 | ||
331 | do | ||
332 | local _obj_1 = tb | ||
333 | a, b, _obj_0 = _obj_1[1], _obj_1[2], _obj_1.c[1] | ||
334 | end | ||
335 | if a == nil then | ||
336 | a = 1 | ||
337 | end | ||
338 | if b == nil then | ||
339 | b = 2 | ||
340 | end | ||
341 | if _obj_0 == nil then | ||
342 | _obj_0 = 3 | ||
343 | end | ||
344 | d.e = _obj_0 | ||
345 | local _list_0 = tuples | ||
346 | for _index_0 = 1, #_list_0 do | ||
347 | local _des_0 = _list_0[_index_0] | ||
348 | local left, right = _des_0[1], _des_0[2] | ||
349 | if left == nil then | ||
350 | left = "null" | ||
351 | end | ||
352 | if right == nil then | ||
353 | right = false | ||
354 | end | ||
355 | print(left, right) | ||
356 | end | ||
357 | end | ||