Skip to content

Commit b04e24d

Browse files
committed
Extract and test start
1 parent 33432ad commit b04e24d

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

lib/elixir_script/passes/create_js_modules.ex

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ defmodule ElixirScript.Passes.CreateJSModules do
6565

6666
elixir = JS.variable_declaration([declarator], :const)
6767

68-
start = JS.assignment_expression(
68+
ast = opts.module_formatter.build(
69+
[],
70+
opts.js_modules,
71+
[elixir, start, load] ++ body,
72+
JS.identifier("Elixir")
73+
)
74+
75+
ast
76+
end
77+
78+
def start do
79+
JS.assignment_expression(
6980
:=,
7081
JS.member_expression(
7182
JS.identifier("Elixir"),
@@ -91,15 +102,6 @@ defmodule ElixirScript.Passes.CreateJSModules do
91102
])
92103
)
93104
)
94-
95-
ast = opts.module_formatter.build(
96-
[],
97-
opts.js_modules,
98-
[elixir, start, load] ++ body,
99-
JS.identifier("Elixir")
100-
)
101-
102-
ast
103105
end
104106

105107
def load do

test/passes/create_js_modules_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ defmodule ElixirScript.Passes.CreateJSModules.Test do
66
alias ElixirScript.Passes.CreateJSModules
77
alias ESTree.Tools.Generator
88

9+
test "start" do
10+
start_js = CreateJSModules.start
11+
|> Generator.generate
12+
13+
expected_js =
14+
"Elixir.start = function(app, args) {
15+
app.__load(Elixir).start(Symbol.for('normal'), args)
16+
}"
17+
18+
19+
assert(start_js == expected_js)
20+
end
21+
922
test "load" do
1023
load_js = CreateJSModules.load
1124
|> Generator.generate

0 commit comments

Comments
 (0)