-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support {...} interpolation in body #3514
base: main
Are you sure you want to change the base?
Conversation
e2fb7d8
to
1f6bdd8
Compare
Co-authored-by: Steffen Deusch <[email protected]>
Co-authored-by: Wojtek Mach <[email protected]>
@@ -443,6 +444,14 @@ defmodule Phoenix.LiveView.TagEngine do | |||
|> update_subengine(:handle_expr, [marker, expr]) | |||
end | |||
|
|||
defp handle_token({:body_expr, value, %{line: line, column: column}}, state) do | |||
quoted = Code.string_to_quoted!(value, line: line, column: column, file: state.file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this template:
{if true do}
we currently receive this error:
** (TokenMissingError) token missing on iex:5:11:
error: missing terminator: end
│
5 │ if true do
│ │ └ missing closing delimiter (expected "end")
│ └ unclosed delimiter
│
└─ iex:5:11
which is great but maybe there's still room to improve?
If we changed Code.string_to_quoted!
to Code.string_to_quoted
we could maybe improve the error message, telling people to use :if
or <%= ... %>
. The error tuple is quite expressive:
iex> Code.string_to_quoted("if true do")
{:error,
{[
opening_delimiter: :do,
expected_delimiter: :end,
line: 1,
column: 9,
end_line: 1,
end_column: 11
], "missing terminator: end", ""}}
and I see it's like this since Elixir 1.16. Let me know if you'd like to pursue this and I'm happy to send a patch.
|
||
<%!-- Phoenix.Component.upload_errors/1 returns a list of error atoms --%> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the EEx syntax is going away it seem odd to keep it around just for comment tags. Why not a {% %}
style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not going away though, it is not possible to do {if ... do}
, {for ... do}
, etc. (Not that people should reach for those given :if and :for exists.) We can't use {...}
interpolation inside <script>
and <style>
either and for that <%= ... %>
is the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EEx syntax is not going away per se because it is still needed in some situations (such as inside script, style, and template, as escaping {
in there would be a pain) but I agree we should probably consider introducing something specific for comments later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The <%!-- --%>
comment syntax was inspired by Surface's {!-- --}
. If we're moving to curly braces in the HTML, I'd vote we use the curly comments too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for {!-- --}
style
The first commit has the code changes. The second commit runs
mix format
to migrate the codebase, so you can see if you prefer the new style or not.cc @SteffenDE @chrismccord @connorlay @msaraiva