-
Notifications
You must be signed in to change notification settings - Fork 935
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
Reserve {
outside of attributes
#3498
Reserve {
outside of attributes
#3498
Conversation
Before this patch, this was valid: <div id={id}>{content}</div> and the text `{content}` is rendered _as is_, without interpolation. I'd like to reserve this syntax for later and for now raise an error: iex> import Phoenix.Component, only: [sigil_H: 2] iex> assigns = %{}; ~H"<div id={id}>{content}</div>" ** (Phoenix.LiveView.Tokenizer.ParseError) iex:3:14: `{` outside of attributes is reserved, use `\\{` to escape | 1 | <div id={id}>{content}</div> (phoenix_live_view 1.0.0-rc.7) lib/phoenix_live_view/tokenizer.ex:732: Phoenix.LiveView.Tokenizer.raise_syntax_error!/3 (phoenix_live_view 1.0.0-rc.7) lib/phoenix_live_view/tag_engine.ex:295: Phoenix.LiveView.TagEngine.handle_text/3 (eex 1.18.0-dev) lib/eex/compiler.ex:331: EEx.Compiler.generate_buffer/4 (phoenix_live_view 1.0.0-rc.7) expanding macro: Phoenix.Component.sigil_H/2 iex:2: (file) If someone needs to use `{`, there's a way to escape it using `\\{`: iex> assigns = %{}; ~H"<div id={:foo}>\\{content}</div>".static ["<div", ">\\{content}</div>"] The idea is to eventually use the same interpolation syntax across the board. And when that happens, deprecate `<%= %>` in favour of `{ }`. Supporting new syntax as well as deprecating old syntax is a massive change because of existing Phoenix projects, syntax highlighters, etc. I think we should be able to automate moving from `<% %>` to `{ }` using tools like https://github.com/adobe/elixir-styler.
cc @msaraiva |
I’ll soon send and update that allows using |
I didn't have to change any code for Looks like actually implementing interpolations with |
Hey @wojtekmach!
Yes, it will be tricky and probably require a major refactor in the Question: would partial code injection using |
I'd personally rather not but I think it is much more practical and pragmatic to support |
I removed support for interpolation inside |
@@ -155,6 +155,18 @@ defmodule Phoenix.LiveView.Tokenizer do | |||
handle_tag_open(rest, line, column + 1, text_to_acc, %{state | context: []}) | |||
end | |||
|
|||
defp handle_text("{" <> rest, line, column, [?\\ | buffer], acc, state) do |
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.
I don't think we should allow escapes. Because if \{
means {
, then how do I write \{
? We would need to support \\{
and so on. We should probably follow JSX here. If you want to write {
, you can either write { "{" }
, {
or {
.
Closing in favor of #3514. |
Before this patch, this was valid:
and the text
{content}
is rendered as is, without interpolation. I'd like to reserve this syntax for later and for now raise an error:If someone needs to use
{
, there's a way to escape it using\\{
:The idea is to eventually use the same interpolation syntax across the board. And when that happens, deprecate
<%= %>
in favour of{ }
. Supporting new syntax as well as deprecating old syntax is a massive change because of existing Phoenix projects, syntax highlighters, etc. I think we should be able to automate moving from<% %>
to{ }
using tools like https://github.com/adobe/elixir-styler.