From 1ed40360d664d397e1178eb60cf8d3fbe0881edc Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 1 Apr 2021 16:11:51 +0800 Subject: fix export assignment statement not working with local statement. --- spec/inputs/export.yue | 7 +++++++ src/lua/makefile | 2 +- src/yuescript/yue_compiler.cpp | 13 +++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/spec/inputs/export.yue b/spec/inputs/export.yue index 085510e..9113508 100644 --- a/spec/inputs/export.yue +++ b/spec/inputs/export.yue @@ -77,3 +77,10 @@ _ = "#{with a _ = "#{a?.b}" _ = "#{a\b}" _ = "#{class A}" + +local * +v1 = 1 +export v2 = 2 +export v3 = class v4 +v5 = 5 + diff --git a/src/lua/makefile b/src/lua/makefile index 8e11fa3..ccd5315 100644 --- a/src/lua/makefile +++ b/src/lua/makefile @@ -61,7 +61,7 @@ else endif CC= gcc -CFLAGS= -Wall -O2 $(MYCFLAGS) -fno-stack-protector -fno-common -march=native +CFLAGS= -Wall -O2 $(MYCFLAGS) -fno-stack-protector -fno-common AR= ar rc RANLIB= ranlib RM= rm -f diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index f27a810..38456cc 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -59,7 +59,7 @@ inline std::string s(std::string_view sv) { return std::string(sv); } -const std::string_view version = "0.7.3"sv; +const std::string_view version = "0.7.4"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -2343,7 +2343,16 @@ private: } } else if (mode != LocalMode::None) { ClassDecl_t* classDecl = nullptr; - if (auto assignment = assignmentFrom(stmt)) { + ast_ptr assignment; + if (auto exportNode = stmt->content.as()) { + if (exportNode->assign) { + assignment = stmt->new_ptr(); + assignment->expList.set(exportNode->target); + assignment->action.set(exportNode->assign); + } + } + if (!assignment) assignment = assignmentFrom(stmt); + if (assignment) { auto vars = getAssignVars(assignment); for (const auto& var : vars) { if (var.empty()) continue; -- cgit v1.2.3-55-g6feb