aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/inputs/in_expression.yue2
-rw-r--r--spec/outputs/in_expression.lua5
-rw-r--r--src/yuescript/yue_ast.h2
-rw-r--r--src/yuescript/yue_compiler.cpp10
4 files changed, 16 insertions, 3 deletions
diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue
index 2756fe8..dacf820 100644
--- a/spec/inputs/in_expression.yue
+++ b/spec/inputs/in_expression.yue
@@ -4,6 +4,8 @@ a, b = x(...) not in [1, 3], 2
4 4
5d = (tb.x.y ...) not in [1, 3] 5d = (tb.x.y ...) not in [1, 3]
6 6
7has = "foo" in { "bar", "foo" }
8
7if a in {1} and b in {2, 3, 4} or c in [1, 10] 9if a in {1} and b in {2, 3, 4} or c in [1, 10]
8 print a, b, c 10 print a, b, c
9 11
diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua
index 061431f..8b37a72 100644
--- a/spec/outputs/in_expression.lua
+++ b/spec/outputs/in_expression.lua
@@ -11,6 +11,11 @@ do
11 local _val_0 = (tb.x.y(...)) 11 local _val_0 = (tb.x.y(...))
12 d = not (1 <= _val_0 and _val_0 <= 3) 12 d = not (1 <= _val_0 and _val_0 <= 3)
13end 13end
14local has
15do
16 local _val_0 = "foo"
17 has = "bar" == _val_0 or "foo" == _val_0
18end
14if (1 == a) and (2 == b or 3 == b or 4 == b) or (function() 19if (1 == a) and (2 == b or 3 == b or 4 == b) or (function()
15 local _val_0 = c 20 local _val_0 = c
16 return 1 <= _val_0 and _val_0 <= 10 21 return 1 <= _val_0 and _val_0 <= 10
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index c47ba8a..85a1e52 100644
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -910,7 +910,7 @@ struct YueFormat {
910 int tabSpaces = 4; 910 int tabSpaces = 4;
911 std::string toString(ast_node* node); 911 std::string toString(ast_node* node);
912 912
913 Converter converter; 913 Converter converter{};
914 void pushScope(); 914 void pushScope();
915 void popScope(); 915 void popScope();
916 std::string convert(const ast_node* node); 916 std::string convert(const ast_node* node);
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index c1426f9..efd0aed 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -72,7 +72,7 @@ static std::unordered_set<std::string> Metamethods = {
72 "close"s // Lua 5.4 72 "close"s // Lua 5.4
73}; 73};
74 74
75const std::string_view version = "0.17.2"sv; 75const std::string_view version = "0.17.3"sv;
76const std::string_view extension = "yue"sv; 76const std::string_view extension = "yue"sv;
77 77
78class CompileError : public std::logic_error { 78class CompileError : public std::logic_error {
@@ -5429,7 +5429,13 @@ private:
5429 for (auto exp : discrete->values.objects()) { 5429 for (auto exp : discrete->values.objects()) {
5430 transformExp(static_cast<Exp_t*>(exp), tmp, ExpUsage::Closure); 5430 transformExp(static_cast<Exp_t*>(exp), tmp, ExpUsage::Closure);
5431 } 5431 }
5432 _buf << indent() << "return "sv; 5432 if (usage == ExpUsage::Assignment) {
5433 str_list tmpList;
5434 transformExp(static_cast<Exp_t*>(assignList->exprs.front()), tmpList, ExpUsage::Closure);
5435 _buf << indent() << tmpList.back() << " = "sv;
5436 } else {
5437 _buf << indent() << "return "sv;
5438 }
5433 if (unary_exp->inExp->not_) { 5439 if (unary_exp->inExp->not_) {
5434 _buf << "not ("sv; 5440 _buf << "not ("sv;
5435 } 5441 }