Skip to content

Commit 6ff7c75

Browse files
committed
Add more tests
1 parent 01a51b3 commit 6ff7c75

32 files changed

+155
-154
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ stdlib_state.bin
2222
.nyc_output
2323
test/app/build
2424
.vscode
25+
cover

lib/elixir_script.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
defmodule ElixirScript do
2+
@moduledoc false
23
end

lib/elixir_script/cli.ex

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ defmodule ElixirScript.CLI do
1919
f: :format
2020
]
2121

22-
def main(argv) do
23-
argv
24-
|> parse_args
25-
|> process
26-
end
27-
2822
def parse_args(args) do
2923
{ options, input, errors } = OptionParser.parse(args, switches: @switches, aliases: @aliases)
3024

@@ -43,7 +37,7 @@ defmodule ElixirScript.CLI do
4337

4438
end
4539

46-
def help_message() do
40+
defp help_message() do
4741
"""
4842
usage: elixirscript <module> [options]
4943
<module> the entry module of your application

lib/elixir_script/compiler.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ defmodule ElixirScript.Compiler do
2828

2929
IO.puts "Building Output"
3030
modules = ElixirScript.State.list_modules(pid)
31-
ElixirScript.Output.execute(modules, pid)
31+
result = ElixirScript.Output.execute(modules, pid)
3232

3333
ElixirScript.State.stop(pid)
34+
35+
result
3436
end
3537

3638
defp build_compiler_options(opts, entry_modules) do

lib/elixir_script/module_systems/common.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ defmodule ElixirScript.ModuleSystems.Common do
22
@moduledoc false
33
alias ESTree.Tools.Builder, as: JS
44
alias ElixirScript.Translator
5-
alias ElixirScript.Translator.State
6-
alias ElixirScript.Translator.Utils
5+
alias ElixirScript.Translator.{State, Utils}
76

87
def build(imports, js_imports, body, exports) do
98
module_imports = Enum.map(imports, fn {module, path} -> import_module(module, path) end)
109

1110
imports = js_imports
1211
|> Enum.map(fn
1312
{module, path} -> import_module(module, path)
14-
{module, path, _} -> import_module(module, path)
1513
end)
1614

1715
imports = Enum.uniq(imports ++ module_imports)

lib/elixir_script/module_systems/es.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
defmodule ElixirScript.ModuleSystems.ES do
22
@moduledoc false
33
alias ESTree.Tools.Builder, as: JS
4-
alias ElixirScript.Translator
5-
alias ElixirScript.Translator.State
6-
alias ElixirScript.Translator.Utils
74

85
def build(imports, js_imports, body, exports) do
96
module_imports = Enum.map(imports, fn {module, path} -> import_module(module, path) end)
107

118
imports = js_imports
129
|> Enum.map(fn
1310
{module, path} -> import_module(module, path)
14-
{module, path, default: true} -> import_module(module, path)
1511
{module, path, default: false} -> import_namespace_module(module, path)
1612
end)
1713

lib/elixir_script/module_systems/namespace.ex

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
defmodule ElixirScript.ModuleSystems.Namespace do
22
@moduledoc false
33
alias ESTree.Tools.Builder, as: JS
4-
alias ElixirScript.Translator
5-
alias ElixirScript.Translator.State
6-
alias ElixirScript.Translator.Utils
74
alias ElixirScript.Translate.Identifier
85

96
def build(module_name, body, exports, env) do
@@ -15,20 +12,6 @@ defmodule ElixirScript.ModuleSystems.Namespace do
1512
Identifier.make_namespace_members(members)
1613
end
1714

18-
def import_module(module_name) do
19-
name = ["Elixir" | Module.split(module_name) ] |> Enum.join("$")
20-
21-
declarator = JS.variable_declarator(
22-
JS.identifier(name),
23-
JS.call_expression(
24-
module_name_function_call(module_name, "__load"),
25-
[JS.identifier("Elixir")]
26-
)
27-
)
28-
29-
JS.variable_declaration([declarator], :const)
30-
end
31-
3215
defp build_namespace() do
3316
JS.member_expression(
3417
JS.identifier("Bootstrap"),

lib/elixir_script/module_systems/umd.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
defmodule ElixirScript.ModuleSystems.UMD do
22
@moduledoc false
33
alias ESTree.Tools.Builder, as: JS
4-
alias ElixirScript.Translator
5-
alias ElixirScript.Translator.State
6-
alias ElixirScript.Translator.Utils
74

85
def build(imports, js_imports, body, exports) do
96
module_imports = Enum.map(imports, fn {module, path} -> import_module(module, path) end)
107

118
imports = js_imports
129
|> Enum.map(fn
1310
{module, path} -> import_module(module, path)
14-
{module, path, _} -> import_module(module, path)
1511
end)
1612

1713
imports = Enum.uniq(imports ++ module_imports)

lib/elixir_script/passes/find_used_modules.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule ElixirScript.FindUsedModules do
2121
{:ok, module, implementations} ->
2222
walk_protocol(module, implementations, pid)
2323
{:error, error} ->
24-
raise "An error occurred while compiling #{inspect module}: #{error}"
24+
raise ElixirScript.CompileError, "An error occurred while compiling #{inspect module}: #{error}"
2525
end
2626
end
2727

lib/elixir_script/passes/output.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,21 @@ defmodule ElixirScript.Output do
6363
end
6464

6565
defp output(code, path) do
66-
file_name = case Path.extname(path) do
67-
".js" ->
68-
path
69-
_ ->
70-
Path.join([path, @generated_name])
71-
end
66+
file_name = get_output_file_name(path)
7267

7368
if !File.exists?(Path.dirname(file_name)) do
7469
File.mkdir_p!(Path.dirname(file_name))
7570
end
7671

7772
File.write!(file_name, code)
7873
end
74+
75+
def get_output_file_name(path) do
76+
case Path.extname(path) do
77+
".js" ->
78+
path
79+
_ ->
80+
Path.join([path, @generated_name])
81+
end
82+
end
7983
end

0 commit comments

Comments
 (0)