From be7fabeef0b6de9b15c2ff34e95794d87042c3bd Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 29 Jul 2022 09:00:17 +0800 Subject: fix not marking variables from `import from` statement to be const issue. --- spec/inputs/import.yue | 9 ++------- spec/outputs/import.lua | 26 ++++++++++++-------------- src/yuescript/yue_compiler.cpp | 7 +++++-- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/spec/inputs/import.yue b/spec/inputs/import.yue index e206d04..570b909 100644 --- a/spec/inputs/import.yue +++ b/spec/inputs/import.yue @@ -1,17 +1,12 @@ import hello from yeah -import hello, world from table["cool"] - -import a, \b, c from items +import holla, world from table["cool"] +import x, \y, z from items import master, \ghost from find "mytable" - -a, yumm = 3434, "hello" - - _table_0 = 232 import something from a table diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua index 6979e47..edb7c44 100644 --- a/spec/outputs/import.lua +++ b/spec/outputs/import.lua @@ -1,16 +1,16 @@ local hello = yeah.hello -local world +local holla, world do local _obj_0 = table["cool"] - hello, world = _obj_0.hello, _obj_0.world + holla, world = _obj_0.holla, _obj_0.world end -local a, b, c = items.a, (function() +local x, y, z = items.x, (function() local _base_0 = items - local _fn_0 = _base_0.b + local _fn_0 = _base_0.y return _fn_0 and function(...) return _fn_0(_base_0, ...) end -end)(), items.c +end)(), items.z local master, ghost do local _obj_0 = find("mytable") @@ -22,8 +22,6 @@ do end end)() end -local yumm -a, yumm = 3434, "hello" local _table_0 = 232 local something do @@ -44,19 +42,19 @@ if indent then end end do - a, b, c = z.a, z.b, z.c + local a, b, c = z.a, z.b, z.c end do - a, b, c = z.a, z.b, z.c + local a, b, c = z.a, z.b, z.c end do - a, b, c = z.a, z.b, z.c + local a, b, c = z.a, z.b, z.c end do - a, b, c = z.a, z.b, z.c + local a, b, c = z.a, z.b, z.c end do - a, b, c = z.a, z.b, z.c + local a, b, c = z.a, z.b, z.c end do local module = require('module') @@ -91,10 +89,10 @@ do end end do - b = getmetatable(require("m")).__a + local b = getmetatable(require("m")).__a local _obj_0 = require("m") local f = _obj_0.e - c = getmetatable(_obj_0).__a + local c = getmetatable(_obj_0).__a local d = require("m").c local g, i do diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 6213631..868bf90 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -54,7 +54,7 @@ namespace yue { typedef std::list str_list; -const std::string_view version = "0.14.3"sv; +const std::string_view version = "0.14.4"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -7043,7 +7043,10 @@ private: temp.push_back(indent() + "end"s + nlr(import)); } out.push_back(join(temp)); - markDestructureConst(assignment); + auto vars = getAssignVars(assignment); + for (const auto& var : vars) { + markVarConst(var); + } } std::string moduleNameFrom(ImportLiteral_t* literal) { -- cgit v1.2.3-55-g6feb