aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-07-24 22:13:08 +0800
committerLi Jin <dragon-fly@qq.com>2022-07-24 22:13:08 +0800
commit303834e1b1e6cd9cae64b66c2ae44dcd7185238f (patch)
tree519f6a1debcc5791d35e06dc5cbb1ce22f9cfd31 /spec
parenteb367126bf3a4f5b0e51ccef93b7c7136bea170e (diff)
downloadyuescript-303834e1b1e6cd9cae64b66c2ae44dcd7185238f.tar.gz
yuescript-303834e1b1e6cd9cae64b66c2ae44dcd7185238f.tar.bz2
yuescript-303834e1b1e6cd9cae64b66c2ae44dcd7185238f.zip
add option --target=5.1 to generate Lua 5.1 compatible codes. add const destructure. make import item const by default.
Diffstat (limited to 'spec')
-rw-r--r--spec/inputs/destructure.yue5
-rw-r--r--spec/inputs/export.yue4
-rw-r--r--spec/inputs/import.yue2
-rw-r--r--spec/inputs/macro.yue2
-rw-r--r--spec/inputs/metatable.yue2
-rw-r--r--spec/inputs/syntax.yue10
-rw-r--r--spec/inputs/tables.yue8
-rw-r--r--spec/inputs/with.yue2
-rw-r--r--spec/outputs/destructure.lua25
-rw-r--r--spec/outputs/export.lua10
-rw-r--r--spec/outputs/import.lua2
-rw-r--r--spec/outputs/macro.lua3
-rw-r--r--spec/outputs/metatable.lua1
-rw-r--r--spec/outputs/syntax.lua10
-rw-r--r--spec/outputs/tables.lua8
-rw-r--r--spec/outputs/with.lua2
16 files changed, 63 insertions, 33 deletions
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue
index 3007adf..24282c0 100644
--- a/spec/inputs/destructure.yue
+++ b/spec/inputs/destructure.yue
@@ -11,7 +11,7 @@ do
11 11
12 {:a,:b,:c,:d} = yeah 12 {:a,:b,:c,:d} = yeah
13 13
14 {a} = one, two 14 {a}, b = one, two
15 {b}, c = one 15 {b}, c = one
16 {d}, e = one, two 16 {d}, e = one, two
17 17
@@ -184,3 +184,6 @@ do
184do 184do
185 {x: a.b = 1, y: a.c = 2} = x.x.x 185 {x: a.b = 1, y: a.c = 2} = x.x.x
186 186
187do
188 const :width, :height = View.size
189 const {:x = 0.0, :y = 0.0} = point
diff --git a/spec/inputs/export.yue b/spec/inputs/export.yue
index 9113508..15ffbcb 100644
--- a/spec/inputs/export.yue
+++ b/spec/inputs/export.yue
@@ -55,7 +55,7 @@ f switch a
55f [i for i = 1,10] 55f [i for i = 1,10]
56f for i = 1,10 do i 56f for i = 1,10 do i
57f {k,v for k,v in pairs tb} 57f {k,v for k,v in pairs tb}
58f for k,v in pairs tb do k,v 58f for k,v in pairs tb do {k,v}
59f while a do true 59f while a do true
60f with a 60f with a
61 .b = 123 61 .b = 123
@@ -70,7 +70,7 @@ _ = "#{switch a
70_ = "#{[i for i = 1,10]}" 70_ = "#{[i for i = 1,10]}"
71_ = "#{for i = 1,10 do i}" 71_ = "#{for i = 1,10 do i}"
72_ = "#{{k,v for k,v in pairs tb}}" 72_ = "#{{k,v for k,v in pairs tb}}"
73_ = "#{for k,v in pairs tb do k,v}" 73_ = "#{for k,v in pairs tb do {k,v}}"
74_ = "#{while a do true}" 74_ = "#{while a do true}"
75_ = "#{with a 75_ = "#{with a
76 .b = 123}" 76 .b = 123}"
diff --git a/spec/inputs/import.yue b/spec/inputs/import.yue
index 8e82a01..e206d04 100644
--- a/spec/inputs/import.yue
+++ b/spec/inputs/import.yue
@@ -70,7 +70,7 @@ do
70 70
71do 71do
72 import "m" as {a#: b} 72 import "m" as {a#: b}
73 import "m" as {e: f, a#: b} 73 import "m" as {e: f, a#: c}
74 import "m" as {c: d} 74 import "m" as {c: d}
75 import "m" as {g, {h#: i}} 75 import "m" as {g, {h#: i}}
76 76
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue
index 7bbb06d..3c89c1c 100644
--- a/spec/inputs/macro.yue
+++ b/spec/inputs/macro.yue
@@ -279,7 +279,7 @@ do
279 279
280macro skip = -> "while false do break" 280macro skip = -> "while false do break"
281 281
282_ = -> 282_1 = ->
283 print 1 283 print 1
284 <- $skip 284 <- $skip
285 print 2 285 print 2
diff --git a/spec/inputs/metatable.yue b/spec/inputs/metatable.yue
index ed68a17..7e9b4f2 100644
--- a/spec/inputs/metatable.yue
+++ b/spec/inputs/metatable.yue
@@ -23,7 +23,7 @@ do
23 = 123, a.b.c, func! 23 = 123, a.b.c, func!
24 24
25x.abc, a.b.# = 123, {} 25x.abc, a.b.# = 123, {}
26func!.# = mt, extra 26func!.# = mt --, extra
27a, b.c.#, d, e = 1, mt, "abc" 27a, b.c.#, d, e = 1, mt, "abc"
28 28
29is_same = a.#.__index == a.index# 29is_same = a.#.__index == a.index#
diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue
index f212bec..d18bd0e 100644
--- a/spec/inputs/syntax.yue
+++ b/spec/inputs/syntax.yue
@@ -71,10 +71,10 @@ _ = something[======[hey]======] * 2
71_ = something[ [======[hey]======] ] * 2 71_ = something[ [======[hey]======] ] * 2
72 72
73 73
74_ = something'else', 2 74_, _ = something'else', 2
75_ = something"else", 2 75_, _ = something"else", 2
76_ = something[[else]], 2 76_, _ = something[[else]], 2
77_ = something[ [[else]] ], 2 77_, _ = something[ [[else]] ], 2
78 78
79something 'else', 2 79something 'else', 2
80something "else", 2 80something "else", 2
@@ -157,7 +157,7 @@ y = #"hello"
157 157
158x = #{#{},#{1},#{1,2}} 158x = #{#{},#{1},#{1,2}}
159 159
160_ = hello, world 160_, _ = hello, world
161 161
162something\hello(what) a,b 162something\hello(what) a,b
163something\hello what 163something\hello what
diff --git a/spec/inputs/tables.yue b/spec/inputs/tables.yue
index e1b9e1d..0b5af46 100644
--- a/spec/inputs/tables.yue
+++ b/spec/inputs/tables.yue
@@ -152,12 +152,12 @@ k = { "hello": 'world', "hat": "zat" }
152please "hello": "world" 152please "hello": "world"
153k = "hello": "world", "one": "zone" 153k = "hello": "world", "one": "zone"
154 154
155f = "one", "two": three, "four" 155f1, f2, f3 = "one", "two": three, "four"
156f = "two": three, "four" 156f1, f2 = "two": three, "four"
157f = { "one", "two": three, "four" } 157f1 = { "one", "two": three, "four" }
158 158
159 159
160j = "one", "two": three, "four": five, 6, 7 160j1, j2, j3, j4 = "one", "two": three, "four": five, 6, 7
161 161
162heroine = 162heroine =
163 name: "Christina" 163 name: "Christina"
diff --git a/spec/inputs/with.yue b/spec/inputs/with.yue
index 6f3e3ba..5da0980 100644
--- a/spec/inputs/with.yue
+++ b/spec/inputs/with.yue
@@ -45,7 +45,7 @@ do
45-- 45--
46 46
47do 47do
48 with a, b -- b is lost 48 with a -- only one value allowed
49 print .world 49 print .world
50 50
51 mod = with _M = {} 51 mod = with _M = {}
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua
index 2fe4ba9..59ee358 100644
--- a/spec/outputs/destructure.lua
+++ b/spec/outputs/destructure.lua
@@ -26,7 +26,7 @@ do
26 local _obj_0 = yeah 26 local _obj_0 = yeah
27 a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d 27 a, b, c, d = _obj_0.a, _obj_0.b, _obj_0.c, _obj_0.d
28 end 28 end
29 local _ = two 29 b = two
30 a = one[1] 30 a = one[1]
31 c = nil 31 c = nil
32 b = one[1] 32 b = one[1]
@@ -56,7 +56,10 @@ do
56 end 56 end
57 do 57 do
58 a = tbl 58 a = tbl
59 b, c = _.b, _.c 59 do
60 local _obj_0 = _
61 b, c = _obj_0.b, _obj_0.c
62 end
60 end 63 end
61 do 64 do
62 b = _ 65 b = _
@@ -386,3 +389,21 @@ do
386 a.c = _tmp_1 389 a.c = _tmp_1
387 end 390 end
388end 391end
392do
393 local width, height
394 do
395 local _obj_0 = View.size
396 width, height = _obj_0.width, _obj_0.height
397 end
398 local x, y
399 do
400 local _obj_0 = point
401 x, y = _obj_0.x, _obj_0.y
402 if x == nil then
403 x = 0.0
404 end
405 if y == nil then
406 y = 0.0
407 end
408 end
409end
diff --git a/spec/outputs/export.lua b/spec/outputs/export.lua
index 84e5424..962f18c 100644
--- a/spec/outputs/export.lua
+++ b/spec/outputs/export.lua
@@ -134,7 +134,10 @@ f((function()
134 local _accum_0 = { } 134 local _accum_0 = { }
135 local _len_0 = 1 135 local _len_0 = 1
136 for k, v in pairs(tb) do 136 for k, v in pairs(tb) do
137 _accum_0[_len_0] = k, v 137 _accum_0[_len_0] = {
138 k,
139 v
140 }
138 _len_0 = _len_0 + 1 141 _len_0 = _len_0 + 1
139 end 142 end
140 return _accum_0 143 return _accum_0
@@ -232,7 +235,10 @@ _ = tostring((function()
232 local _accum_0 = { } 235 local _accum_0 = { }
233 local _len_0 = 1 236 local _len_0 = 1
234 for k, v in pairs(tb) do 237 for k, v in pairs(tb) do
235 _accum_0[_len_0] = k, v 238 _accum_0[_len_0] = {
239 k,
240 v
241 }
236 _len_0 = _len_0 + 1 242 _len_0 = _len_0 + 1
237 end 243 end
238 return _accum_0 244 return _accum_0
diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua
index 65e703f..6979e47 100644
--- a/spec/outputs/import.lua
+++ b/spec/outputs/import.lua
@@ -94,7 +94,7 @@ do
94 b = getmetatable(require("m")).__a 94 b = getmetatable(require("m")).__a
95 local _obj_0 = require("m") 95 local _obj_0 = require("m")
96 local f = _obj_0.e 96 local f = _obj_0.e
97 b = getmetatable(_obj_0).__a 97 c = getmetatable(_obj_0).__a
98 local d = require("m").c 98 local d = require("m").c
99 local g, i 99 local g, i
100 do 100 do
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua
index c19b2d7..fbc1d48 100644
--- a/spec/outputs/macro.lua
+++ b/spec/outputs/macro.lua
@@ -282,7 +282,8 @@ print("current line: " .. tostring(268));
282do 282do
283 print(1) 283 print(1)
284end 284end
285_ = function() 285local _1
286_1 = function()
286 print(1) 287 print(1)
287 local _accum_0 = { } 288 local _accum_0 = { }
288 local _len_0 = 1 289 local _len_0 = 1
diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua
index 935202c..2d72e1d 100644
--- a/spec/outputs/metatable.lua
+++ b/spec/outputs/metatable.lua
@@ -65,7 +65,6 @@ end
65setmetatable(a.b, { }) 65setmetatable(a.b, { })
66x.abc = 123 66x.abc = 123
67setmetatable(func(), mt) 67setmetatable(func(), mt)
68local _ = extra
69setmetatable(b.c, mt) 68setmetatable(b.c, mt)
70a, d, e = 1, "abc" 69a, d, e = 1, "abc"
71local is_same = getmetatable(a).__index == getmetatable(a).__index 70local is_same = getmetatable(a).__index == getmetatable(a).__index
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua
index 24b78c6..a4cb8e2 100644
--- a/spec/outputs/syntax.lua
+++ b/spec/outputs/syntax.lua
@@ -56,10 +56,10 @@ something("else")
56_ = something([[hey]]) * 2 56_ = something([[hey]]) * 2
57_ = something([======[hey]======]) * 2 57_ = something([======[hey]======]) * 2
58_ = something[ [======[hey]======]] * 2 58_ = something[ [======[hey]======]] * 2
59_ = something('else'), 2 59_, _ = something('else'), 2
60_ = something("else"), 2 60_, _ = something("else"), 2
61_ = something([[else]]), 2 61_, _ = something([[else]]), 2
62_ = something[ [[else]]], 2 62_, _ = something[ [[else]]], 2
63something('else', 2) 63something('else', 2)
64something("else", 2) 64something("else", 2)
65something([[else]], 2) 65something([[else]], 2)
@@ -165,7 +165,7 @@ x = #{
165 2 165 2
166 } 166 }
167} 167}
168_ = hello, world 168_, _ = hello, world
169something:hello(what)(a, b) 169something:hello(what)(a, b)
170something:hello(what) 170something:hello(what)
171something.hello:world(a, b) 171something.hello:world(a, b)
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua
index 1d28a43..e9df1c4 100644
--- a/spec/outputs/tables.lua
+++ b/spec/outputs/tables.lua
@@ -187,18 +187,18 @@ k = {
187 ["hello"] = "world", 187 ["hello"] = "world",
188 ["one"] = "zone" 188 ["one"] = "zone"
189} 189}
190local f = "one", { 190local f1, f2, f3 = "one", {
191 ["two"] = three 191 ["two"] = three
192}, "four" 192}, "four"
193f = { 193f1, f2 = {
194 ["two"] = three 194 ["two"] = three
195}, "four" 195}, "four"
196f = { 196f1 = {
197 "one", 197 "one",
198 ["two"] = three, 198 ["two"] = three,
199 "four" 199 "four"
200} 200}
201local j = "one", { 201local j1, j2, j3, j4 = "one", {
202 ["two"] = three, 202 ["two"] = three,
203 ["four"] = five 203 ["four"] = five
204}, 6, 7 204}, 6, 7
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua
index 9dcaca3..304d26e 100644
--- a/spec/outputs/with.lua
+++ b/spec/outputs/with.lua
@@ -54,7 +54,7 @@ do
54end 54end
55do 55do
56 do 56 do
57 local _with_0 = a, b 57 local _with_0 = a
58 print(_with_0.world) 58 print(_with_0.world)
59 end 59 end
60 local mod 60 local mod