Skip to content

[EEx] Allow commenting inside case & cond clauses #11307

@tcitworld

Description

@tcitworld

Environment

  • Elixir & Erlang/OTP versions (elixir --version): Erlang/OTP 24, Elixir 1.12.1
  • Operating system: Fedora 35

Current behavior

The following EEx template doesn't compile when a comment lies between the case/cond do and the first clause. I would expect blocks starting with <%# to be ignored by the compiler and not interpreted as an expression.

EEx.compile_string("""
<%= case true do %>
<%# comment %>
<% true -> %>
  false
<% false -> %>
  true
<% end %>
""")
** (SyntaxError) nofile:4: unexpected operator ->. If you want to define multiple clauses, the first expression must use ->. Syntax error before: '->'

If the comment is placed in the first clause (or anytime later), it works properly.

EEx.compile_string("""
<%= case true do %>
<% true -> %>
  <%# comment %>
  false
<% false -> %>
  true
<% end %>
""")

Expected behavior

I would expect a similar behavior than:

case true do
  # comment
  true -> true
  false -> false
end

It can make sense to put a comment to explain what this clause means before the clause itself.

Possibly related: #10256

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions