diff options
| author | Li Jin <dragon-fly@qq.com> | 2023-10-27 16:58:43 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2023-10-27 16:58:43 +0800 |
| commit | 7bfa002f3d4dcb62e6a301141be6d17889a94f55 (patch) | |
| tree | 927eab759af3e333b1f7d80c3724ec4b869c02e1 /spec | |
| parent | bafe9b44212316a51ee00f7af15e881c81d96fe6 (diff) | |
| download | yuescript-7bfa002f3d4dcb62e6a301141be6d17889a94f55.tar.gz yuescript-7bfa002f3d4dcb62e6a301141be6d17889a94f55.tar.bz2 yuescript-7bfa002f3d4dcb62e6a301141be6d17889a94f55.zip | |
fix a missing case for list destructuring.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/destructure.yue | 8 | ||||
| -rw-r--r-- | spec/outputs/destructure.lua | 24 |
2 files changed, 32 insertions, 0 deletions
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index d161fd8..73e4d33 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue | |||
| @@ -80,6 +80,8 @@ do | |||
| 80 | for {x,y} in *thing | 80 | for {x,y} in *thing |
| 81 | print x,y | 81 | print x,y |
| 82 | 82 | ||
| 83 | for [x,y] in *thing | ||
| 84 | print x,y | ||
| 83 | 85 | ||
| 84 | -- | 86 | -- |
| 85 | 87 | ||
| @@ -178,10 +180,16 @@ do | |||
| 178 | for {left = "null", right = false} in *tuples | 180 | for {left = "null", right = false} in *tuples |
| 179 | print left, right | 181 | print left, right |
| 180 | 182 | ||
| 183 | for [left = "null", right = false] in *tuples | ||
| 184 | print left, right | ||
| 185 | |||
| 181 | do | 186 | do |
| 182 | {_, a, _, b} = tb -- list placeholder | 187 | {_, a, _, b} = tb -- list placeholder |
| 183 | 188 | ||
| 184 | do | 189 | do |
| 190 | [a, _, b, _] = tb -- list placeholder | ||
| 191 | |||
| 192 | do | ||
| 185 | {x: a.b = 1, y: a.c = 2} = x.x.x | 193 | {x: a.b = 1, y: a.c = 2} = x.x.x |
| 186 | 194 | ||
| 187 | do | 195 | do |
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 25e0529..38f21ff 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua | |||
| @@ -124,6 +124,11 @@ do | |||
| 124 | local x, y = _des_0[1], _des_0[2] | 124 | local x, y = _des_0[1], _des_0[2] |
| 125 | print(x, y) | 125 | print(x, y) |
| 126 | end | 126 | end |
| 127 | for _index_0 = 1, #thing do | ||
| 128 | local _des_0 = thing[_index_0] | ||
| 129 | local x, y = _des_0[1], _des_0[2] | ||
| 130 | print(x, y) | ||
| 131 | end | ||
| 127 | end | 132 | end |
| 128 | do | 133 | do |
| 129 | do | 134 | do |
| @@ -370,6 +375,18 @@ do | |||
| 370 | end | 375 | end |
| 371 | print(left, right) | 376 | print(left, right) |
| 372 | end | 377 | end |
| 378 | local _list_1 = tuples | ||
| 379 | for _index_0 = 1, #_list_1 do | ||
| 380 | local _des_0 = _list_1[_index_0] | ||
| 381 | local left, right = _des_0[1], _des_0[2] | ||
| 382 | if left == nil then | ||
| 383 | left = "null" | ||
| 384 | end | ||
| 385 | if right == nil then | ||
| 386 | right = false | ||
| 387 | end | ||
| 388 | print(left, right) | ||
| 389 | end | ||
| 373 | end | 390 | end |
| 374 | do | 391 | do |
| 375 | local a, b | 392 | local a, b |
| @@ -379,6 +396,13 @@ do | |||
| 379 | end | 396 | end |
| 380 | end | 397 | end |
| 381 | do | 398 | do |
| 399 | local a, b | ||
| 400 | do | ||
| 401 | local _obj_0 = tb | ||
| 402 | a, b = _obj_0[1], _obj_0[3] | ||
| 403 | end | ||
| 404 | end | ||
| 405 | do | ||
| 382 | do | 406 | do |
| 383 | local _obj_0 = x.x.x | 407 | local _obj_0 = x.x.x |
| 384 | local _tmp_0, _tmp_1 = _obj_0.x, _obj_0.y | 408 | local _tmp_0, _tmp_1 = _obj_0.x, _obj_0.y |
