Skip to content

Commit

Permalink
Reset context on body expression, closes #3590
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 21, 2024
1 parent 16a55b1 commit e22d22e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/phoenix_live_view/tokenizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ defmodule Phoenix.LiveView.Tokenizer do

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

case handle_interpolation(rest, line, column + 1, [], 0, state) do
{:ok, value, new_line, new_column, rest} ->
Expand Down
9 changes: 9 additions & 0 deletions test/phoenix_live_view/html_formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ defmodule Phoenix.LiveView.HTMLFormatterTest do
)
end

test "avoids additional whitespace on curly with html comments" do
assert_formatter_doesnt_change("""
<select>
<!-- Comment -->
{hello + world}
</select>
""")
end

test "migrates from eex to curly braces" do
input = """
<section>
Expand Down
9 changes: 9 additions & 0 deletions test/phoenix_live_view/tokenizer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ defmodule Phoenix.LiveView.TokenizerTest do
]
end

test "followed by curly" do
assert tokenize("<!-- comment -->{hello}text") == [
{:text, "<!-- comment -->",
%{column_end: 17, context: [:comment_start, :comment_end], line_end: 1}},
{:body_expr, "hello", %{line: 1, column: 17}},
{:text, "text", %{line_end: 1, column_end: 28}}
]
end

test "multiple lines and wrapped by tags" do
code = """
<p>
Expand Down

0 comments on commit e22d22e

Please sign in to comment.