From 635ce55c778eb0ccf0cb0f5d495402dbbb42deb1 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 20 Feb 2026 21:17:16 +0800 Subject: Skip line-number comments on empty lines in table/class blocks --- spec/cli/test_compilation.sh | 21 +++++++++++++++++++++ src/yuescript/yue_compiler.cpp | 3 +++ 2 files changed, 24 insertions(+) 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 assert_success "Compile with line numbers" $YUE_BIN -l "$TMP_DIR/test_line.yue" -o "$TMP_DIR/test_line.lua" assert_output_contains "Compiled file should have line comment" "yue" cat "$TMP_DIR/test_line.lua" +cat > "$TMP_DIR/test_line_empty_block.yue" << 'EOF' +x = { + 1 + + 2 +} + +y = + a: 1 + + b: 2 + +Z = class + m: 1 + + n: 2 +EOF + +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" +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" + # Test 7: Compile with spaces instead of tabs (-s) echo "" 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: const std::string nl(ast_node* node) const { if (_config.reserveLineNumber) { + if (ast_is(node)) { + return _newLine; + } return " -- "s + std::to_string(node->m_begin.m_line + _config.lineOffset) + _newLine; } else { return _newLine; -- cgit v1.2.3-55-g6feb