aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2024-05-23 16:30:05 +0800
committerLi Jin <dragon-fly@qq.com>2024-05-23 16:30:05 +0800
commit1890294226034d27165af016c8c93a484d978b49 (patch)
tree97f7f698aef1998ceb037080bd9f46b6f894e441 /spec
parent06bf167924d04aaefe80d6e4ead40989a447ea34 (diff)
downloadyuescript-1890294226034d27165af016c8c93a484d978b49.tar.gz
yuescript-1890294226034d27165af016c8c93a484d978b49.tar.bz2
yuescript-1890294226034d27165af016c8c93a484d978b49.zip
prevent more anonymous functions generating from `const`, `close` decl.
Diffstat (limited to 'spec')
-rw-r--r--spec/outputs/5.1/attrib.lua115
-rw-r--r--spec/outputs/attrib.lua94
-rw-r--r--spec/outputs/compile_doc.lua70
-rw-r--r--spec/outputs/unicode/attrib.lua96
4 files changed, 185 insertions, 190 deletions
diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua
index 8361b24..c48c72c 100644
--- a/spec/outputs/5.1/attrib.lua
+++ b/spec/outputs/5.1/attrib.lua
@@ -55,22 +55,16 @@ local _anon_func_0 = function(_close_1, error, f, _arg_0, ...)
55 end 55 end
56 end 56 end
57end 57end
58local _anon_func_1 = function(io) 58local _anon_func_1 = function() end
59 local _with_0 = io.open("file.txt")
60 _with_0:write("Hello")
61 return _with_0
62end
63local _anon_func_2 = function() end
64do 59do
65 local v = (function() 60 local v
66 if flag then 61 if flag then
67 return func() 62 v = func()
68 else 63 else
69 return setmetatable({ }, { 64 v = setmetatable({ }, {
70 __close = function(self) end 65 __close = function(self) end
71 }) 66 })
72 end 67 end
73 end)()
74 local _close_0 = assert(getmetatable(v).__close); 68 local _close_0 = assert(getmetatable(v).__close);
75 (function(_arg_0, ...) 69 (function(_arg_0, ...)
76 local _ok_0 = _arg_0 70 local _ok_0 = _arg_0
@@ -81,12 +75,17 @@ do
81 return error(...) 75 return error(...)
82 end 76 end
83 end)(pcall(function() 77 end)(pcall(function()
84 local f = _anon_func_1(io) 78 local f
79 do
80 local _with_0 = io.open("file.txt")
81 _with_0:write("Hello")
82 f = _with_0
83 end
85 local _close_1 = assert(getmetatable(f).__close) 84 local _close_1 = assert(getmetatable(f).__close)
86 return _anon_func_0(_close_1, error, f, pcall(_anon_func_2)) 85 return _anon_func_0(_close_1, error, f, pcall(_anon_func_1))
87 end)) 86 end))
88end 87end
89local _anon_func_3 = function(_close_1, d, error, _arg_0, ...) 88local _anon_func_2 = function(_close_1, d, error, _arg_0, ...)
90 do 89 do
91 local _ok_0 = _arg_0 90 local _ok_0 = _arg_0
92 _close_1(d) 91 _close_1(d)
@@ -97,41 +96,25 @@ local _anon_func_3 = function(_close_1, d, error, _arg_0, ...)
97 end 96 end
98 end 97 end
99end 98end
100local _anon_func_4 = function(x) 99local _anon_func_3 = function(a, b)
101 if true then
102 if "abc" == x then
103 return 998
104 end
105 end
106end
107local _anon_func_6 = function(a, b)
108 if a ~= nil then 100 if a ~= nil then
109 return a 101 return a
110 else 102 else
111 return b 103 return b
112 end 104 end
113end 105end
114local _anon_func_5 = function(a, b) 106local _anon_func_4 = function() end
115 if _anon_func_6(a, b) then
116 return {
117 value = value
118 }
119 end
120end
121local _anon_func_7 = function() end
122do 107do
123 local a = (function() 108 local a
124 if true then 109 if true then
125 return 1 110 a = 1
126 end 111 end
127 end)() 112 local b
128 local b = (function() 113 if not false then
129 if not false then 114 if x then
130 if x then 115 b = 1
131 return 1
132 end
133 end 116 end
134 end)() 117 end
135 local _close_0 = assert(getmetatable(b).__close); 118 local _close_0 = assert(getmetatable(b).__close);
136 (function(_arg_0, ...) 119 (function(_arg_0, ...)
137 local _ok_0 = _arg_0 120 local _ok_0 = _arg_0
@@ -142,13 +125,24 @@ do
142 return error(...) 125 return error(...)
143 end 126 end
144 end)(pcall(function() 127 end)(pcall(function()
145 local c = _anon_func_4(x) 128 local c
146 local d = _anon_func_5(a, b) 129 if true then
130 local _exp_0 = x
131 if "abc" == _exp_0 then
132 c = 998
133 end
134 end
135 local d
136 if _anon_func_3(a, b) then
137 d = {
138 value = value
139 }
140 end
147 local _close_1 = assert(getmetatable(d).__close) 141 local _close_1 = assert(getmetatable(d).__close)
148 return _anon_func_3(_close_1, d, error, pcall(_anon_func_7)) 142 return _anon_func_2(_close_1, d, error, pcall(_anon_func_4))
149 end)) 143 end))
150end 144end
151local _anon_func_8 = function(_, _close_1, error, _arg_0, ...) 145local _anon_func_5 = function(_, _close_1, error, _arg_0, ...)
152 do 146 do
153 local _ok_0 = _arg_0 147 local _ok_0 = _arg_0
154 _close_1(_) 148 _close_1(_)
@@ -159,7 +153,7 @@ local _anon_func_8 = function(_, _close_1, error, _arg_0, ...)
159 end 153 end
160 end 154 end
161end 155end
162local _anon_func_9 = function(_, _close_2, error, _arg_0, ...) 156local _anon_func_6 = function(_, _close_2, error, _arg_0, ...)
163 do 157 do
164 local _ok_0 = _arg_0 158 local _ok_0 = _arg_0
165 _close_2(_) 159 _close_2(_)
@@ -171,11 +165,12 @@ local _anon_func_9 = function(_, _close_2, error, _arg_0, ...)
171 end 165 end
172end 166end
173do 167do
174 local _ = (function() 168 local _
169 do
175 local _with_0 = io.open("file.txt") 170 local _with_0 = io.open("file.txt")
176 _with_0:write("Hello") 171 _with_0:write("Hello")
177 return _with_0 172 _ = _with_0
178 end)() 173 end
179 local _close_0 = assert(getmetatable(_).__close); 174 local _close_0 = assert(getmetatable(_).__close);
180 (function(_arg_0, ...) 175 (function(_arg_0, ...)
181 local _ok_0 = _arg_0 176 local _ok_0 = _arg_0
@@ -192,14 +187,14 @@ do
192 end 187 end
193 }) 188 })
194 local _close_1 = assert(getmetatable(_).__close) 189 local _close_1 = assert(getmetatable(_).__close)
195 return _anon_func_8(_, _close_1, error, pcall(function() 190 return _anon_func_5(_, _close_1, error, pcall(function()
196 local _ = setmetatable({ }, { 191 local _ = setmetatable({ }, {
197 __close = function() 192 __close = function()
198 return print("first") 193 return print("first")
199 end 194 end
200 }) 195 })
201 local _close_2 = assert(getmetatable(_).__close) 196 local _close_2 = assert(getmetatable(_).__close)
202 return _anon_func_9(_, _close_2, error, pcall(function() 197 return _anon_func_6(_, _close_2, error, pcall(function()
203 return print("third") 198 return print("third")
204 end)) 199 end))
205 end)) 200 end))
@@ -216,7 +211,7 @@ def = function(item)
216 _defers[#_defers + 1] = item 211 _defers[#_defers + 1] = item
217 return _defers 212 return _defers
218end 213end
219local _anon_func_10 = function(_, _close_1, error, _arg_0, ...) 214local _anon_func_7 = function(_, _close_1, error, _arg_0, ...)
220 do 215 do
221 local _ok_0 = _arg_0 216 local _ok_0 = _arg_0
222 _close_1(_) 217 _close_1(_)
@@ -227,7 +222,7 @@ local _anon_func_10 = function(_, _close_1, error, _arg_0, ...)
227 end 222 end
228 end 223 end
229end 224end
230local _anon_func_11 = function(_, _close_2, error, _arg_0, ...) 225local _anon_func_8 = function(_, _close_2, error, _arg_0, ...)
231 do 226 do
232 local _ok_0 = _arg_0 227 local _ok_0 = _arg_0
233 _close_2(_) 228 _close_2(_)
@@ -238,7 +233,7 @@ local _anon_func_11 = function(_, _close_2, error, _arg_0, ...)
238 end 233 end
239 end 234 end
240end 235end
241local _anon_func_12 = function() end 236local _anon_func_9 = function() end
242do 237do
243 local _ = def(function() 238 local _ = def(function()
244 return print(3) 239 return print(3)
@@ -257,12 +252,12 @@ do
257 return print(2) 252 return print(2)
258 end) 253 end)
259 local _close_1 = assert(getmetatable(_).__close) 254 local _close_1 = assert(getmetatable(_).__close)
260 return _anon_func_10(_, _close_1, error, pcall(function() 255 return _anon_func_7(_, _close_1, error, pcall(function()
261 local _ = def(function() 256 local _ = def(function()
262 return print(1) 257 return print(1)
263 end) 258 end)
264 local _close_2 = assert(getmetatable(_).__close) 259 local _close_2 = assert(getmetatable(_).__close)
265 return _anon_func_11(_, _close_2, error, pcall(_anon_func_12)) 260 return _anon_func_8(_, _close_2, error, pcall(_anon_func_9))
266 end)) 261 end))
267 end)) 262 end))
268end 263end
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua
index 626944e..e48963c 100644
--- a/spec/outputs/attrib.lua
+++ b/spec/outputs/attrib.lua
@@ -34,62 +34,62 @@ do
34 a, b = _obj_0[1], _obj_0[2] 34 a, b = _obj_0[1], _obj_0[2]
35end 35end
36do 36do
37 local v <close> = (function() 37 local v
38 if flag then 38 if flag then
39 return func() 39 v = func()
40 else 40 else
41 return setmetatable({ }, { 41 v = setmetatable({ }, {
42 __close = function(self) end 42 __close = function(self) end
43 }) 43 })
44 end 44 end
45 end)() 45 local _close_0 <close> = v
46 local f <close> = (function() 46 local f
47 local _with_0 = io.open("file.txt") 47 local _with_0 = io.open("file.txt")
48 _with_0:write("Hello") 48 _with_0:write("Hello")
49 return _with_0 49 f = _with_0
50 end)() 50 local _close_1 <close> = f
51end 51end
52do 52do
53 local a <const> = (function() 53 local a
54 if true then 54 if true then
55 return 1 55 a = 1
56 end 56 end
57 end)() 57 local b
58 local b <close> = (function() 58 if not false then
59 if not false then 59 if x then
60 if x then 60 b = 1
61 return 1
62 end
63 end 61 end
64 end)() 62 end
65 local c <const> = (function() 63 local _close_0 <close> = b
66 if true then 64 local c
67 local _exp_0 = x 65 if true then
68 if "abc" == _exp_0 then 66 local _exp_0 = x
69 return 998 67 if "abc" == _exp_0 then
70 end 68 c = 998
71 end 69 end
72 end)() 70 end
73 local d <close> = (function() 71 local d
74 if (function() 72 if (function()
75 if a ~= nil then 73 if a ~= nil then
76 return a 74 return a
77 else 75 else
78 return b 76 return b
79 end
80 end)() then
81 return {
82 value = value
83 }
84 end 77 end
85 end)() 78 end)() then
79 d = {
80 value = value
81 }
82 end
83 local _close_1 <close> = d
86end 84end
87do 85do
88 local _ <close> = (function() 86 local _
87 do
89 local _with_0 = io.open("file.txt") 88 local _with_0 = io.open("file.txt")
90 _with_0:write("Hello") 89 _with_0:write("Hello")
91 return _with_0 90 _ = _with_0
92 end)() 91 end
92 local _close_0 <close> = _
93 local _ <close> = setmetatable({ }, { 93 local _ <close> = setmetatable({ }, {
94 __close = function() 94 __close = function()
95 return print("second") 95 return print("second")
diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua
index 29f4aeb..3781fb9 100644
--- a/spec/outputs/compile_doc.lua
+++ b/spec/outputs/compile_doc.lua
@@ -12,42 +12,42 @@ local _list_0 = {
12for _index_0 = 1, #_list_0 do 12for _index_0 = 1, #_list_0 do
13 local _des_0 = _list_0[_index_0] 13 local _des_0 = _list_0[_index_0]
14 local compiledFile, docFile = _des_0[1], _des_0[2] 14 local compiledFile, docFile = _des_0[1], _des_0[2]
15 local input <close> = (function() 15 local input
16 local _with_0 = io.open(docFile) 16 local _with_0 = io.open(docFile)
17 if _with_0 ~= nil then 17 if _with_0 ~= nil then
18 local to_lua = require("yue").to_lua 18 local to_lua = require("yue").to_lua
19 local text = _with_0:read("*a") 19 local text = _with_0:read("*a")
20 local codes = { } 20 local codes = { }
21 for code in text:gmatch("```moonscript(.-)```") do 21 for code in text:gmatch("```moonscript(.-)```") do
22 local result, err = to_lua(code, { 22 local result, err = to_lua(code, {
23 implicit_return_root = false, 23 implicit_return_root = false,
24 reserve_line_number = false 24 reserve_line_number = false
25 }) 25 })
26 if result then 26 if result then
27 codes[#codes + 1] = result 27 codes[#codes + 1] = result
28 elseif not err:match("macro exporting module only accepts macro definition") then 28 elseif not err:match("macro exporting module only accepts macro definition") then
29 print(err) 29 print(err)
30 os.exit(1) 30 os.exit(1)
31 end
32 end 31 end
33 for code in text:gmatch("<pre>(.-)</pre>") do 32 end
34 local result, err = to_lua(code:gsub("&lt;", "<"):gsub("&gt;", ">"), { 33 for code in text:gmatch("<pre>(.-)</pre>") do
35 implicit_return_root = false, 34 local result, err = to_lua(code:gsub("&lt;", "<"):gsub("&gt;", ">"), {
36 reserve_line_number = false 35 implicit_return_root = false,
37 }) 36 reserve_line_number = false
38 if result then 37 })
39 codes[#codes + 1] = result 38 if result then
40 else 39 codes[#codes + 1] = result
41 print(err) 40 else
42 os.exit(1) 41 print(err)
43 end 42 os.exit(1)
44 end 43 end
45 local output <close> = (function()
46 local _with_1 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+")
47 _with_1:write(table.concat(codes))
48 return _with_1
49 end)()
50 end 44 end
51 return _with_0 45 local output
52 end)() 46 local _with_1 = io.open(tostring(outputFolder) .. "/" .. tostring(compiledFile), "w+")
47 _with_1:write(table.concat(codes))
48 output = _with_1
49 local _close_0 <close> = output
50 end
51 input = _with_0
52 local _close_0 <close> = input
53end 53end
diff --git a/spec/outputs/unicode/attrib.lua b/spec/outputs/unicode/attrib.lua
index 58ad4b2..1c48de4 100644
--- a/spec/outputs/unicode/attrib.lua
+++ b/spec/outputs/unicode/attrib.lua
@@ -26,63 +26,63 @@ do
26 _u5143_u7d20d = _obj_2[1] 26 _u5143_u7d20d = _obj_2[1]
27end 27end
28do 28do
29 local _u5173_u95ed_u53d8_u91cfv <close> = (function() 29 local _u5173_u95ed_u53d8_u91cfv
30 if _u6807_u8bb0_u4e3a_u771f then 30 if _u6807_u8bb0_u4e3a_u771f then
31 return _u51fd_u6570_u8c03_u7528() 31 _u5173_u95ed_u53d8_u91cfv = _u51fd_u6570_u8c03_u7528()
32 else 32 else
33 return setmetatable({ }, { 33 _u5173_u95ed_u53d8_u91cfv = setmetatable({ }, {
34 __close = function(self) end 34 __close = function(self) end
35 }) 35 })
36 end 36 end
37 end)() 37 local _close_0 <close> = _u5173_u95ed_u53d8_u91cfv
38 local _u5173_u95ed_u53d8_u91cff <close> = (function() 38 local _u5173_u95ed_u53d8_u91cff
39 local _with_0 = io.open("文件.txt") 39 local _with_0 = io.open("文件.txt")
40 _with_0:write("你好") 40 _with_0:write("你好")
41 return _with_0 41 _u5173_u95ed_u53d8_u91cff = _with_0
42 end)() 42 local _close_1 <close> = _u5173_u95ed_u53d8_u91cff
43end 43end
44do 44do
45 local _u5e38_u91cfa <const> = (function() 45 local _u5e38_u91cfa
46 if true then 46 if true then
47 return 1 47 _u5e38_u91cfa = 1
48 end 48 end
49 end)() 49 local _u5173_u95ed_u53d8_u91cfb
50 local _u5173_u95ed_u53d8_u91cfb <close> = (function() 50 if not false then
51 if not false then 51 if _u6761_u4ef6x then
52 if _u6761_u4ef6x then 52 _u5173_u95ed_u53d8_u91cfb = 1
53 return 1
54 end
55 end 53 end
56 end)() 54 end
57 local _u5e38_u91cfc <const> = (function() 55 local _close_0 <close> = _u5173_u95ed_u53d8_u91cfb
58 if true then 56 local _u5e38_u91cfc
59 local _exp_0 = _u6761_u4ef6x 57 if true then
60 if "abc" == _exp_0 then 58 local _exp_0 = _u6761_u4ef6x
61 return 998 59 if "abc" == _exp_0 then
62 end 60 _u5e38_u91cfc = 998
63 end 61 end
64 end)() 62 end
65 local _u5173_u95ed_u53d8_u91cfd <close> = (function() 63 local _u5173_u95ed_u53d8_u91cfd
66 if (function() 64 if (function()
67 local _exp_0 = _u6761_u4ef6a 65 local _exp_0 = _u6761_u4ef6a
68 if _exp_0 ~= nil then 66 if _exp_0 ~= nil then
69 return _exp_0 67 return _exp_0
70 else 68 else
71 return _u6761_u4ef6b 69 return _u6761_u4ef6b
72 end
73 end)() then
74 return {
75 ["数值"] = _u6570_u503c
76 }
77 end 70 end
78 end)() 71 end)() then
72 _u5173_u95ed_u53d8_u91cfd = {
73 ["数值"] = _u6570_u503c
74 }
75 end
76 local _close_1 <close> = _u5173_u95ed_u53d8_u91cfd
79end 77end
80do 78do
81 local __u65e0_u6548_u53d8_u91cf <close> = (function() 79 local __u65e0_u6548_u53d8_u91cf
80 do
82 local _with_0 = io.open("文件.txt") 81 local _with_0 = io.open("文件.txt")
83 _with_0:write("你好") 82 _with_0:write("你好")
84 return _with_0 83 __u65e0_u6548_u53d8_u91cf = _with_0
85 end)() 84 end
85 local _close_0 <close> = __u65e0_u6548_u53d8_u91cf
86 local __u65e0_u6548_u53d8_u91cf <close> = setmetatable({ }, { 86 local __u65e0_u6548_u53d8_u91cf <close> = setmetatable({ }, {
87 __close = function() 87 __close = function()
88 return _u6253_u5370("第二") 88 return _u6253_u5370("第二")