From bae594f764c058bf1c1b872109aba6cf29e4e3bf Mon Sep 17 00:00:00 2001 From: Jonas Porto Date: Thu, 29 Oct 2026 20:20:57 -0300 Subject: [PATCH] Engine: Honor `# herb:debug disable` on an output tag --- lib/herb/engine/visitors/debug_visitor.rb | 2 +- test/engine/debug_mode_test.rb | 21 +++++++++++++++++++ ..._span_21a1a29b0d0f10840b6b9dceab214fc6.txt | 6 ++++++ ...apped_2e8f389887f5a32d9e10aaa0100b6fa9.txt | 8 +++++++ ...space_7a9f3c801b42d671a6ffda3265ee0e94.txt | 6 ++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/snapshots/engine/debug_mode_test/test_0072_output_tag_with_debug_disable_comment_does_NOT_get_debug_span_21a1a29b0d0f10840b6b9dceab214fc6.txt create mode 100644 test/snapshots/engine/debug_mode_test/test_0073_output_tag_with_debug_disable_comment_leaves_the_other_output_tags_wrapped_2e8f389887f5a32d9e10aaa0100b6fa9.txt create mode 100644 test/snapshots/engine/debug_mode_test/test_0074_output_tag_with_debug_disable_comment_and_extra_whitespace_7a9f3c801b42d671a6ffda3265ee0e94.txt diff --git a/lib/herb/engine/visitors/debug_visitor.rb b/lib/herb/engine/visitors/debug_visitor.rb index 548f2a005..d06682589 100644 --- a/lib/herb/engine/visitors/debug_visitor.rb +++ b/lib/herb/engine/visitors/debug_visitor.rb @@ -81,7 +81,7 @@ def visit_erb_content_node(node) if !@in_attribute && !@in_html_comment && !@in_html_doctype && !in_excluded_context? && erb_output?(node.tag_opening.value) code = node.content.value.strip - @erb_nodes_to_wrap << node unless complex_rails_helper?(code) + @erb_nodes_to_wrap << node unless complex_rails_helper?(code) || include_debug_disable_comment?(code) end super diff --git a/test/engine/debug_mode_test.rb b/test/engine/debug_mode_test.rb index e978dca05..58fd36375 100644 --- a/test/engine/debug_mode_test.rb +++ b/test/engine/debug_mode_test.rb @@ -649,6 +649,27 @@ def inspect assert_snapshot_matches(compiled, "debug_mode_test-0") end + test "output tag with debug disable comment does NOT get debug span" do + template = %(<%= tag.td "Ada", id: "cell_1" # herb:debug disable %>) + + assert_compiled_snapshot(template, visitors: [Herb::Engine::DebugVisitor.new], filename: "app/views/people/_cell.html.erb") + end + + test "output tag with debug disable comment leaves the other output tags wrapped" do + template = <<~ERB + <%= tag.tr tag.td(@name), id: "row_1" # herb:debug disable %> +

<%= @name %>

+ ERB + + assert_compiled_snapshot(template, visitors: [Herb::Engine::DebugVisitor.new], filename: "app/views/people/_row.html.erb") + end + + test "output tag with debug disable comment and extra whitespace" do + template = %(<%= tag.td "Ada" # herb:debug disable %>) + + assert_compiled_snapshot(template, visitors: [Herb::Engine::DebugVisitor.new]) + end + describe "marking which render a tag came from" do def visitors_for(node:, instrument: true) visitors = [Herb::Engine::DebugVisitor.new(node: node)] diff --git a/test/snapshots/engine/debug_mode_test/test_0072_output_tag_with_debug_disable_comment_does_NOT_get_debug_span_21a1a29b0d0f10840b6b9dceab214fc6.txt b/test/snapshots/engine/debug_mode_test/test_0072_output_tag_with_debug_disable_comment_does_NOT_get_debug_span_21a1a29b0d0f10840b6b9dceab214fc6.txt new file mode 100644 index 000000000..4de62d07a --- /dev/null +++ b/test/snapshots/engine/debug_mode_test/test_0072_output_tag_with_debug_disable_comment_does_NOT_get_debug_span_21a1a29b0d0f10840b6b9dceab214fc6.txt @@ -0,0 +1,6 @@ +--- +source: "Engine::DebugModeTest#test_0072_output tag with debug disable comment does NOT get debug span" +input: "{source: \"<%= tag.td \\\"Ada\\\", id: \\\"cell_1\\\" # herb:debug disable %>\", options: {visitors: [#], filename: \"app/views/people/_cell.html.erb\"}}" +--- +_buf = ::String.new; _buf << (tag.td "Ada", id: "cell_1").to_s; +_buf.to_s diff --git a/test/snapshots/engine/debug_mode_test/test_0073_output_tag_with_debug_disable_comment_leaves_the_other_output_tags_wrapped_2e8f389887f5a32d9e10aaa0100b6fa9.txt b/test/snapshots/engine/debug_mode_test/test_0073_output_tag_with_debug_disable_comment_leaves_the_other_output_tags_wrapped_2e8f389887f5a32d9e10aaa0100b6fa9.txt new file mode 100644 index 000000000..4dab67544 --- /dev/null +++ b/test/snapshots/engine/debug_mode_test/test_0073_output_tag_with_debug_disable_comment_leaves_the_other_output_tags_wrapped_2e8f389887f5a32d9e10aaa0100b6fa9.txt @@ -0,0 +1,8 @@ +--- +source: "Engine::DebugModeTest#test_0073_output tag with debug disable comment leaves the other output tags wrapped" +input: "{source: \"<%= tag.tr tag.td(@name), id: \\\"row_1\\\" # herb:debug disable %>\\n

<%= @name %>

\\n\", options: {visitors: [#], filename: \"app/views/people/_row.html.erb\"}}" +--- +_buf = ::String.new; _buf << (tag.tr tag.td(@name), id: "row_1").to_s; _buf << ' +

'.freeze; _buf << (@name).to_s; _buf << '

+'.freeze; +_buf.to_s diff --git a/test/snapshots/engine/debug_mode_test/test_0074_output_tag_with_debug_disable_comment_and_extra_whitespace_7a9f3c801b42d671a6ffda3265ee0e94.txt b/test/snapshots/engine/debug_mode_test/test_0074_output_tag_with_debug_disable_comment_and_extra_whitespace_7a9f3c801b42d671a6ffda3265ee0e94.txt new file mode 100644 index 000000000..f7d0be8b4 --- /dev/null +++ b/test/snapshots/engine/debug_mode_test/test_0074_output_tag_with_debug_disable_comment_and_extra_whitespace_7a9f3c801b42d671a6ffda3265ee0e94.txt @@ -0,0 +1,6 @@ +--- +source: "Engine::DebugModeTest#test_0074_output tag with debug disable comment and extra whitespace" +input: "{source: \"<%= tag.td \\\"Ada\\\" # herb:debug disable %>\", options: {visitors: [#]}}" +--- +_buf = ::String.new; _buf << (tag.td "Ada").to_s; +_buf.to_s