diff options
author | Li Jin <dragon-fly@qq.com> | 2024-12-19 11:26:23 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2024-12-19 11:30:01 +0800 |
commit | f38c4f94c9ba0499d923e59483d6381b97cce926 (patch) | |
tree | 945fd3658a9018dc2558ddf4f2c95d17e3a80091 /spec | |
parent | 8a3d78c4d5bfe2ba39173e91146025278bf0deb2 (diff) | |
download | yuescript-f38c4f94c9ba0499d923e59483d6381b97cce926.tar.gz yuescript-f38c4f94c9ba0499d923e59483d6381b97cce926.tar.bz2 yuescript-f38c4f94c9ba0499d923e59483d6381b97cce926.zip |
Fixed MoonScript issue # 459.v0.26.1
Supported local/const/close hoist in class body.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/class.yue | 15 | ||||
-rw-r--r-- | spec/outputs/class.lua | 60 |
2 files changed, 75 insertions, 0 deletions
diff --git a/spec/inputs/class.yue b/spec/inputs/class.yue index 49537c2..3c73ebc 100644 --- a/spec/inputs/class.yue +++ b/spec/inputs/class.yue | |||
@@ -242,4 +242,19 @@ class Foo | |||
242 | :add | 242 | :add |
243 | :<add> | 243 | :<add> |
244 | 244 | ||
245 | do | ||
246 | global xa, xb | ||
247 | class CX | ||
248 | xa = 1 | ||
249 | xb = 1 | ||
250 | new: => | ||
251 | |||
252 | do | ||
253 | class CY | ||
254 | xa = 1 | ||
255 | local xb = 2 | ||
256 | new: => print xa, xb, xc, xd | ||
257 | const xc = 3 | ||
258 | close xd = <close>: => | ||
259 | |||
245 | nil | 260 | nil |
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua index 442ff4b..aaea33c 100644 --- a/spec/outputs/class.lua +++ b/spec/outputs/class.lua | |||
@@ -1229,4 +1229,64 @@ do | |||
1229 | _base_0.__class = _class_0 | 1229 | _base_0.__class = _class_0 |
1230 | Foo = _class_0 | 1230 | Foo = _class_0 |
1231 | end | 1231 | end |
1232 | do | ||
1233 | local CX | ||
1234 | do | ||
1235 | local _class_0 | ||
1236 | local _base_0 = { } | ||
1237 | if _base_0.__index == nil then | ||
1238 | _base_0.__index = _base_0 | ||
1239 | end | ||
1240 | _class_0 = setmetatable({ | ||
1241 | __init = function(self) end, | ||
1242 | __base = _base_0, | ||
1243 | __name = "CX" | ||
1244 | }, { | ||
1245 | __index = _base_0, | ||
1246 | __call = function(cls, ...) | ||
1247 | local _self_0 = setmetatable({ }, _base_0) | ||
1248 | cls.__init(_self_0, ...) | ||
1249 | return _self_0 | ||
1250 | end | ||
1251 | }) | ||
1252 | _base_0.__class = _class_0 | ||
1253 | local self = _class_0; | ||
1254 | xa = 1 | ||
1255 | xb = 1 | ||
1256 | CX = _class_0 | ||
1257 | end | ||
1258 | end | ||
1259 | do | ||
1260 | local CY | ||
1261 | local _class_0 | ||
1262 | local xa, xb, xc, xd | ||
1263 | local _base_0 = { } | ||
1264 | if _base_0.__index == nil then | ||
1265 | _base_0.__index = _base_0 | ||
1266 | end | ||
1267 | _class_0 = setmetatable({ | ||
1268 | __init = function(self) | ||
1269 | return print(xa, xb, xc, xd) | ||
1270 | end, | ||
1271 | __base = _base_0, | ||
1272 | __name = "CY" | ||
1273 | }, { | ||
1274 | __index = _base_0, | ||
1275 | __call = function(cls, ...) | ||
1276 | local _self_0 = setmetatable({ }, _base_0) | ||
1277 | cls.__init(_self_0, ...) | ||
1278 | return _self_0 | ||
1279 | end | ||
1280 | }) | ||
1281 | _base_0.__class = _class_0 | ||
1282 | local self = _class_0; | ||
1283 | xa = 1 | ||
1284 | xb = 2 | ||
1285 | xc = 3 | ||
1286 | xd = setmetatable({ }, { | ||
1287 | __close = function(self) end | ||
1288 | }) | ||
1289 | local _close_0 <close> = xd | ||
1290 | CY = _class_0 | ||
1291 | end | ||
1232 | return nil | 1292 | return nil |