aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/destructure.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-07-12 17:41:19 +0800
committerLi Jin <dragon-fly@qq.com>2022-07-12 17:41:19 +0800
commit68e167e9f0b90968ea67b7f21fdc50a48d129173 (patch)
tree64612476c7cc5636d7a9eea68ea1e5b449bb9732 /spec/outputs/destructure.lua
parent1a7c8e3c38fcf0af94ca799a3cd9fa7c4ef1bf08 (diff)
downloadyuescript-68e167e9f0b90968ea67b7f21fdc50a48d129173.tar.gz
yuescript-68e167e9f0b90968ea67b7f21fdc50a48d129173.tar.bz2
yuescript-68e167e9f0b90968ea67b7f21fdc50a48d129173.zip
add table pattern matching syntax and fix issue #93, remove a confusing default value syntax for destructuring.
Diffstat (limited to 'spec/outputs/destructure.lua')
-rw-r--r--spec/outputs/destructure.lua121
1 files changed, 71 insertions, 50 deletions
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua
index 9b16181..2fe4ba9 100644
--- a/spec/outputs/destructure.lua
+++ b/spec/outputs/destructure.lua
@@ -229,12 +229,12 @@ do
229 do 229 do
230 local _obj_0 = person 230 local _obj_0 = person
231 name, job = _obj_0.name, _obj_0.job 231 name, job = _obj_0.name, _obj_0.job
232 end 232 if name == nil then
233 if name == nil then 233 name = "nameless"
234 name = "nameless" 234 end
235 end 235 if job == nil then
236 if job == nil then 236 job = "jobless"
237 job = "jobless" 237 end
238 end 238 end
239 local request 239 local request
240 request = function(url, options) 240 request = function(url, options)
@@ -261,29 +261,29 @@ do
261 do 261 do
262 local _obj_0 = tb 262 local _obj_0 = tb
263 value1, key3 = _obj_0.key1.key2, _obj_0.key3 263 value1, key3 = _obj_0.key1.key2, _obj_0.key3
264 end 264 if value1 == nil then
265 if value1 == nil then 265 value1 = 123
266 value1 = 123 266 end
267 end 267 if key3 == nil then
268 if key3 == nil then 268 key3 = "abc"
269 key3 = "abc" 269 end
270 end 270 end
271 local mt, call, add 271 local mt, call, add
272 do 272 do
273 local _obj_0 = getmetatable(tb) 273 local _obj_0 = getmetatable(tb)
274 mt, call, add = _obj_0, getmetatable(_obj_0).__call, getmetatable(_obj_0).__add 274 mt, call, add = _obj_0, getmetatable(_obj_0).__call, getmetatable(_obj_0).__add
275 end 275 if mt == nil then
276 if mt == nil then 276 mt = {
277 mt = { 277 __index = {
278 __index = { 278 abc = 123
279 abc = 123 279 }
280 } 280 }
281 } 281 end
282 end 282 if call == nil then
283 if call == nil then 283 call = (function()
284 call = (function() 284 return { }
285 return { } 285 end)
286 end) 286 end
287 end 287 end
288 local _obj_0 = tb 288 local _obj_0 = tb
289 local mtx, y, zItem = getmetatable(_obj_0.x), _obj_0.y, _obj_0.z 289 local mtx, y, zItem = getmetatable(_obj_0.x), _obj_0.y, _obj_0.z
@@ -296,27 +296,33 @@ do
296 return nil 296 return nil
297 end 297 end
298 end 298 end
299 local _obj_1 = getmetatable(tb).func 299 do
300 if _obj_1 == nil then 300 local _tmp_0
301 do 301 do
302 local _obj_2 = item 302 local _obj_1 = getmetatable(tb)
303 if _obj_2 ~= nil then 303 _tmp_0 = _obj_1.func
304 _obj_1 = _obj_2.defVal 304 end
305 if _tmp_0 == nil then
306 do
307 local _obj_1 = item
308 if _obj_1 ~= nil then
309 _tmp_0 = _obj_1.defVal
310 end
305 end 311 end
306 end 312 end
307 end 313 a.b(function()
308 a.b(function()
309 return 123 314 return 123
310 end).c = _obj_1 315 end).c = _tmp_0
316 end
311end 317end
312do 318do
313 local mt, subFunc 319 local mt, subFunc
314 do 320 do
315 local _obj_0 = getmetatable(tb.x) 321 local _obj_0 = getmetatable(tb.x)
316 mt, subFunc = _obj_0, _obj_0.__sub 322 mt, subFunc = _obj_0, _obj_0.__sub
317 end 323 if mt == nil then
318 if mt == nil then 324 mt = { }
319 mt = { } 325 end
320 end 326 end
321end 327end
322do 328do
@@ -324,27 +330,28 @@ do
324 do 330 do
325 local _obj_0 = tb 331 local _obj_0 = tb
326 mt, subFunc = getmetatable(_obj_0.x), getmetatable(_obj_0.x).__sub 332 mt, subFunc = getmetatable(_obj_0.x), getmetatable(_obj_0.x).__sub
327 end 333 if mt == nil then
328 if mt == nil then 334 mt = { }
329 mt = { } 335 end
330 end 336 end
331end 337end
332do 338do
333 local a, b, _obj_0 339 local a, b
334 do 340 do
335 local _obj_1 = tb 341 local _obj_0 = tb
336 a, b, _obj_0 = _obj_1[1], _obj_1[2], _obj_1.c[1] 342 local _tmp_0
337 end 343 a, b, _tmp_0 = _obj_0[1], _obj_0[2], _obj_0.c[1]
338 if a == nil then 344 if a == nil then
339 a = 1 345 a = 1
340 end 346 end
341 if b == nil then 347 if b == nil then
342 b = 2 348 b = 2
343 end 349 end
344 if _obj_0 == nil then 350 if _tmp_0 == nil then
345 _obj_0 = 3 351 _tmp_0 = 3
352 end
353 d.e = _tmp_0
346 end 354 end
347 d.e = _obj_0
348 local _list_0 = tuples 355 local _list_0 = tuples
349 for _index_0 = 1, #_list_0 do 356 for _index_0 = 1, #_list_0 do
350 local _des_0 = _list_0[_index_0] 357 local _des_0 = _list_0[_index_0]
@@ -365,3 +372,17 @@ do
365 a, b = _obj_0[2], _obj_0[4] 372 a, b = _obj_0[2], _obj_0[4]
366 end 373 end
367end 374end
375do
376 do
377 local _obj_0 = x.x.x
378 local _tmp_0, _tmp_1 = _obj_0.x, _obj_0.y
379 if _tmp_0 == nil then
380 _tmp_0 = 1
381 end
382 if _tmp_1 == nil then
383 _tmp_1 = 2
384 end
385 a.b = _tmp_0
386 a.c = _tmp_1
387 end
388end