diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-03-04 12:05:15 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-03-04 12:05:15 +0800 |
| commit | 74d2d5c51702b7355981331b3d069acc47d324b6 (patch) | |
| tree | f4b9424b9510be02217b3bcee2ac6edc0b2ffb2a /src | |
| parent | 6c3f69309a9b4b24c1af8d43a28e2c53a0e7d560 (diff) | |
| download | yuescript-74d2d5c51702b7355981331b3d069acc47d324b6.tar.gz yuescript-74d2d5c51702b7355981331b3d069acc47d324b6.tar.bz2 yuescript-74d2d5c51702b7355981331b3d069acc47d324b6.zip | |
Fixed empty lines in statement reserving issue.v0.33.9
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
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<std::string> Metamethods = { | |||
| 78 | "close"s // Lua 5.4 | 78 | "close"s // Lua 5.4 |
| 79 | }; | 79 | }; |
| 80 | 80 | ||
| 81 | const std::string_view version = "0.33.8"sv; | 81 | const std::string_view version = "0.33.9"sv; |
| 82 | const std::string_view extension = "yue"sv; | 82 | const std::string_view extension = "yue"sv; |
| 83 | 83 | ||
| 84 | class CompileError : public std::logic_error { | 84 | class CompileError : public std::logic_error { |
| @@ -5363,8 +5363,12 @@ private: | |||
| 5363 | if (auto comment = ast_cast<YueComment_t>(node)) { | 5363 | if (auto comment = ast_cast<YueComment_t>(node)) { |
| 5364 | transformComment(comment, temp); | 5364 | transformComment(comment, temp); |
| 5365 | continue; | 5365 | continue; |
| 5366 | } | 5366 | } else if (ast_is<EmptyLine_t>(node)) { |
| 5367 | if (!ast_is<Statement_t>(node)) { | 5367 | if (_config.reserveComment) { |
| 5368 | temp.push_back("\n"s); | ||
| 5369 | } | ||
| 5370 | continue; | ||
| 5371 | } else if (!ast_is<Statement_t>(node)) { | ||
| 5368 | continue; | 5372 | continue; |
| 5369 | } | 5373 | } |
| 5370 | auto transformNode = [&]() { | 5374 | auto transformNode = [&]() { |
| @@ -8376,10 +8380,11 @@ private: | |||
| 8376 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(item), temp); break; | 8380 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(item), temp); break; |
| 8377 | default: YUEE("AST node mismatch", item); break; | 8381 | default: YUEE("AST node mismatch", item); break; |
| 8378 | } | 8382 | } |
| 8383 | auto ind = temp.back().empty() ? Empty : indent(); | ||
| 8379 | if (skipComma) { | 8384 | if (skipComma) { |
| 8380 | temp.back() = indent() + temp.back() + '\n'; | 8385 | temp.back() = ind + temp.back() + '\n'; |
| 8381 | } else { | 8386 | } else { |
| 8382 | temp.back() = indent() + (item == lastValueNode ? temp.back() : temp.back() + ',') + nl(item); | 8387 | temp.back() = ind + (item == lastValueNode ? temp.back() : temp.back() + ',') + nl(item); |
| 8383 | } | 8388 | } |
| 8384 | } | 8389 | } |
| 8385 | if (metatable->values.empty() && !metatableItem) { | 8390 | if (metatable->values.empty() && !metatableItem) { |
| @@ -10008,7 +10013,8 @@ private: | |||
| 10008 | if (!commentOrEmpty.empty()) { | 10013 | if (!commentOrEmpty.empty()) { |
| 10009 | for (auto& item : commentOrEmpty) { | 10014 | for (auto& item : commentOrEmpty) { |
| 10010 | auto [content, newLine, isComment] = std::move(item); | 10015 | auto [content, newLine, isComment] = std::move(item); |
| 10011 | target.emplace_back(indent(1) + content, newLine, isComment); | 10016 | auto ind = content.empty() ? Empty : indent(1); |
| 10017 | target.emplace_back(ind + content, newLine, isComment); | ||
| 10012 | } | 10018 | } |
| 10013 | commentOrEmpty.clear(); | 10019 | commentOrEmpty.clear(); |
| 10014 | } | 10020 | } |
