Skip to content

Commit 8eed9af

Browse files
committed
fix another whitespace bug
1 parent bb38d91 commit 8eed9af

5 files changed

+28
-3
lines changed

‎lib/herb/engine/compiler.rb‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,18 @@ def at_line_start?
512512
@tokens.last[0] != :text ||
513513
@tokens.last[1].empty? ||
514514
@tokens.last[1].end_with?("\n") ||
515-
@tokens.last[1] =~ /\A[ \t]+\z/ ||
515+
(@tokens.last[1] =~ /\A[ \t]+\z/ && preceding_token_ends_with_newline?) ||
516516
@tokens.last[1] =~ /\n[ \t]+\z/
517517
end
518518

519+
def preceding_token_ends_with_newline?
520+
preceding = @tokens.length >= 2 ? @tokens[-2] : nil
521+
return true unless preceding
522+
return true unless preceding[0] == :text
523+
524+
preceding[1].end_with?("\n")
525+
end
526+
519527
def extract_lspace
520528
return "" unless @tokens.last && @tokens.last[0] == :text
521529

‎test/engine/whitespace_trimming_test.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,12 @@ class WhitespaceTrimmingTest < Minitest::Spec
169169
assert_compiled_snapshot(template)
170170
assert_evaluated_snapshot(template, enforce_erubi_equality: true)
171171
end
172+
173+
test "inline space between close tag and ERB control tag is preserved" do
174+
template = "<strong>Foo:</strong> <% if true %>Bar<% end %>"
175+
176+
assert_compiled_snapshot(template)
177+
assert_evaluated_snapshot(template, enforce_erubi_equality: true)
178+
end
172179
end
173180
end

‎test/snapshots/engine/examples_compilation_test/test_0013_doctype_compilation_8c18fb8399a2fd1e65b0333bc01e041c.txt‎

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/snapshots/engine/whitespace_trimming_test/test_0019_inline_space_between_close_tag_and_ERB_control_tag_is_preserved_0280ea5ce8087e601da098dec2ea2502.txt‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/snapshots/engine/whitespace_trimming_test/test_0019_inline_space_between_close_tag_and_ERB_control_tag_is_preserved_c014a9212a83aca0d5a68e0e5e61c05d.txt‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)