diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-07-29 09:00:17 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-07-29 09:00:17 +0800 |
| commit | be7fabeef0b6de9b15c2ff34e95794d87042c3bd (patch) | |
| tree | d7860e34ca53416902099c39b51a9e0f1651e53e | |
| parent | c1a599fccfd3c37ad2afc743b2a49cc5290fcb9f (diff) | |
| download | yuescript-be7fabeef0b6de9b15c2ff34e95794d87042c3bd.tar.gz yuescript-be7fabeef0b6de9b15c2ff34e95794d87042c3bd.tar.bz2 yuescript-be7fabeef0b6de9b15c2ff34e95794d87042c3bd.zip | |
fix not marking variables from `import from` statement to be const issue.v0.14.4
Diffstat (limited to '')
| -rw-r--r-- | spec/inputs/import.yue | 9 | ||||
| -rw-r--r-- | spec/outputs/import.lua | 26 | ||||
| -rwxr-xr-x | 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 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | import hello from yeah | 3 | import hello from yeah |
| 4 | import hello, world from table["cool"] | 4 | import holla, world from table["cool"] |
| 5 | |||
| 6 | import a, \b, c from items | ||
| 7 | 5 | ||
| 6 | import x, \y, z from items | ||
| 8 | 7 | ||
| 9 | import master, \ghost from find "mytable" | 8 | import master, \ghost from find "mytable" |
| 10 | 9 | ||
| 11 | |||
| 12 | a, yumm = 3434, "hello" | ||
| 13 | |||
| 14 | |||
| 15 | _table_0 = 232 | 10 | _table_0 = 232 |
| 16 | 11 | ||
| 17 | import something from a table | 12 | 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 @@ | |||
| 1 | local hello = yeah.hello | 1 | local hello = yeah.hello |
| 2 | local world | 2 | local holla, world |
| 3 | do | 3 | do |
| 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 |
| 6 | end | 6 | end |
| 7 | local a, b, c = items.a, (function() | 7 | local 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 |
| 13 | end)(), items.c | 13 | end)(), items.z |
| 14 | local master, ghost | 14 | local master, ghost |
| 15 | do | 15 | do |
| 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)() |
| 24 | end | 24 | end |
| 25 | local yumm | ||
| 26 | a, yumm = 3434, "hello" | ||
| 27 | local _table_0 = 232 | 25 | local _table_0 = 232 |
| 28 | local something | 26 | local something |
| 29 | do | 27 | do |
| @@ -44,19 +42,19 @@ if indent then | |||
| 44 | end | 42 | end |
| 45 | end | 43 | end |
| 46 | do | 44 | do |
| 47 | a, b, c = z.a, z.b, z.c | 45 | local a, b, c = z.a, z.b, z.c |
| 48 | end | 46 | end |
| 49 | do | 47 | do |
| 50 | a, b, c = z.a, z.b, z.c | 48 | local a, b, c = z.a, z.b, z.c |
| 51 | end | 49 | end |
| 52 | do | 50 | do |
| 53 | a, b, c = z.a, z.b, z.c | 51 | local a, b, c = z.a, z.b, z.c |
| 54 | end | 52 | end |
| 55 | do | 53 | do |
| 56 | a, b, c = z.a, z.b, z.c | 54 | local a, b, c = z.a, z.b, z.c |
| 57 | end | 55 | end |
| 58 | do | 56 | do |
| 59 | a, b, c = z.a, z.b, z.c | 57 | local a, b, c = z.a, z.b, z.c |
| 60 | end | 58 | end |
| 61 | do | 59 | do |
| 62 | local module = require('module') | 60 | local module = require('module') |
| @@ -91,10 +89,10 @@ do | |||
| 91 | end | 89 | end |
| 92 | end | 90 | end |
| 93 | do | 91 | do |
| 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 | ||
| 55 | typedef std::list<std::string> str_list; | 55 | typedef std::list<std::string> str_list; |
| 56 | 56 | ||
| 57 | const std::string_view version = "0.14.3"sv; | 57 | const std::string_view version = "0.14.4"sv; |
| 58 | const std::string_view extension = "yue"sv; | 58 | const std::string_view extension = "yue"sv; |
| 59 | 59 | ||
| 60 | class YueCompilerImpl { | 60 | class 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) { |
