From 74d2d5c51702b7355981331b3d069acc47d324b6 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 4 Mar 2026 12:05:15 +0800 Subject: Fixed empty lines in statement reserving issue. --- src/yuescript/yue_compiler.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index cca0179..861c547 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -78,7 +78,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.33.8"sv; +const std::string_view version = "0.33.9"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -5363,8 +5363,12 @@ private: if (auto comment = ast_cast(node)) { transformComment(comment, temp); continue; - } - if (!ast_is(node)) { + } else if (ast_is(node)) { + if (_config.reserveComment) { + temp.push_back("\n"s); + } + continue; + } else if (!ast_is(node)) { continue; } auto transformNode = [&]() { @@ -8376,10 +8380,11 @@ private: case id(): transformTableBlock(static_cast(item), temp); break; default: YUEE("AST node mismatch", item); break; } + auto ind = temp.back().empty() ? Empty : indent(); if (skipComma) { - temp.back() = indent() + temp.back() + '\n'; + temp.back() = ind + temp.back() + '\n'; } else { - temp.back() = indent() + (item == lastValueNode ? temp.back() : temp.back() + ',') + nl(item); + temp.back() = ind + (item == lastValueNode ? temp.back() : temp.back() + ',') + nl(item); } } if (metatable->values.empty() && !metatableItem) { @@ -10008,7 +10013,8 @@ private: if (!commentOrEmpty.empty()) { for (auto& item : commentOrEmpty) { auto [content, newLine, isComment] = std::move(item); - target.emplace_back(indent(1) + content, newLine, isComment); + auto ind = content.empty() ? Empty : indent(1); + target.emplace_back(ind + content, newLine, isComment); } commentOrEmpty.clear(); } -- cgit v1.2.3-55-g6feb