diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-10-31 17:29:45 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-10-31 17:29:45 +0800 |
| commit | aed806476fe50899c0f01750175531ac41267b9d (patch) | |
| tree | c46f212a2987a9088b03e2c0225f18cd9a5d4265 /spec | |
| parent | 60a979e224f26117f5be82bfca757a2483cef0fd (diff) | |
| download | yuescript-aed806476fe50899c0f01750175531ac41267b9d.tar.gz yuescript-aed806476fe50899c0f01750175531ac41267b9d.tar.bz2 yuescript-aed806476fe50899c0f01750175531ac41267b9d.zip | |
partially fix issue #69, fix a few case the generated code leaks some temp variables.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/nil_coalesing.yue | 40 | ||||
| -rw-r--r-- | spec/outputs/export.lua | 32 | ||||
| -rw-r--r-- | spec/outputs/multiline_chain.lua | 12 | ||||
| -rw-r--r-- | spec/outputs/nil_coalesing.lua | 138 | ||||
| -rw-r--r-- | spec/outputs/switch.lua | 110 |
5 files changed, 266 insertions, 66 deletions
diff --git a/spec/inputs/nil_coalesing.yue b/spec/inputs/nil_coalesing.yue new file mode 100644 index 0000000..45b34f4 --- /dev/null +++ b/spec/inputs/nil_coalesing.yue | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | do | ||
| 2 | a = b ?? c | ||
| 3 | |||
| 4 | do | ||
| 5 | :a = b ?? c | ||
| 6 | |||
| 7 | do | ||
| 8 | a = func! | ||
| 9 | a ??= false | ||
| 10 | |||
| 11 | do | ||
| 12 | a ??= func! | ||
| 13 | |||
| 14 | do | ||
| 15 | local a, b, c, d, e | ||
| 16 | a = b ?? c ?? d ?? e | ||
| 17 | |||
| 18 | do | ||
| 19 | a = b ?? c ?? d ?? e | ||
| 20 | |||
| 21 | do | ||
| 22 | func x ?? "hello" | ||
| 23 | |||
| 24 | do | ||
| 25 | with funcA! ?? funcB! | ||
| 26 | print .field | ||
| 27 | |||
| 28 | do | ||
| 29 | a = 1 + 2 + b ?? c + 3 + 4 | ||
| 30 | |||
| 31 | do | ||
| 32 | a = 1 + 2 + (b ?? c) + 3 + 4 | ||
| 33 | |||
| 34 | do | ||
| 35 | :a, :b = func! | ||
| 36 | a or= 1 | ||
| 37 | b ??= c ?? 2 | ||
| 38 | |||
| 39 | nil | ||
| 40 | |||
diff --git a/spec/outputs/export.lua b/spec/outputs/export.lua index 02546ec..4d81cc0 100644 --- a/spec/outputs/export.lua +++ b/spec/outputs/export.lua | |||
| @@ -65,22 +65,26 @@ y = function() | |||
| 65 | local k = 100 | 65 | local k = 100 |
| 66 | end | 66 | end |
| 67 | _module_0["y"] = y | 67 | _module_0["y"] = y |
| 68 | local _exp_0 = h | 68 | do |
| 69 | if 100 == _exp_0 or 150 == _exp_0 then | 69 | local _exp_0 = h |
| 70 | _module_0[#_module_0 + 1] = 200 | 70 | if 100 == _exp_0 or 150 == _exp_0 then |
| 71 | elseif 200 == _exp_0 then | 71 | _module_0[#_module_0 + 1] = 200 |
| 72 | _module_0[#_module_0 + 1] = 300 | 72 | elseif 200 == _exp_0 then |
| 73 | else | 73 | _module_0[#_module_0 + 1] = 300 |
| 74 | _module_0[#_module_0 + 1] = 0 | 74 | else |
| 75 | _module_0[#_module_0 + 1] = 0 | ||
| 76 | end | ||
| 75 | end | 77 | end |
| 76 | local Constant | 78 | local Constant |
| 77 | local _exp_1 = value | 79 | do |
| 78 | if "good" == _exp_1 then | 80 | local _exp_0 = value |
| 79 | Constant = 1 | 81 | if "good" == _exp_0 then |
| 80 | elseif "better" == _exp_1 then | 82 | Constant = 1 |
| 81 | Constant = 2 | 83 | elseif "better" == _exp_0 then |
| 82 | elseif "best" == _exp_1 then | 84 | Constant = 2 |
| 83 | Constant = 3 | 85 | elseif "best" == _exp_0 then |
| 86 | Constant = 3 | ||
| 87 | end | ||
| 84 | end | 88 | end |
| 85 | _module_0["Constant"] = Constant | 89 | _module_0["Constant"] = Constant |
| 86 | local item = func(123) | 90 | local item = func(123) |
diff --git a/spec/outputs/multiline_chain.lua b/spec/outputs/multiline_chain.lua index fea7bc6..ecd2ca8 100644 --- a/spec/outputs/multiline_chain.lua +++ b/spec/outputs/multiline_chain.lua | |||
| @@ -56,11 +56,13 @@ do | |||
| 56 | _with_0:callMethod():chainCall() | 56 | _with_0:callMethod():chainCall() |
| 57 | _with_0:callMethod():chainCall() | 57 | _with_0:callMethod():chainCall() |
| 58 | _with_0:chainCall() | 58 | _with_0:chainCall() |
| 59 | local _exp_0 = _with_0.itemFieldB:getValue() | 59 | do |
| 60 | if "Valid" == _exp_0 or _with_0:getItemState() == _exp_0 then | 60 | local _exp_0 = _with_0.itemFieldB:getValue() |
| 61 | _with_0:itemMethodA():getValue() | 61 | if "Valid" == _exp_0 or _with_0:getItemState() == _exp_0 then |
| 62 | else | 62 | _with_0:itemMethodA():getValue() |
| 63 | _with_0:itemMethodB():getValue() | 63 | else |
| 64 | _with_0:itemMethodB():getValue() | ||
| 65 | end | ||
| 64 | end | 66 | end |
| 65 | local a | 67 | local a |
| 66 | if _with_0.itemFieldC then | 68 | if _with_0.itemFieldC then |
diff --git a/spec/outputs/nil_coalesing.lua b/spec/outputs/nil_coalesing.lua new file mode 100644 index 0000000..36a6644 --- /dev/null +++ b/spec/outputs/nil_coalesing.lua | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | do | ||
| 2 | local a | ||
| 3 | do | ||
| 4 | local _exp_0 = b | ||
| 5 | if _exp_0 ~= nil then | ||
| 6 | a = _exp_0 | ||
| 7 | else | ||
| 8 | a = c | ||
| 9 | end | ||
| 10 | end | ||
| 11 | end | ||
| 12 | do | ||
| 13 | local a | ||
| 14 | do | ||
| 15 | local _exp_0 = b | ||
| 16 | if _exp_0 ~= nil then | ||
| 17 | a = _exp_0.a | ||
| 18 | else | ||
| 19 | a = c.a | ||
| 20 | end | ||
| 21 | end | ||
| 22 | end | ||
| 23 | do | ||
| 24 | local a = func() | ||
| 25 | if a == nil then | ||
| 26 | a = false | ||
| 27 | end | ||
| 28 | end | ||
| 29 | do | ||
| 30 | local a | ||
| 31 | if a == nil then | ||
| 32 | a = func() | ||
| 33 | end | ||
| 34 | end | ||
| 35 | do | ||
| 36 | local a, b, c, d, e | ||
| 37 | if b ~= nil then | ||
| 38 | a = b | ||
| 39 | else | ||
| 40 | if c ~= nil then | ||
| 41 | a = c | ||
| 42 | else | ||
| 43 | if d ~= nil then | ||
| 44 | a = d | ||
| 45 | else | ||
| 46 | a = e | ||
| 47 | end | ||
| 48 | end | ||
| 49 | end | ||
| 50 | end | ||
| 51 | do | ||
| 52 | local a | ||
| 53 | do | ||
| 54 | local _exp_0 = b | ||
| 55 | if _exp_0 ~= nil then | ||
| 56 | a = _exp_0 | ||
| 57 | else | ||
| 58 | do | ||
| 59 | local _exp_1 = c | ||
| 60 | if _exp_1 ~= nil then | ||
| 61 | a = _exp_1 | ||
| 62 | else | ||
| 63 | do | ||
| 64 | local _exp_2 = d | ||
| 65 | if _exp_2 ~= nil then | ||
| 66 | a = _exp_2 | ||
| 67 | else | ||
| 68 | a = e | ||
| 69 | end | ||
| 70 | end | ||
| 71 | end | ||
| 72 | end | ||
| 73 | end | ||
| 74 | end | ||
| 75 | end | ||
| 76 | do | ||
| 77 | func((function() | ||
| 78 | local _exp_0 = x | ||
| 79 | if _exp_0 ~= nil then | ||
| 80 | return _exp_0 | ||
| 81 | else | ||
| 82 | return "hello" | ||
| 83 | end | ||
| 84 | end)()) | ||
| 85 | end | ||
| 86 | do | ||
| 87 | do | ||
| 88 | local _with_0 | ||
| 89 | do | ||
| 90 | local _exp_0 = funcA() | ||
| 91 | if _exp_0 ~= nil then | ||
| 92 | _with_0 = _exp_0 | ||
| 93 | else | ||
| 94 | _with_0 = funcB() | ||
| 95 | end | ||
| 96 | end | ||
| 97 | print(_with_0.field) | ||
| 98 | end | ||
| 99 | end | ||
| 100 | do | ||
| 101 | local a = 1 + 2 + (function() | ||
| 102 | local _exp_0 = b | ||
| 103 | if _exp_0 ~= nil then | ||
| 104 | return _exp_0 | ||
| 105 | else | ||
| 106 | return c + 3 + 4 | ||
| 107 | end | ||
| 108 | end)() | ||
| 109 | end | ||
| 110 | do | ||
| 111 | local a = 1 + 2 + ((function() | ||
| 112 | local _exp_0 = b | ||
| 113 | if _exp_0 ~= nil then | ||
| 114 | return _exp_0 | ||
| 115 | else | ||
| 116 | return c | ||
| 117 | end | ||
| 118 | end)()) + 3 + 4 | ||
| 119 | end | ||
| 120 | do | ||
| 121 | local a, b | ||
| 122 | do | ||
| 123 | local _obj_0 = func() | ||
| 124 | a, b = _obj_0.a, _obj_0.b | ||
| 125 | end | ||
| 126 | a = a or 1 | ||
| 127 | if b == nil then | ||
| 128 | do | ||
| 129 | local _exp_0 = c | ||
| 130 | if _exp_0 ~= nil then | ||
| 131 | b = _exp_0 | ||
| 132 | else | ||
| 133 | b = 2 | ||
| 134 | end | ||
| 135 | end | ||
| 136 | end | ||
| 137 | end | ||
| 138 | return nil | ||
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index 1c8839f..81f6d5a 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua | |||
| @@ -1,70 +1,86 @@ | |||
| 1 | local _exp_0 = value | 1 | do |
| 2 | if "cool" == _exp_0 then | 2 | local _exp_0 = value |
| 3 | print("hello world") | 3 | if "cool" == _exp_0 then |
| 4 | print("hello world") | ||
| 5 | end | ||
| 4 | end | 6 | end |
| 5 | local _exp_1 = value | 7 | do |
| 6 | if "cool" == _exp_1 then | 8 | local _exp_0 = value |
| 7 | print("hello world") | 9 | if "cool" == _exp_0 then |
| 8 | else | 10 | print("hello world") |
| 9 | print("okay rad") | 11 | else |
| 12 | print("okay rad") | ||
| 13 | end | ||
| 10 | end | 14 | end |
| 11 | local _exp_2 = value | 15 | do |
| 12 | if "cool" == _exp_2 then | 16 | local _exp_0 = value |
| 13 | print("hello world") | 17 | if "cool" == _exp_0 then |
| 14 | elseif "yeah" == _exp_2 then | 18 | print("hello world") |
| 15 | local _ = [[FFFF]] + [[MMMM]] | 19 | elseif "yeah" == _exp_0 then |
| 16 | elseif (2323 + 32434) == _exp_2 then | 20 | local _ = [[FFFF]] + [[MMMM]] |
| 17 | print("okay") | 21 | elseif (2323 + 32434) == _exp_0 then |
| 18 | else | 22 | print("okay") |
| 19 | print("okay rad") | 23 | else |
| 24 | print("okay rad") | ||
| 25 | end | ||
| 20 | end | 26 | end |
| 21 | local out | 27 | local out |
| 22 | local _exp_3 = value | 28 | do |
| 23 | if "cool" == _exp_3 then | 29 | local _exp_0 = value |
| 24 | out = print("hello world") | 30 | if "cool" == _exp_0 then |
| 25 | else | 31 | out = print("hello world") |
| 26 | out = print("okay rad") | 32 | else |
| 33 | out = print("okay rad") | ||
| 34 | end | ||
| 27 | end | 35 | end |
| 28 | local _exp_4 = value | 36 | do |
| 29 | if "cool" == _exp_4 then | 37 | local _exp_0 = value |
| 30 | out = xxxx | 38 | if "cool" == _exp_0 then |
| 31 | elseif "umm" == _exp_4 then | 39 | out = xxxx |
| 32 | out = 34340 | 40 | elseif "umm" == _exp_0 then |
| 33 | else | 41 | out = 34340 |
| 34 | out = error("this failed big time") | 42 | else |
| 43 | out = error("this failed big time") | ||
| 44 | end | ||
| 35 | end | 45 | end |
| 36 | do | 46 | do |
| 37 | local _with_0 = something | 47 | local _with_0 = something |
| 38 | local _exp_5 = _with_0:value() | 48 | do |
| 39 | if _with_0.okay == _exp_5 then | 49 | local _exp_0 = _with_0:value() |
| 40 | local _ = "world" | 50 | if _with_0.okay == _exp_0 then |
| 41 | else | 51 | local _ = "world" |
| 42 | local _ = "yesh" | 52 | else |
| 53 | local _ = "yesh" | ||
| 54 | end | ||
| 43 | end | 55 | end |
| 44 | end | 56 | end |
| 45 | fix(this) | 57 | fix(this) |
| 46 | call_func((function() | 58 | call_func((function() |
| 47 | local _exp_5 = something | 59 | local _exp_0 = something |
| 48 | if 1 == _exp_5 then | 60 | if 1 == _exp_0 then |
| 49 | return "yes" | 61 | return "yes" |
| 50 | else | 62 | else |
| 51 | return "no" | 63 | return "no" |
| 52 | end | 64 | end |
| 53 | end)()) | 65 | end)()) |
| 54 | local _exp_5 = hi | 66 | do |
| 55 | if (hello or world) == _exp_5 then | 67 | local _exp_0 = hi |
| 56 | local _ = greene | 68 | if (hello or world) == _exp_0 then |
| 69 | local _ = greene | ||
| 70 | end | ||
| 57 | end | 71 | end |
| 58 | local _exp_6 = hi | 72 | do |
| 59 | if "one" == _exp_6 or "two" == _exp_6 then | 73 | local _exp_0 = hi |
| 60 | print("cool") | 74 | if "one" == _exp_0 or "two" == _exp_0 then |
| 61 | elseif "dad" == _exp_6 then | 75 | print("cool") |
| 62 | local _ = no | 76 | elseif "dad" == _exp_0 then |
| 77 | local _ = no | ||
| 78 | end | ||
| 63 | end | 79 | end |
| 64 | local _exp_7 = hi | 80 | local _exp_0 = hi |
| 65 | if (3 + 1) == _exp_7 or hello() == _exp_7 or (function() | 81 | if (3 + 1) == _exp_0 or hello() == _exp_0 or (function() |
| 66 | return 4 | 82 | return 4 |
| 67 | end)() == _exp_7 then | 83 | end)() == _exp_0 then |
| 68 | return yello | 84 | return yello |
| 69 | else | 85 | else |
| 70 | return print("cool") | 86 | return print("cool") |
