From 5ad0f4daa8171460dc71332669c365bb8e07dab0 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 2 Nov 2023 12:27:27 +0800 Subject: fix table matching syntax in switch statement with list table. --- spec/inputs/switch.yue | 6 ++++++ spec/outputs/switch.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'spec') diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue index cb1eb31..49d47f3 100644 --- a/spec/inputs/switch.yue +++ b/spec/inputs/switch.yue @@ -159,5 +159,11 @@ do when {x: <>: mt} print mt +do + switch tb + when [ [item,],] + print item + when [a = 1, b = "abc"] + print a, b nil diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index 1ace1e3..bbdf794 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua @@ -398,4 +398,39 @@ do end end end +do + do + local _exp_0 = tb + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local item + do + local _obj_0 = _exp_0[1] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + item = _obj_0[1] + end + end + if item ~= nil then + _match_0 = true + print(item) + end + end + if not _match_0 then + if _tab_0 then + local a = _exp_0[1] + local b = _exp_0[2] + if a == nil then + a = 1 + end + if b == nil then + b = "abc" + end + print(a, b) + end + end + end +end return nil -- cgit v1.2.3-55-g6feb