Skip to content

Commit 408b0bb

Browse files
committed
separate module_filepaths into 2 separate passes
1 parent 217e33b commit 408b0bb

3 files changed

Lines changed: 53 additions & 28 deletions

File tree

lib/elixir_script.ex

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ defmodule ElixirScript do
6060
"""
6161
@spec compile_quoted(Macro.t, Map.t) :: [binary | {binary, binary} | :ok]
6262
def compile_quoted(quoted, opts \\ %{}) do
63+
64+
opts = build_compiler_options(opts)
65+
66+
result = %{ data: [%{ast: quoted}] }
67+
|> ElixirScript.Passes.FindModules.execute(opts)
68+
|> ElixirScript.Passes.FindDeps.execute(opts)
69+
|> ElixirScript.Passes.RemoveUnused.execute(opts)
70+
|> ElixirScript.Passes.LoadModules.execute(opts)
71+
|> ElixirScript.Passes.FindChangedFiles.execute(opts)
72+
|> ElixirScript.Passes.FindFunctions.execute(opts)
73+
|> ElixirScript.Passes.JavaScriptAST.execute(opts)
74+
|> ElixirScript.Passes.ConsolidateProtocols.execute(opts)
75+
|> ElixirScript.Passes.JavaScriptCode.execute(opts)
76+
|> ElixirScript.Passes.JavaScriptName.execute(opts)
77+
|> ElixirScript.Passes.HandleOutput.execute(opts)
78+
79+
6380
{ code, _ } = do_compile(opts, [quoted], get_stdlib_state, [])
6481
result = Output.out(quoted, code, build_compiler_options(opts))
6582
ElixirScript.Translator.State.stop
@@ -76,7 +93,8 @@ defmodule ElixirScript do
7693

7794
result = %{ path: path }
7895
|> ElixirScript.Passes.DepsPaths.execute(opts)
79-
|> ElixirScript.Passes.ModuleFilepaths.execute(opts)
96+
|> ElixirScript.Passes.ASTFromFile.execute(opts)
97+
|> ElixirScript.Passes.FindModules.execute(opts)
8098
|> ElixirScript.Passes.FindDeps.execute(opts)
8199
|> ElixirScript.Passes.RemoveUnused.execute(opts)
82100
|> ElixirScript.Passes.LoadModules.execute(opts)
@@ -172,7 +190,8 @@ defmodule ElixirScript do
172190

173191
result = %{ path: libs_path }
174192
|> ElixirScript.Passes.DepsPaths.execute(opts)
175-
|> ElixirScript.Passes.ModuleFilepaths.execute(opts)
193+
|> ElixirScript.Passes.ASTFromFile.execute(opts)
194+
|> ElixirScript.Passes.FindModules.execute(opts)
176195
#|> ElixirScript.Passes.FindDeps.execute(opts)
177196
#|> ElixirScript.Passes.RemoveUnused.execute(opts)
178197
#|> ElixirScript.Passes.LoadModules.execute(opts)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
defmodule ElixirScript.Passes.ASTFromFile do
2+
3+
4+
def execute(compiler_data, opts) do
5+
data = Enum.reduce(compiler_data.data, [], fn({dep, paths}, list) ->
6+
7+
file_paths = paths
8+
|> Enum.flat_map(fn(path) -> Path.join(path, "**/*.{ex,exs,exjs}") |> Path.wildcard end)
9+
|> Enum.reduce([], fn(path, list) ->
10+
quoted = path
11+
|> File.read!
12+
|> Code.string_to_quoted!
13+
14+
stat = File.stat!(path)
15+
16+
list ++ [%{ path: path, app: dep, stat: stat, ast: quoted }]
17+
end)
18+
19+
20+
list ++ file_paths
21+
end)
22+
23+
Map.put(compiler_data, :data, data)
24+
end
25+
26+
end

lib/elixir_script/passes/module_filepaths.ex renamed to lib/elixir_script/passes/find_modules.ex

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
1-
defmodule ElixirScript.Passes.ModuleFilepaths do
1+
defmodule ElixirScript.Passes.FindModules do
22
@pass 2
33

44
alias ElixirScript.Translator.Utils
55

6-
7-
#TODO: Split into smaller passes?
8-
96
def execute(compiler_data, opts) do
10-
data = Enum.reduce(compiler_data.data, [], fn({dep, paths}, list) ->
11-
12-
file_paths = Enum.flat_map(paths, fn(path) ->
13-
Path.join(path, "**/*.{ex,exs,exjs}")
14-
|> Path.wildcard
15-
end)
16-
17-
file_paths = Enum.reduce(file_paths, [], fn(path, list) ->
18-
quoted = path
19-
|> File.read!
20-
|> Code.string_to_quoted!
21-
|> update_quoted
22-
23-
{ _, modules } = Macro.postwalk(quoted, [], &get_defmodules(&1, &2, opts))
24-
25-
stat = File.stat!(path)
26-
27-
modules = Enum.map(modules, fn(x) -> { x.module, Map.merge(x, %{ path: path, app: dep, stat: stat }) } end)
28-
list ++ modules
29-
end)
30-
7+
data = Enum.reduce(compiler_data.data, [], fn(data, list) ->
8+
quoted = update_quoted(data.ast)
9+
{ _, modules } = Macro.postwalk(quoted, [], &get_defmodules(&1, &2, opts))
3110

32-
list ++ file_paths
11+
modules = Enum.map(modules, fn(x) -> { x.module, Map.merge(data, x) } end)
12+
list ++ modules
3313
end)
3414

3515
Map.put(compiler_data, :data, data)

0 commit comments

Comments
 (0)