From 53bd5a32e30493f4915e79bfb63b1eec846f1a7f Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 20 Apr 2022 09:19:59 +0800 Subject: add placeholder support for list destructuring. fix part of issue #93. --- doc/docs/doc/README.md | 6 +++--- spec/inputs/destructure.yue | 3 +++ spec/outputs/destructure.lua | 7 +++++++ src/yuescript/yue_compiler.cpp | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 5c43917..adff569 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -657,7 +657,7 @@ do The export statement offers a concise way to define modules. -* **Named Export** +* **Named Export** Named export will define a local variable as well as adding a field in the exported table. ```moonscript @@ -693,7 +693,7 @@ export class Something -* **Unnamed Export** +* **Unnamed Export** Unnamed export will add the target item into the array part of the exported table. ```moonscript @@ -723,7 +723,7 @@ export with tmp -* **Default Export** +* **Default Export** Using the **default** keyword in export statement to replace the exported table with any thing. ```moonscript diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index e1c6b27..a235abd 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue @@ -178,3 +178,6 @@ do for {left = "null", right = false} in *tuples print left, right +do + {_, a, _, b} = tb -- list placeholder + diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 1862b85..9b16181 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua @@ -358,3 +358,10 @@ do print(left, right) end end +do + local a, b + do + local _obj_0 = tb + a, b = _obj_0[2], _obj_0[4] + end +end diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index e7da2dd..17fbaf6 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -60,7 +60,7 @@ using namespace parserlib; typedef std::list str_list; -const std::string_view version = "0.10.11"sv; +const std::string_view version = "0.10.12"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -1597,6 +1597,7 @@ private: _config.lintGlobalVariable = false; auto exp = static_cast(pair); auto varName = singleVariableFrom(exp); + if (varName == "_"sv) break; bool isVariable = !varName.empty(); if (!isVariable) { str_list temp; -- cgit v1.2.3-55-g6feb