Skip to content

Commit 328541b

Browse files
committed
We don't need import_file/2
Since the argument to import_file/1 has to be a literal, it's not that difficult to construct desired path by hand
1 parent 85b7684 commit 328541b

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule IEx.Helpers do
2525
* `t/1` — prints type information
2626
* `v/0` - prints all commands and values
2727
* `v/1` - retrieves nth value from console
28-
* `import_file/1`, `import_file/2` - evaluate the given file in the shell's context
28+
* `import_file/1` - evaluate the given file in the shell's context
2929
3030
Help for functions in this module can be consulted
3131
directly from the command line, as an example, try:
@@ -375,13 +375,9 @@ defmodule IEx.Helpers do
375375

376376
@doc """
377377
Evaluates the contents of file at `path` as if it were directly typed into
378-
the shell. When `relative_to` is provided, `path` is treated as being
379-
relative to that (unless it is already an absolute path). See `Path.expand`
380-
for more details.
378+
the shell. `path` has to be a literal binary.
381379
382-
Both `path` and `relative_to` (if present) have to be literal binaries.
383-
384-
Leading `~` in `path` and `relative_to` is automatically expanded.
380+
Leading `~` in `path` is automatically expanded.
385381
386382
## Examples
387383
@@ -394,22 +390,12 @@ defmodule IEx.Helpers do
394390
iex(2)> value
395391
13
396392
"""
397-
defmacro import_file(path, relative_to // nil)
398-
399-
defmacro import_file(path, relative_to)
400-
when is_binary(path) and (nil?(relative_to) or is_binary(relative_to)) do
401-
if relative_to do
402-
inject_file Path.expand(path, relative_to)
403-
else
404-
inject_file Path.expand(path)
405-
end
406-
end
407-
408-
defmacro import_file(_, _) do
409-
raise "import_file expects literal binaries as its arguments"
393+
defmacro import_file(path) when is_binary(path) do
394+
path = Path.expand(path)
395+
Code.string_to_ast! File.read!(path), file: path
410396
end
411397

412-
defp inject_file(path) do
413-
Code.string_to_ast! File.read!(path), file: path
398+
defmacro import_file(_) do
399+
raise "import_file/1 expects a literal binary as its argument"
414400
end
415401
end

0 commit comments

Comments
 (0)