diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-20 21:17:16 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-20 21:17:16 +0800 |
| commit | 635ce55c778eb0ccf0cb0f5d495402dbbb42deb1 (patch) | |
| tree | ec7ae2a02a188ab3789b22d9918796100c1fea7a | |
| parent | abe6859edcc85c2b2da1d6c5bdae9ac5ee2e94c5 (diff) | |
| download | yuescript-635ce55c778eb0ccf0cb0f5d495402dbbb42deb1.tar.gz yuescript-635ce55c778eb0ccf0cb0f5d495402dbbb42deb1.tar.bz2 yuescript-635ce55c778eb0ccf0cb0f5d495402dbbb42deb1.zip | |
Skip line-number comments on empty lines in table/class blockscodex/remove-line-number-comments-from-empty-lines
| -rwxr-xr-x | spec/cli/test_compilation.sh | 21 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/spec/cli/test_compilation.sh b/spec/cli/test_compilation.sh index 4ddde5a..780f135 100755 --- a/spec/cli/test_compilation.sh +++ b/spec/cli/test_compilation.sh | |||
| @@ -88,6 +88,27 @@ EOF | |||
| 88 | assert_success "Compile with line numbers" $YUE_BIN -l "$TMP_DIR/test_line.yue" -o "$TMP_DIR/test_line.lua" | 88 | assert_success "Compile with line numbers" $YUE_BIN -l "$TMP_DIR/test_line.yue" -o "$TMP_DIR/test_line.lua" |
| 89 | assert_output_contains "Compiled file should have line comment" "yue" cat "$TMP_DIR/test_line.lua" | 89 | assert_output_contains "Compiled file should have line comment" "yue" cat "$TMP_DIR/test_line.lua" |
| 90 | 90 | ||
| 91 | cat > "$TMP_DIR/test_line_empty_block.yue" << 'EOF' | ||
| 92 | x = { | ||
| 93 | 1 | ||
| 94 | |||
| 95 | 2 | ||
| 96 | } | ||
| 97 | |||
| 98 | y = | ||
| 99 | a: 1 | ||
| 100 | |||
| 101 | b: 2 | ||
| 102 | |||
| 103 | Z = class | ||
| 104 | m: 1 | ||
| 105 | |||
| 106 | n: 2 | ||
| 107 | EOF | ||
| 108 | |||
| 109 | assert_success "Compile with line numbers for table/class blocks with empty lines" $YUE_BIN -l "$TMP_DIR/test_line_empty_block.yue" -o "$TMP_DIR/test_line_empty_block.lua" | ||
| 110 | assert_success "Empty lines should not generate standalone line number comments" bash -lc '! grep -Eq "^[[:space:]]*-- [0-9]+$" "$0"' "$TMP_DIR/test_line_empty_block.lua" | ||
| 111 | |||
| 91 | # Test 7: Compile with spaces instead of tabs (-s) | 112 | # Test 7: Compile with spaces instead of tabs (-s) |
| 92 | echo "" | 113 | echo "" |
| 93 | echo "Testing compilation with spaces..." | 114 | echo "Testing compilation with spaces..." |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 6637d1f..a4ce15c 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -1033,6 +1033,9 @@ private: | |||
| 1033 | 1033 | ||
| 1034 | const std::string nl(ast_node* node) const { | 1034 | const std::string nl(ast_node* node) const { |
| 1035 | if (_config.reserveLineNumber) { | 1035 | if (_config.reserveLineNumber) { |
| 1036 | if (ast_is<EmptyLine_t>(node)) { | ||
| 1037 | return _newLine; | ||
| 1038 | } | ||
| 1036 | return " -- "s + std::to_string(node->m_begin.m_line + _config.lineOffset) + _newLine; | 1039 | return " -- "s + std::to_string(node->m_begin.m_line + _config.lineOffset) + _newLine; |
| 1037 | } else { | 1040 | } else { |
| 1038 | return _newLine; | 1041 | return _newLine; |
