@@ -63,26 +63,54 @@ defmodule ElixirScript do
6363
6464 opts = build_compiler_options ( opts )
6565
66- result = % { data: [ % { ast: quoted } ] }
66+ data = quoted
67+ |> get_modules_from_quoted
68+ |> Enum . map ( fn ( x ) -> % { ast: x , app: :app } end )
69+
70+ result = % { data: data }
71+ |> ElixirScript.Passes.Init . execute ( opts )
6772 |> ElixirScript.Passes.FindModules . execute ( opts )
6873 |> ElixirScript.Passes.FindDeps . execute ( opts )
69- |> ElixirScript.Passes.RemoveUnused . execute ( opts )
70- |> ElixirScript.Passes.LoadModules . execute ( opts )
71- |> ElixirScript.Passes.FindChangedFiles . execute ( opts )
7274 |> ElixirScript.Passes.FindFunctions . execute ( opts )
75+ |> ElixirScript.Passes.AddStdLib . execute ( opts )
7376 |> ElixirScript.Passes.JavaScriptAST . execute ( opts )
7477 |> ElixirScript.Passes.ConsolidateProtocols . execute ( opts )
7578 |> ElixirScript.Passes.JavaScriptCode . execute ( opts )
7679 |> ElixirScript.Passes.JavaScriptName . execute ( opts )
7780 |> ElixirScript.Passes.HandleOutput . execute ( opts )
7881
79-
80- { code , _ } = do_compile ( opts , [ quoted ] , get_stdlib_state , [ ] )
81- result = Output . out ( quoted , code , build_compiler_options ( opts ) )
82- ElixirScript.Translator.State . stop
8382 result
8483 end
8584
85+ defp get_modules_from_quoted ( quoted ) do
86+ results = case quoted do
87+ { :__block__ , _ , list } ->
88+ { modules , not_modules } = Enum . partition ( list ,
89+ fn
90+ { type , _ , _ } when type in [ :defprotocol , :defimpl , :defmodule ] ->
91+ true
92+ _ ->
93+ false
94+ end )
95+
96+ temp_module = case not_modules do
97+ [ ] ->
98+ [ ]
99+ _ ->
100+ [ { :defmodule , [ ] , [ { :__aliases__ , [ ] , [ :ElixirScript , :Temp ] } , [ do: { :__block__ , [ ] , not_modules } ] ] } ]
101+ end
102+
103+ modules ++ temp_module
104+
105+ { type , _ , _ } = x when type in [ :defprotocol , :defimpl , :defmodule ] ->
106+ x
107+ x ->
108+ { :defmodule , [ ] , [ { :__aliases__ , [ ] , [ :ElixirScript , :Temp ] } , [ do: { :__block__ , [ ] , [ x ] } ] ] }
109+ end
110+
111+ List . wrap ( results )
112+ end
113+
86114 @ doc """
87115 Compiles the elixir files found at the given path
88116 """
@@ -92,6 +120,7 @@ defmodule ElixirScript do
92120 opts = build_compiler_options ( opts )
93121
94122 result = % { path: path }
123+ |> ElixirScript.Passes.Init . execute ( opts )
95124 |> ElixirScript.Passes.DepsPaths . execute ( opts )
96125 |> ElixirScript.Passes.ASTFromFile . execute ( opts )
97126 |> ElixirScript.Passes.FindModules . execute ( opts )
@@ -106,6 +135,8 @@ defmodule ElixirScript do
106135 |> ElixirScript.Passes.JavaScriptName . execute ( opts )
107136 |> ElixirScript.Passes.WriteCache . execute ( opts )
108137 |> ElixirScript.Passes.HandleOutput . execute ( opts )
138+
139+ result
109140 end
110141
111142 defp process_path ( path ) do
@@ -189,13 +220,10 @@ defmodule ElixirScript do
189220 libs_path = Path . join ( [ __DIR__ , "elixir_script" , "prelude" ] )
190221
191222 result = % { path: libs_path }
223+ |> ElixirScript.Passes.Init . execute ( opts )
192224 |> ElixirScript.Passes.DepsPaths . execute ( opts )
193225 |> ElixirScript.Passes.ASTFromFile . execute ( opts )
194226 |> ElixirScript.Passes.FindModules . execute ( opts )
195- #|> ElixirScript.Passes.FindDeps.execute(opts)
196- #|> ElixirScript.Passes.RemoveUnused.execute(opts)
197- #|> ElixirScript.Passes.LoadModules.execute(opts)
198- #|> ElixirScript.Passes.FindChangedFiles.execute(opts)
199227 |> ElixirScript.Passes.FindFunctions . execute ( opts )
200228 |> ElixirScript.Passes.JavaScriptAST . execute ( opts )
201229 |> ElixirScript.Passes.ConsolidateProtocols . execute ( opts )
0 commit comments