aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-15 17:54:59 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-15 17:54:59 +0800
commitafb046316a15a2c3702b1f056456b58e9356e693 (patch)
treec4820522be5c92948553673dad42c1734d30689f /spec
parent873aced12cf65e633c95358f89a1d5ec37b81d00 (diff)
downloadyuescript-afb046316a15a2c3702b1f056456b58e9356e693.tar.gz
yuescript-afb046316a15a2c3702b1f056456b58e9356e693.tar.bz2
yuescript-afb046316a15a2c3702b1f056456b58e9356e693.zip
Added const attributes.
Diffstat (limited to 'spec')
-rw-r--r--spec/outputs/5.1/import_global.lua120
-rw-r--r--spec/outputs/codes_from_doc.lua60
-rw-r--r--spec/outputs/codes_from_doc_zh.lua60
-rw-r--r--spec/outputs/import_global.lua46
4 files changed, 219 insertions, 67 deletions
diff --git a/spec/outputs/5.1/import_global.lua b/spec/outputs/5.1/import_global.lua
new file mode 100644
index 0000000..c748c78
--- /dev/null
+++ b/spec/outputs/5.1/import_global.lua
@@ -0,0 +1,120 @@
1do
2 local print = print
3 local math = math
4 print("hello")
5 math.random(10)
6end
7do
8 local print = print
9 local value = 1
10 value = value + 2
11 print(value)
12end
13do
14 local print
15 print = function(msg)
16 return msg
17 end
18 do
19 local math = math
20 print("local")
21 math.random(1)
22 end
23end
24do
25 local print = print
26 local tostring
27 tostring = function(v)
28 return "local"
29 end
30 tostring("value")
31 print(tostring(123))
32end
33do
34 local func
35 func = function(x, y)
36 local type = type
37 local tostring = tostring
38 local print = print
39 return type(x, tostring(y, print))
40 end
41 func(1, 2)
42end
43do
44 local xpcall = xpcall
45 local func = func
46 local world = world
47 local tostring = tostring
48 local print = print
49 xpcall(function()
50 return func("hello " .. tostring(world))
51 end, function(err)
52 return print(err)
53 end)
54end
55do
56 local print = print
57 print(FLAG)
58 FLAG = 123
59end
60do
61 local print = print
62 Foo = 10
63 print(Foo)
64 Foo = Foo + 2
65end
66do
67 local print = print
68 Bar = 1
69 Baz = 2
70 print(Bar, Baz)
71end
72do
73 local y = y
74 x = 3434
75 if y then
76 x = 10
77 end
78end
79do
80 local lowercase = lowercase
81 local tostring = tostring
82 local Uppercase = Uppercase
83 local foobar = "all " .. tostring(lowercase)
84 FooBar = "pascal case"
85 FOOBAR = "all " .. tostring(Uppercase)
86end
87do
88 local setmetatable = setmetatable
89 local print = print
90 do
91 local _class_0
92 local _base_0 = { }
93 if _base_0.__index == nil then
94 _base_0.__index = _base_0
95 end
96 _class_0 = setmetatable({
97 __init = function() end,
98 __base = _base_0,
99 __name = "A"
100 }, {
101 __index = _base_0,
102 __call = function(cls, ...)
103 local _self_0 = setmetatable({ }, _base_0)
104 cls.__init(_self_0, ...)
105 return _self_0
106 end
107 })
108 _base_0.__class = _class_0
109 A = _class_0
110 end
111 Flag = 1
112 const, x, y = "const", 1, 2
113 print(math, table)
114end
115do
116 local X = X
117 X:func(1, 2, 3)
118 X.tag = "abc"
119 return X
120end
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 84dfc4e..1df7cef 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.lua
@@ -409,17 +409,6 @@ local tb = {
409 } 409 }
410} 410}
411do 411do
412 local print = print
413 local math = math
414 print("hello")
415 math.random(3)
416end
417do
418 local print = print
419 print(FLAG)
420 FLAG = 123
421end
422do
423 local insert, concat = table.insert, table.concat 412 local insert, concat = table.insert, table.concat
424 local C, Ct, Cmt 413 local C, Ct, Cmt
425 do 414 do
@@ -452,6 +441,25 @@ do
452 local _obj_0 = require("export") 441 local _obj_0 = require("export")
453 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 442 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
454end 443end
444do
445 local tostring <const> = tostring
446 local concat <const> = table.concat
447 print(concat({
448 "a",
449 tostring(1)
450 }))
451end
452do
453 local print <const> = print
454 local math <const> = math
455 print("hello")
456 math.random(3)
457end
458do
459 local print <const> = print
460 print(FLAG)
461 FLAG = 123
462end
455local _module_0 = { } 463local _module_0 = { }
456local a, b, c = 1, 2, 3 464local a, b, c = 1, 2, 3
457_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 465_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -2928,17 +2936,6 @@ local tb = {
2928 } 2936 }
2929} 2937}
2930do 2938do
2931 local print = print
2932 local math = math
2933 print("hello")
2934 math.random(3)
2935end
2936do
2937 local print = print
2938 print(FLAG)
2939 FLAG = 123
2940end
2941do
2942 local insert, concat = table.insert, table.concat 2939 local insert, concat = table.insert, table.concat
2943 local C, Ct, Cmt 2940 local C, Ct, Cmt
2944 do 2941 do
@@ -2971,6 +2968,25 @@ do
2971 local _obj_0 = require("export") 2968 local _obj_0 = require("export")
2972 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 2969 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
2973end 2970end
2971do
2972 local tostring <const> = tostring
2973 local concat <const> = table.concat
2974 print(concat({
2975 "a",
2976 tostring(1)
2977 }))
2978end
2979do
2980 local print <const> = print
2981 local math <const> = math
2982 print("hello")
2983 math.random(3)
2984end
2985do
2986 local print <const> = print
2987 print(FLAG)
2988 FLAG = 123
2989end
2974local _module_0 = { } 2990local _module_0 = { }
2975local a, b, c = 1, 2, 3 2991local a, b, c = 1, 2, 3
2976_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 2992_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua
index d4e8b6a..b407895 100644
--- a/spec/outputs/codes_from_doc_zh.lua
+++ b/spec/outputs/codes_from_doc_zh.lua
@@ -409,17 +409,6 @@ local tb = {
409 } 409 }
410} 410}
411do 411do
412 local print = print
413 local math = math
414 print("hello")
415 math.random(3)
416end
417do
418 local print = print
419 print(FLAG)
420 FLAG = 123
421end
422do
423 local insert, concat = table.insert, table.concat 412 local insert, concat = table.insert, table.concat
424 local C, Ct, Cmt 413 local C, Ct, Cmt
425 do 414 do
@@ -452,6 +441,25 @@ do
452 local _obj_0 = require("export") 441 local _obj_0 = require("export")
453 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 442 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
454end 443end
444do
445 local tostring <const> = tostring
446 local concat <const> = table.concat
447 print(concat({
448 "a",
449 tostring(1)
450 }))
451end
452do
453 local print <const> = print
454 local math <const> = math
455 print("hello")
456 math.random(3)
457end
458do
459 local print <const> = print
460 print(FLAG)
461 FLAG = 123
462end
455local _module_0 = { } 463local _module_0 = { }
456local a, b, c = 1, 2, 3 464local a, b, c = 1, 2, 3
457_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 465_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -2922,17 +2930,6 @@ local tb = {
2922 } 2930 }
2923} 2931}
2924do 2932do
2925 local print = print
2926 local math = math
2927 print("hello")
2928 math.random(3)
2929end
2930do
2931 local print = print
2932 print(FLAG)
2933 FLAG = 123
2934end
2935do
2936 local insert, concat = table.insert, table.concat 2933 local insert, concat = table.insert, table.concat
2937 local C, Ct, Cmt 2934 local C, Ct, Cmt
2938 do 2935 do
@@ -2965,6 +2962,25 @@ do
2965 local _obj_0 = require("export") 2962 local _obj_0 = require("export")
2966 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1] 2963 one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
2967end 2964end
2965do
2966 local tostring <const> = tostring
2967 local concat <const> = table.concat
2968 print(concat({
2969 "a",
2970 tostring(1)
2971 }))
2972end
2973do
2974 local print <const> = print
2975 local math <const> = math
2976 print("hello")
2977 math.random(3)
2978end
2979do
2980 local print <const> = print
2981 print(FLAG)
2982 FLAG = 123
2983end
2968local _module_0 = { } 2984local _module_0 = { }
2969local a, b, c = 1, 2, 3 2985local a, b, c = 1, 2, 3
2970_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c 2986_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
diff --git a/spec/outputs/import_global.lua b/spec/outputs/import_global.lua
index c748c78..f76b4fe 100644
--- a/spec/outputs/import_global.lua
+++ b/spec/outputs/import_global.lua
@@ -1,11 +1,11 @@
1do 1do
2 local print = print 2 local print <const> = print
3 local math = math 3 local math <const> = math
4 print("hello") 4 print("hello")
5 math.random(10) 5 math.random(10)
6end 6end
7do 7do
8 local print = print 8 local print <const> = print
9 local value = 1 9 local value = 1
10 value = value + 2 10 value = value + 2
11 print(value) 11 print(value)
@@ -16,13 +16,13 @@ do
16 return msg 16 return msg
17 end 17 end
18 do 18 do
19 local math = math 19 local math <const> = math
20 print("local") 20 print("local")
21 math.random(1) 21 math.random(1)
22 end 22 end
23end 23end
24do 24do
25 local print = print 25 local print <const> = print
26 local tostring 26 local tostring
27 tostring = function(v) 27 tostring = function(v)
28 return "local" 28 return "local"
@@ -33,19 +33,19 @@ end
33do 33do
34 local func 34 local func
35 func = function(x, y) 35 func = function(x, y)
36 local type = type 36 local type <const> = type
37 local tostring = tostring 37 local tostring <const> = tostring
38 local print = print 38 local print <const> = print
39 return type(x, tostring(y, print)) 39 return type(x, tostring(y, print))
40 end 40 end
41 func(1, 2) 41 func(1, 2)
42end 42end
43do 43do
44 local xpcall = xpcall 44 local xpcall <const> = xpcall
45 local func = func 45 local func <const> = func
46 local world = world 46 local world <const> = world
47 local tostring = tostring 47 local tostring <const> = tostring
48 local print = print 48 local print <const> = print
49 xpcall(function() 49 xpcall(function()
50 return func("hello " .. tostring(world)) 50 return func("hello " .. tostring(world))
51 end, function(err) 51 end, function(err)
@@ -53,40 +53,40 @@ do
53 end) 53 end)
54end 54end
55do 55do
56 local print = print 56 local print <const> = print
57 print(FLAG) 57 print(FLAG)
58 FLAG = 123 58 FLAG = 123
59end 59end
60do 60do
61 local print = print 61 local print <const> = print
62 Foo = 10 62 Foo = 10
63 print(Foo) 63 print(Foo)
64 Foo = Foo + 2 64 Foo = Foo + 2
65end 65end
66do 66do
67 local print = print 67 local print <const> = print
68 Bar = 1 68 Bar = 1
69 Baz = 2 69 Baz = 2
70 print(Bar, Baz) 70 print(Bar, Baz)
71end 71end
72do 72do
73 local y = y 73 local y <const> = y
74 x = 3434 74 x = 3434
75 if y then 75 if y then
76 x = 10 76 x = 10
77 end 77 end
78end 78end
79do 79do
80 local lowercase = lowercase 80 local lowercase <const> = lowercase
81 local tostring = tostring 81 local tostring <const> = tostring
82 local Uppercase = Uppercase 82 local Uppercase <const> = Uppercase
83 local foobar = "all " .. tostring(lowercase) 83 local foobar = "all " .. tostring(lowercase)
84 FooBar = "pascal case" 84 FooBar = "pascal case"
85 FOOBAR = "all " .. tostring(Uppercase) 85 FOOBAR = "all " .. tostring(Uppercase)
86end 86end
87do 87do
88 local setmetatable = setmetatable 88 local setmetatable <const> = setmetatable
89 local print = print 89 local print <const> = print
90 do 90 do
91 local _class_0 91 local _class_0
92 local _base_0 = { } 92 local _base_0 = { }
@@ -113,7 +113,7 @@ do
113 print(math, table) 113 print(math, table)
114end 114end
115do 115do
116 local X = X 116 local X <const> = X
117 X:func(1, 2, 3) 117 X:func(1, 2, 3)
118 X.tag = "abc" 118 X.tag = "abc"
119 return X 119 return X