From 52c750ece75211117f4d86a694d774b3317e61c6 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Sat, 5 Sep 2020 22:56:23 +0900 Subject: [PATCH] Parser: apply string pieces combination even if heredoc has no indent (#9475) Fixed #9473 It is important to simplify the formatter implementation. --- spec/compiler/formatter/formatter_spec.cr | 2 ++ src/compiler/crystal/syntax/parser.cr | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index bb07ee7dad48..0185c1cd0c5d 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -999,6 +999,8 @@ describe Crystal::Formatter do assert_format "<<-FOO\n#{"foo"}bar\nFOO" assert_format "<<-FOO\nbar#{"foo"}\nFOO" assert_format "<<-FOO\nbar#{"foo"}bar\nFOO" + assert_format "<<-FOO\nfoo\n#{"foo"}\nFOO" + assert_format "<<-FOO\nfoo\n#{1}\nFOO" assert_format "#!shebang\n1 + 2" diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index bdc3ab64e817..448b6fefc61c 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -2145,7 +2145,7 @@ module Crystal end def needs_heredoc_indent_removed?(delimiter_state) - delimiter_state.kind == :heredoc && delimiter_state.heredoc_indent > 0 + delimiter_state.kind == :heredoc && delimiter_state.heredoc_indent >= 0 end def remove_heredoc_indent(pieces : Array, indent)