summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-07-29 09:00:17 +0800
committerLi Jin <dragon-fly@qq.com>2022-07-29 09:00:17 +0800
commitbe7fabeef0b6de9b15c2ff34e95794d87042c3bd (patch)
treed7860e34ca53416902099c39b51a9e0f1651e53e
parentc1a599fccfd3c37ad2afc743b2a49cc5290fcb9f (diff)
downloadyuescript-0.14.4.tar.gz
yuescript-0.14.4.tar.bz2
yuescript-0.14.4.zip
fix not marking variables from `import from` statement to be const issue.v0.14.4
-rw-r--r--spec/inputs/import.yue9
-rw-r--r--spec/outputs/import.lua26
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp7
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 @@
1 1
2 2
3import hello from yeah 3import hello from yeah
4import hello, world from table["cool"] 4import holla, world from table["cool"]
5
6import a, \b, c from items
7 5
6import x, \y, z from items
8 7
9import master, \ghost from find "mytable" 8import master, \ghost from find "mytable"
10 9
11
12a, yumm = 3434, "hello"
13
14
15_table_0 = 232 10_table_0 = 232
16 11
17import something from a table 12import 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 @@
1local hello = yeah.hello 1local hello = yeah.hello
2local world 2local holla, world
3do 3do
4 local _obj_0 = table["cool"] 4 local _obj_0 = table["cool"]
5 hello, world = _obj_0.hello, _obj_0.world 5 holla, world = _obj_0.holla, _obj_0.world
6end 6end
7local a, b, c = items.a, (function() 7local x, y, z = items.x, (function()
8 local _base_0 = items 8 local _base_0 = items
9 local _fn_0 = _base_0.b 9 local _fn_0 = _base_0.y
10 return _fn_0 and function(...) 10 return _fn_0 and function(...)
11 return _fn_0(_base_0, ...) 11 return _fn_0(_base_0, ...)
12 end 12 end
13end)(), items.c 13end)(), items.z
14local master, ghost 14local master, ghost
15do 15do
16 local _obj_0 = find("mytable") 16 local _obj_0 = find("mytable")
@@ -22,8 +22,6 @@ do
22 end 22 end
23 end)() 23 end)()
24end 24end
25local yumm
26a, yumm = 3434, "hello"
27local _table_0 = 232 25local _table_0 = 232
28local something 26local something
29do 27do
@@ -44,19 +42,19 @@ if indent then
44 end 42 end
45end 43end
46do 44do
47 a, b, c = z.a, z.b, z.c 45 local a, b, c = z.a, z.b, z.c
48end 46end
49do 47do
50 a, b, c = z.a, z.b, z.c 48 local a, b, c = z.a, z.b, z.c
51end 49end
52do 50do
53 a, b, c = z.a, z.b, z.c 51 local a, b, c = z.a, z.b, z.c
54end 52end
55do 53do
56 a, b, c = z.a, z.b, z.c 54 local a, b, c = z.a, z.b, z.c
57end 55end
58do 56do
59 a, b, c = z.a, z.b, z.c 57 local a, b, c = z.a, z.b, z.c
60end 58end
61do 59do
62 local module = require('module') 60 local module = require('module')
@@ -91,10 +89,10 @@ do
91 end 89 end
92end 90end
93do 91do
94 b = getmetatable(require("m")).__a 92 local b = getmetatable(require("m")).__a
95 local _obj_0 = require("m") 93 local _obj_0 = require("m")
96 local f = _obj_0.e 94 local f = _obj_0.e
97 c = getmetatable(_obj_0).__a 95 local c = getmetatable(_obj_0).__a
98 local d = require("m").c 96 local d = require("m").c
99 local g, i 97 local g, i
100 do 98 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 {
54 54
55typedef std::list<std::string> str_list; 55typedef std::list<std::string> str_list;
56 56
57const std::string_view version = "0.14.3"sv; 57const std::string_view version = "0.14.4"sv;
58const std::string_view extension = "yue"sv; 58const std::string_view extension = "yue"sv;
59 59
60class YueCompilerImpl { 60class YueCompilerImpl {
@@ -7043,7 +7043,10 @@ private:
7043 temp.push_back(indent() + "end"s + nlr(import)); 7043 temp.push_back(indent() + "end"s + nlr(import));
7044 } 7044 }
7045 out.push_back(join(temp)); 7045 out.push_back(join(temp));
7046 markDestructureConst(assignment); 7046 auto vars = getAssignVars(assignment);
7047 for (const auto& var : vars) {
7048 markVarConst(var);
7049 }
7047 } 7050 }
7048 7051
7049 std::string moduleNameFrom(ImportLiteral_t* literal) { 7052 std::string moduleNameFrom(ImportLiteral_t* literal) {