diff options
author | Li Jin <dragon-fly@qq.com> | 2022-04-06 18:03:49 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-04-06 18:03:49 +0800 |
commit | 9af15048c75e845d9f6f647a3ebe2f538fac995c (patch) | |
tree | 9745928383df49940d6e17a95c269a1ae91b82f5 | |
parent | fe6ce26a58f23311cda3e82b3dfd3a55b9b16bc8 (diff) | |
download | yuescript-9af15048c75e845d9f6f647a3ebe2f538fac995c.tar.gz yuescript-9af15048c75e845d9f6f647a3ebe2f538fac995c.tar.bz2 yuescript-9af15048c75e845d9f6f647a3ebe2f538fac995c.zip |
allow doing mixin with a class and a table.
-rw-r--r-- | spec/inputs/class.yue | 2 | ||||
-rw-r--r-- | spec/outputs/class.lua | 7 | ||||
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 2 |
3 files changed, 7 insertions, 4 deletions
diff --git a/spec/inputs/class.yue b/spec/inputs/class.yue index 82dbef6..c7be481 100644 --- a/spec/inputs/class.yue +++ b/spec/inputs/class.yue | |||
@@ -229,7 +229,7 @@ do | |||
229 | class extends lapis.Application | 229 | class extends lapis.Application |
230 | "/": => json: { status: true } | 230 | "/": => json: { status: true } |
231 | 231 | ||
232 | class A using B, C, D | 232 | class A using B, C, D, {value: 123} |
233 | 233 | ||
234 | class Example | 234 | class Example |
235 | @field1 = 1 | 235 | @field1 = 1 |
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua index bb14ad8..f0482f9 100644 --- a/spec/outputs/class.lua +++ b/spec/outputs/class.lua | |||
@@ -1107,11 +1107,14 @@ do | |||
1107 | local _list_0 = { | 1107 | local _list_0 = { |
1108 | B, | 1108 | B, |
1109 | C, | 1109 | C, |
1110 | D | 1110 | D, |
1111 | { | ||
1112 | value = 123 | ||
1113 | } | ||
1111 | } | 1114 | } |
1112 | for _index_0 = 1, #_list_0 do | 1115 | for _index_0 = 1, #_list_0 do |
1113 | local _mixin_0 = _list_0[_index_0] | 1116 | local _mixin_0 = _list_0[_index_0] |
1114 | for _key_0, _val_0 in pairs(_mixin_0.__base) do | 1117 | for _key_0, _val_0 in pairs(_mixin_0.__class and _mixin_0.__base or _mixin_0) do |
1115 | if _base_0[_key_0] == nil then | 1118 | if _base_0[_key_0] == nil then |
1116 | _base_0[_key_0] = _val_0 | 1119 | _base_0[_key_0] = _val_0 |
1117 | end | 1120 | end |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 3e9c048..3c2f809 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -5418,7 +5418,7 @@ private: | |||
5418 | auto val = getUnusedName("_val_"sv); | 5418 | auto val = getUnusedName("_val_"sv); |
5419 | auto mixins = _parser.toString(classDecl->mixes); | 5419 | auto mixins = _parser.toString(classDecl->mixes); |
5420 | _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; | 5420 | _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; |
5421 | _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base\n"sv; | 5421 | _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__class and "sv << mixin << ".__base or "sv << mixin << '\n'; |
5422 | _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << baseVar << '[' << key << "]==nil"sv; | 5422 | _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << baseVar << '[' << key << "]==nil"sv; |
5423 | transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); | 5423 | transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); |
5424 | } | 5424 | } |