aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-10-31 17:29:45 +0800
committerLi Jin <dragon-fly@qq.com>2021-10-31 17:29:45 +0800
commitaed806476fe50899c0f01750175531ac41267b9d (patch)
treec46f212a2987a9088b03e2c0225f18cd9a5d4265 /spec
parent60a979e224f26117f5be82bfca757a2483cef0fd (diff)
downloadyuescript-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.yue40
-rw-r--r--spec/outputs/export.lua32
-rw-r--r--spec/outputs/multiline_chain.lua12
-rw-r--r--spec/outputs/nil_coalesing.lua138
-rw-r--r--spec/outputs/switch.lua110
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 @@
1do
2 a = b ?? c
3
4do
5 :a = b ?? c
6
7do
8 a = func!
9 a ??= false
10
11do
12 a ??= func!
13
14do
15 local a, b, c, d, e
16 a = b ?? c ?? d ?? e
17
18do
19 a = b ?? c ?? d ?? e
20
21do
22 func x ?? "hello"
23
24do
25 with funcA! ?? funcB!
26 print .field
27
28do
29 a = 1 + 2 + b ?? c + 3 + 4
30
31do
32 a = 1 + 2 + (b ?? c) + 3 + 4
33
34do
35 :a, :b = func!
36 a or= 1
37 b ??= c ?? 2
38
39nil
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
66end 66end
67_module_0["y"] = y 67_module_0["y"] = y
68local _exp_0 = h 68do
69if 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
71elseif 200 == _exp_0 then 71 _module_0[#_module_0 + 1] = 200
72 _module_0[#_module_0 + 1] = 300 72 elseif 200 == _exp_0 then
73else 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
75end 77end
76local Constant 78local Constant
77local _exp_1 = value 79do
78if "good" == _exp_1 then 80 local _exp_0 = value
79 Constant = 1 81 if "good" == _exp_0 then
80elseif "better" == _exp_1 then 82 Constant = 1
81 Constant = 2 83 elseif "better" == _exp_0 then
82elseif "best" == _exp_1 then 84 Constant = 2
83 Constant = 3 85 elseif "best" == _exp_0 then
86 Constant = 3
87 end
84end 88end
85_module_0["Constant"] = Constant 89_module_0["Constant"] = Constant
86local item = func(123) 90local 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 @@
1do
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
11end
12do
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
22end
23do
24 local a = func()
25 if a == nil then
26 a = false
27 end
28end
29do
30 local a
31 if a == nil then
32 a = func()
33 end
34end
35do
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
50end
51do
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
75end
76do
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)())
85end
86do
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
99end
100do
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)()
109end
110do
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
119end
120do
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
137end
138return 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 @@
1local _exp_0 = value 1do
2if "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
4end 6end
5local _exp_1 = value 7do
6if "cool" == _exp_1 then 8 local _exp_0 = value
7 print("hello world") 9 if "cool" == _exp_0 then
8else 10 print("hello world")
9 print("okay rad") 11 else
12 print("okay rad")
13 end
10end 14end
11local _exp_2 = value 15do
12if "cool" == _exp_2 then 16 local _exp_0 = value
13 print("hello world") 17 if "cool" == _exp_0 then
14elseif "yeah" == _exp_2 then 18 print("hello world")
15 local _ = [[FFFF]] + [[MMMM]] 19 elseif "yeah" == _exp_0 then
16elseif (2323 + 32434) == _exp_2 then 20 local _ = [[FFFF]] + [[MMMM]]
17 print("okay") 21 elseif (2323 + 32434) == _exp_0 then
18else 22 print("okay")
19 print("okay rad") 23 else
24 print("okay rad")
25 end
20end 26end
21local out 27local out
22local _exp_3 = value 28do
23if "cool" == _exp_3 then 29 local _exp_0 = value
24 out = print("hello world") 30 if "cool" == _exp_0 then
25else 31 out = print("hello world")
26 out = print("okay rad") 32 else
33 out = print("okay rad")
34 end
27end 35end
28local _exp_4 = value 36do
29if "cool" == _exp_4 then 37 local _exp_0 = value
30 out = xxxx 38 if "cool" == _exp_0 then
31elseif "umm" == _exp_4 then 39 out = xxxx
32 out = 34340 40 elseif "umm" == _exp_0 then
33else 41 out = 34340
34 out = error("this failed big time") 42 else
43 out = error("this failed big time")
44 end
35end 45end
36do 46do
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
44end 56end
45fix(this) 57fix(this)
46call_func((function() 58call_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
53end)()) 65end)())
54local _exp_5 = hi 66do
55if (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
57end 71end
58local _exp_6 = hi 72do
59if "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
61elseif "dad" == _exp_6 then 75 print("cool")
62 local _ = no 76 elseif "dad" == _exp_0 then
77 local _ = no
78 end
63end 79end
64local _exp_7 = hi 80local _exp_0 = hi
65if (3 + 1) == _exp_7 or hello() == _exp_7 or (function() 81if (3 + 1) == _exp_0 or hello() == _exp_0 or (function()
66 return 4 82 return 4
67end)() == _exp_7 then 83end)() == _exp_0 then
68 return yello 84 return yello
69else 85else
70 return print("cool") 86 return print("cool")