Skip to content

Commit

Permalink
Do not generate compile-time deps when expanding literals, closes #3592
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 21, 2024
1 parent a00ba4f commit 16a55b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/phoenix_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1975,8 +1975,8 @@ defmodule Phoenix.Component do
'''
@doc type: :macro
defmacro attr(name, type, opts \\ []) do
type = Macro.expand_literals(type, __CALLER__)
opts = Macro.expand_literals(opts, __CALLER__)
type = Macro.expand_literals(type, %{__CALLER__ | function: {:attr, 3}})
opts = Macro.expand_literals(opts, %{__CALLER__ | function: {:attr, 3}})

quote bind_quoted: [name: name, type: type, opts: opts] do
Phoenix.Component.Declarative.__attr__!(
Expand Down
6 changes: 4 additions & 2 deletions lib/phoenix_live_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,18 @@ defmodule Phoenix.LiveView do
"""
defmacro on_mount(mod_or_mod_arg) do
caller = %{__CALLER__ | function: {:on_mount, 1}}

# While we could pass `mod_or_mod_arg` as a whole to
# expand_literals, we want to also be able to expand only
# the first element, even if the second element is not a literal.
mod_or_mod_arg =
case mod_or_mod_arg do
{mod, arg} ->
{Macro.expand_literals(mod, __CALLER__), Macro.expand_literals(arg, __CALLER__)}
{Macro.expand_literals(mod, caller), Macro.expand_literals(arg, caller)}

mod_or_mod_arg ->
Macro.expand_literals(mod_or_mod_arg, __CALLER__)
Macro.expand_literals(mod_or_mod_arg, caller)
end

quote do
Expand Down
8 changes: 4 additions & 4 deletions lib/phoenix_live_view/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ defmodule Phoenix.LiveView.Router do
"""
defmacro live(path, live_view, action \\ nil, opts \\ []) do
live_view = Macro.expand_literals(live_view, __CALLER__)
action = Macro.expand_literals(action, __CALLER__)
opts = Macro.expand_literals(opts, __CALLER__)
live_view = Macro.expand_literals(live_view, %{__CALLER__ | function: {:live, 4}})
action = Macro.expand_literals(action, %{__CALLER__ | function: {:live, 4}})
opts = Macro.expand_literals(opts, %{__CALLER__ | function: {:live, 4}})

quote bind_quoted: binding() do
{action, router_options} =
Expand Down Expand Up @@ -227,7 +227,7 @@ defmodule Phoenix.LiveView.Router do
and be executed via `on_mount` hooks.
"""
defmacro live_session(name, opts \\ [], do: block) do
opts = Macro.expand_literals(opts, __CALLER__)
opts = Macro.expand_literals(opts, %{__CALLER__ | function: {:live_session, 3}})

quote do
unquote(__MODULE__).__live_session__(__MODULE__, unquote(opts), unquote(name))
Expand Down

0 comments on commit 16a55b1

Please sign in to comment.