Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/phoenix_live_view/tag_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Phoenix.LiveView.TagEngine do
file: "nofile",
engine: Phoenix.LiveView.Engine
])
|> Keyword.merge(source: source, trim_eex: false)
|> Keyword.merge(source: source, trim_eex: false, strip_eex_comments: true)

source
|> TagEngine.Parser.parse!(options)
Expand Down
5 changes: 0 additions & 5 deletions lib/phoenix_live_view/tag_engine/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ defmodule Phoenix.LiveView.TagEngine.Compiler do
{state, substate}
end

## Skip EEx comments (<%!-- ... --%>)
defp handle_node({:eex_comment, _text}, substate, state) do
{state, substate}
end

## HEEx interpolation {...}
defp handle_node({:body_expr, expr, %{line: line, column: column}}, substate, state) do
ast = Code.string_to_quoted!(expr, line: line, column: column, file: state.file)
Expand Down
16 changes: 13 additions & 3 deletions lib/phoenix_live_view/tag_engine/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,19 @@ defmodule Phoenix.LiveView.TagEngine.Parser do
file = Keyword.get(opts, :file, "nofile")
indentation = Keyword.get(opts, :indentation, 0)
trim_eex = Keyword.get(opts, :trim_eex, true)
strip_eex_comments = Keyword.get(opts, :strip_eex_comments, false)
{:ok, eex_nodes} = EEx.tokenize(source, opts)

{tokens, cont} =
Enum.reduce(
eex_nodes,
{[], {:text, :enabled}},
&do_tokenize(&1, &2, source, %{file: file, indentation: indentation, trim_eex: trim_eex})
&do_tokenize(&1, &2, source, %{
file: file,
indentation: indentation,
trim_eex: trim_eex,
strip_eex_comments: strip_eex_comments
})
)

Tokenizer.finalize(tokens, file, cont, source)
Expand All @@ -134,8 +140,12 @@ defmodule Phoenix.LiveView.TagEngine.Parser do
Tokenizer.tokenize(text, meta, tokens, cont, state)
end

defp do_tokenize({:comment, text, meta}, {tokens, cont}, _contents, _opts) do
{[{:eex_comment, List.to_string(text), meta} | tokens], cont}
defp do_tokenize({:comment, text, meta}, {tokens, cont}, _contents, opts) do
if opts.strip_eex_comments do
{tokens, cont}
else
{[{:eex_comment, List.to_string(text), meta} | tokens], cont}
end
end

defp do_tokenize(
Expand Down
1 change: 1 addition & 0 deletions test/phoenix_live_view/html_engine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ defmodule Phoenix.LiveView.HTMLEngineTest do

assert eval(" <foo></foo> ").root == true
assert eval("\n\n<foo></foo>\n").root == true
assert eval("<%!-- comment --%>\n\n<foo></foo>\n").root == true
end

test "invalid cases" do
Expand Down
Loading