Skip to content

Commit 1363b1a

Browse files
committed
Readying for release
1 parent fad714f commit 1363b1a

File tree

8 files changed

+77
-9
lines changed

8 files changed

+77
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
8+
## [0.23.3] - 2016-11-18
9+
10+
### Added
11+
- `@load_only`: lets the compiler know to load in the module, but not to compile it
12+
13+
714
## [0.23.2] - 2016-11-17
815

916
### Fixed

lib/elixir_script.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ defmodule ElixirScript do
7070
result = %{ data: data }
7171
|> ElixirScript.Passes.Init.execute(opts)
7272
|> ElixirScript.Passes.FindModules.execute(opts)
73+
|> ElixirScript.Passes.FindLoadOnly.execute(opts)
7374
|> ElixirScript.Passes.FindFunctions.execute(opts)
7475
|> ElixirScript.Passes.AddStdLib.execute(opts)
7576
|> ElixirScript.Passes.JavaScriptAST.execute(opts)
@@ -124,6 +125,7 @@ defmodule ElixirScript do
124125
|> ElixirScript.Passes.ASTFromFile.execute(opts)
125126
|> ElixirScript.Passes.LoadModules.execute(opts)
126127
|> ElixirScript.Passes.FindModules.execute(opts)
128+
|> ElixirScript.Passes.FindLoadOnly.execute(opts)
127129
|> ElixirScript.Passes.FindChangedFiles.execute(opts)
128130
|> ElixirScript.Passes.FindFunctions.execute(opts)
129131
|> ElixirScript.Passes.AddStdLib.execute(opts)
@@ -165,6 +167,7 @@ defmodule ElixirScript do
165167
|> ElixirScript.Passes.DepsPaths.execute(opts)
166168
|> ElixirScript.Passes.ASTFromFile.execute(opts)
167169
|> ElixirScript.Passes.FindModules.execute(opts)
170+
|> ElixirScript.Passes.FindLoadOnly.execute(opts)
168171
|> ElixirScript.Passes.FindFunctions.execute(opts)
169172
|> ElixirScript.Passes.JavaScriptAST.execute(opts)
170173
|> ElixirScript.Passes.ConsolidateProtocols.execute(opts)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
defmodule ElixirScript.Passes.FindLoadOnly do
2+
@moduledoc false
3+
4+
def execute(compiler_data, opts) do
5+
data = compiler_data.data
6+
|> Enum.map(fn({module_name, module_data}) ->
7+
8+
{_, load_only} = Macro.prewalk(module_data.ast, false, fn
9+
({:@, _, [{:load_only, _, [true]}]} = ast, state) ->
10+
{ast, true}
11+
12+
({:@, _, [{:load_only, _, [false]}]} = ast, state) ->
13+
{ast, false}
14+
15+
({:@, _, [{:load_only, _, []}]} = ast, state) ->
16+
{ast, true}
17+
18+
(ast, state) ->
19+
{ast, state}
20+
end)
21+
22+
{ module_name, Map.put(module_data, :load_only, load_only) }
23+
24+
end)
25+
26+
27+
28+
%{ compiler_data | data: data }
29+
end
30+
31+
32+
33+
end

lib/elixir_script/passes/handle_output.ex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ElixirScript.Passes.HandleOutput do
2-
@moduledoc false
2+
@moduledoc false
33
alias ElixirScript.Translator.State
44

55
def execute(compiler_data, opts) do
@@ -24,12 +24,14 @@ defmodule ElixirScript.Passes.HandleOutput do
2424

2525
defp out(compiler_output, %{output: nil} = compiler_opts) do
2626
compiler_output
27-
|> process_include_path(compiler_opts)
27+
|> remove_load_only
28+
|> process_include_path(compiler_opts)
2829
end
2930

3031
defp out(compiler_output, %{output: :stdout} = compiler_opts) do
3132
compiler_output
32-
|> process_include_path(compiler_opts)
33+
|> remove_load_only
34+
|> process_include_path(compiler_opts)
3335
|> Enum.each(fn
3436
{_, code, _} -> IO.write(code)
3537
code -> IO.write(code)
@@ -41,6 +43,8 @@ defmodule ElixirScript.Passes.HandleOutput do
4143
ElixirScript.copy_stdlib_to_destination(output_path)
4244
end
4345

46+
compiler_output = remove_load_only(compiler_output)
47+
4448
compiler_output.data
4549
|> Enum.each(fn({_, x}) ->
4650
write_to_file(x, output_path)
@@ -69,4 +73,9 @@ defmodule ElixirScript.Passes.HandleOutput do
6973
end
7074
end)
7175
end
76+
77+
defp remove_load_only(compiler_output) do
78+
data = Enum.filter(compiler_output.data, fn({m, d}) -> Map.get(d, :load_only, false) == false end)
79+
%{ compiler_output | data: data }
80+
end
7281
end

lib/elixir_script/passes/java_script_ast.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ElixirScript.Passes.JavaScriptAST do
2-
@moduledoc false
2+
@moduledoc false
33
alias ElixirScript.Translator.Utils
44
alias ElixirScript.Translator.State
55

@@ -30,6 +30,10 @@ defmodule ElixirScript.Passes.JavaScriptAST do
3030
%{ compiler_data | data: data }
3131
end
3232

33+
defp compile(%{load_only: true} = module_data, opts) do
34+
module_data
35+
end
36+
3337
defp compile(module_data, opts) do
3438

3539
env = ElixirScript.Translator.LexicalScope.module_scope(module_data.name, Utils.name_to_js_file_name(module_data.name) <> ".js", opts.env)

lib/elixir_script/passes/java_script_code.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ElixirScript.Passes.JavaScriptCode do
2-
@moduledoc false
2+
@moduledoc false
33
alias ESTree.Tools.{ Builder, Generator }
44

55
def execute(compiler_data, _) do
@@ -24,6 +24,10 @@ defmodule ElixirScript.Passes.JavaScriptCode do
2424
%{ compiler_data | data: data }
2525
end
2626

27+
defp compile(%{load_only: true} = module_data) do
28+
module_data
29+
end
30+
2731

2832
defp compile(module_data) do
2933
js_ast = Builder.program(module_data.javascript_ast)

lib/elixir_script/translator/lexical_scope.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,22 @@ defmodule ElixirScript.Translator.LexicalScope do
187187
raise "Module #{inspect module_name} not found"
188188
end
189189

190-
ElixirScript.Translator.State.add_module_reference(env.module, module.name)
190+
if Map.get(module, :load_only, false) == false do
191+
ElixirScript.Translator.State.add_module_reference(env.module, module.name)
192+
end
193+
191194
module
192195
end
193196

194197
defp has_module?(env, module_name) do
195198
try do
196-
get_module(env, module_name)
197-
true
199+
module = get_module(env, module_name)
200+
case module do
201+
%{load_only: true} ->
202+
false
203+
_ ->
204+
true
205+
end
198206
rescue
199207
_ ->
200208
false

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule ElixirScript.Mixfile do
44
def project do
55
[
66
app: :elixir_script,
7-
version: "0.23.2",
7+
version: "0.23.3",
88
elixir: "~> 1.0",
99
escript: escript_config,
1010
deps: deps,

0 commit comments

Comments
 (0)