Skip to content

Commit 75813e4

Browse files
committed
Refactor IEx.Introspection.decompose/2
1 parent d775df0 commit 75813e4

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ defmodule IEx.Helpers do
333333
"""
334334
defmacro open(term) do
335335
quote do
336-
IEx.Introspection.open(unquote(IEx.Introspection.decompose(term, __CALLER__)))
336+
IEx.Introspection.open(unquote(Macro.escape(IEx.Introspection.decompose(term, __CALLER__))))
337337
end
338338
end
339339

@@ -362,7 +362,7 @@ defmodule IEx.Helpers do
362362
"""
363363
defmacro h(term) do
364364
quote do
365-
IEx.Introspection.h(unquote(IEx.Introspection.decompose(term, __CALLER__)))
365+
IEx.Introspection.h(unquote(Macro.escape(IEx.Introspection.decompose(term, __CALLER__))))
366366
end
367367
end
368368

@@ -381,7 +381,7 @@ defmodule IEx.Helpers do
381381
"""
382382
defmacro b(term) do
383383
quote do
384-
IEx.Introspection.b(unquote(IEx.Introspection.decompose(term, __CALLER__)))
384+
IEx.Introspection.b(unquote(Macro.escape(IEx.Introspection.decompose(term, __CALLER__))))
385385
end
386386
end
387387

@@ -406,7 +406,7 @@ defmodule IEx.Helpers do
406406
"""
407407
defmacro t(term) do
408408
quote do
409-
IEx.Introspection.t(unquote(IEx.Introspection.decompose(term, __CALLER__)))
409+
IEx.Introspection.t(unquote(Macro.escape(IEx.Introspection.decompose(term, __CALLER__))))
410410
end
411411
end
412412

lib/iex/lib/iex/introspection.ex

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ defmodule IEx.Introspection do
1111
Decomposes an introspection call into `{mod, fun, arity}`,
1212
`{mod, fun}` or `mod`.
1313
"""
14+
def decompose(atom, _context) when is_atom(atom), do: atom
15+
16+
def decompose({:__aliases__, _, _} = module, context) do
17+
Macro.expand(module, context)
18+
end
19+
1420
def decompose({:/, _, [call, arity]} = term, context) do
1521
case Macro.decompose_call(call) do
1622
{_mod, :__info__, []} when arity == 1 ->
17-
{:{}, [], [Module, :__info__, 1]}
23+
{Module, :__info__, 1}
1824

1925
{mod, fun, []} ->
20-
{:{}, [], [mod, fun, arity]}
26+
{Macro.expand(mod, context), fun, arity}
2127

2228
{fun, []} ->
23-
{:{}, [], [find_decompose_fun_arity(fun, arity, context), fun, arity]}
29+
{find_decompose_fun_arity(fun, arity, context), fun, arity}
2430

2531
_ ->
2632
term
@@ -30,20 +36,20 @@ defmodule IEx.Introspection do
3036
def decompose(call, context) do
3137
case Macro.decompose_call(call) do
3238
{_mod, :__info__, []} ->
33-
Macro.escape({Module, :__info__, 1})
34-
35-
{mod, fun, []} ->
36-
{mod, fun}
39+
{Module, :__info__, 1}
3740

3841
{maybe_sigil, [_, _]} ->
3942
case Atom.to_string(maybe_sigil) do
4043
"sigil_" <> _ ->
41-
{:{}, [], [find_decompose_fun_arity(maybe_sigil, 2, context), maybe_sigil, 2]}
44+
{find_decompose_fun_arity(maybe_sigil, 2, context), maybe_sigil, 2}
4245

4346
_ ->
4447
call
4548
end
4649

50+
{mod, fun, []} ->
51+
{Macro.expand(mod, context), fun}
52+
4753
{fun, []} ->
4854
{find_decompose_fun(fun, context), fun}
4955

lib/mix/lib/mix/tasks/help.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ defmodule Mix.Tasks.Help do
106106
module
107107
|> Code.string_to_quoted!()
108108
|> IEx.Introspection.decompose(__ENV__)
109-
|> Code.eval_quoted()
110-
|> elem(0)
111109
|> IEx.Introspection.h()
112110
after
113111
Application.put_env(:iex, :colors, iex_colors)

0 commit comments

Comments
 (0)