Skip to content

Commit e22d22e

Browse files
committed
Reset context on body expression, closes #3590
1 parent 16a55b1 commit e22d22e

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/phoenix_live_view/tokenizer.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ defmodule Phoenix.LiveView.Tokenizer do
157157

158158
defp handle_text("{" <> rest, line, column, buffer, acc, %{braces: :enabled} = state) do
159159
text_to_acc = text_to_acc(buffer, acc, line, column, state.context)
160+
state = put_in(state.context, [])
160161

161162
case handle_interpolation(rest, line, column + 1, [], 0, state) do
162163
{:ok, value, new_line, new_column, rest} ->

test/phoenix_live_view/html_formatter_test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ defmodule Phoenix.LiveView.HTMLFormatterTest do
435435
)
436436
end
437437

438+
test "avoids additional whitespace on curly with html comments" do
439+
assert_formatter_doesnt_change("""
440+
<select>
441+
<!-- Comment -->
442+
{hello + world}
443+
</select>
444+
""")
445+
end
446+
438447
test "migrates from eex to curly braces" do
439448
input = """
440449
<section>

test/phoenix_live_view/tokenizer_test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ defmodule Phoenix.LiveView.TokenizerTest do
6464
]
6565
end
6666

67+
test "followed by curly" do
68+
assert tokenize("<!-- comment -->{hello}text") == [
69+
{:text, "<!-- comment -->",
70+
%{column_end: 17, context: [:comment_start, :comment_end], line_end: 1}},
71+
{:body_expr, "hello", %{line: 1, column: 17}},
72+
{:text, "text", %{line_end: 1, column_end: 28}}
73+
]
74+
end
75+
6776
test "multiple lines and wrapped by tags" do
6877
code = """
6978
<p>

0 commit comments

Comments
 (0)