Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/elixir_script/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ defmodule ElixirScript.Compiler do
If a directory is given, file will be named `elixirscript.build.js`

* `root`: Optional root for imports of FFI JavaScript modules. Defaults to `.`.
* `remove_unused_functions`: Removed unused functions in output. Defaults to
removing unused functions when Mix.env == :prod
"""
alias ElixirScript.{
State,
Expand Down Expand Up @@ -72,7 +74,9 @@ defmodule ElixirScript.Compiler do
defp do_compile(entry_modules, pid, opts) do
FindUsedModules.execute(entry_modules, pid)

FindUsedFunctions.execute(entry_modules, pid)
if opts.remove_unused_functions do
FindUsedFunctions.execute(entry_modules, pid)
end

modules = State.list_modules(pid)
Translate.execute(modules, pid)
Expand All @@ -90,6 +94,7 @@ defmodule ElixirScript.Compiler do
|> Map.put(:output, Keyword.get(opts, :output))
|> Map.put(:format, :es)
|> Map.put(:root, Keyword.get(opts, :root, "."))
|> Map.put(:remove_unused_functions, Keyword.get(opts, :remove_unused_functions, Mix.env == :prod))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long (max is 80, was 103).


options = default_options
Map.put(options, :module_formatter, ES)
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_script/passes/translate/forms/receive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule ElixirScript.Translate.Forms.Receive do
"""
def compile(blocks, state) do
receive_block = blocks
|> Keyword.get(:do)
|> Keyword.get(:do, [])
|> Enum.map(fn x ->
Clause.compile(x, state)
|> elem(0)
Expand Down
9 changes: 7 additions & 2 deletions lib/elixir_script/passes/translate/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ defmodule ElixirScript.Translate.Module do
ElixirScript.Translate.Protocol.compile(module, info, pid)
end

def compile(_module, %{attributes: [__foreign_info__: %{path: _, name: _, global: _}]}, _) do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions should have a @SPEC type specification.

nil
end

def compile(module, info, pid) do
%{
attributes: attrs,
Expand All @@ -23,9 +27,10 @@ defmodule ElixirScript.Translate.Module do
line: _line,
module: ^module,
unreachable: unreachable,
used: used
} = info

used = Map.get(info, :used)

state = %{
module: module,
pid: pid
Expand All @@ -39,7 +44,7 @@ defmodule ElixirScript.Translate.Module do
_ -> true
end)

used_defs = if Keyword.has_key?(attrs, :protocol_impl) do
used_defs = if Keyword.has_key?(attrs, :protocol_impl) or used == nil do
reachable_defs
else
Enum.filter(reachable_defs, fn
Expand Down
4 changes: 3 additions & 1 deletion lib/elixir_script/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ defmodule ElixirScript.State do
def has_used?(pid, module, func) do
Agent.get(pid, fn(state) ->
module_info = Keyword.get(state.modules, module)
Enum.find(module_info.used, fn(x) -> x == func end) != nil
used = Map.get(module_info, :used, [])

Enum.find(used, fn(x) -> x == func end) != nil
end)
end

Expand Down