Skip to content

Commit cb976fa

Browse files
committed
Update travis
1 parent adc39f8 commit cb976fa

File tree

5 files changed

+111
-77
lines changed

5 files changed

+111
-77
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
erlang 20.1
2-
elixir 1.6.0-rc.0-otp-20
2+
elixir 1.6.0-otp-20
33
nodejs 8.9.1

.travis.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
sudo: false
2-
language: erlang
2+
language: elixir
3+
elixir:
4+
- 1.6.0-otp-20
35
otp_release:
4-
- 20.0
6+
- 20.2
57
env:
68
- TRAVIS_NODE_VERSION="8"
79
install:
810
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
911
- npm install -g yarn
1012
- yarn
11-
before_script:
12-
- wget https://repo.hex.pm/builds/elixir/v1.6.0-rc.0-otp-20.zip
13-
- unzip -d elixir v1.6.0-rc.0-otp-20.zip
14-
- export PATH=$(pwd)/elixir/bin:${PATH}
15-
- mix local.rebar --force
1613
- mix local.hex --force
14+
- mix local.rebar --force
1715
- mix deps.get
1816
script:
1917
- make

lib/elixir_script/passes/translate/form.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@ defmodule ElixirScript.Translate.Form do
5959

6060
def compile(form, state) when is_atom(form) do
6161
ast =
62-
if ElixirScript.Translate.Module.is_elixir_module(form) do
63-
Remote.process_module_name(form, state)
64-
else
65-
Helpers.symbol(form)
62+
cond do
63+
ElixirScript.Translate.Module.is_elixir_module(form) and
64+
ModuleState.get_module(state.pid, form) != nil ->
65+
Remote.process_module_name(form, state)
66+
67+
ElixirScript.Translate.Module.is_elixir_module(form) ->
68+
J.object_expression([])
69+
70+
true ->
71+
Helpers.symbol(form)
6672
end
6773

6874
{ast, state}

mix.exs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ defmodule ElixirScript.Mixfile do
55
[
66
app: :elixir_script,
77
version: "0.32.0-dev",
8-
elixir: "~> 1.6-rc",
9-
elixirc_paths: elixirc_paths(Mix.env),
8+
elixir: "~> 1.6",
9+
elixirc_paths: elixirc_paths(Mix.env()),
1010
deps: deps(),
1111
description: description(),
1212
package: package(),
@@ -37,7 +37,7 @@ defmodule ElixirScript.Mixfile do
3737
end
3838

3939
defp elixirc_paths(:test), do: ["lib", "test/support"]
40-
defp elixirc_paths(_), do: ["lib"]
40+
defp elixirc_paths(_), do: ["lib"]
4141

4242
defp description do
4343
"""
@@ -56,5 +56,4 @@ defmodule ElixirScript.Mixfile do
5656
build_tools: ["mix"]
5757
]
5858
end
59-
6059
end

test/passes/translate/form_test.exs

Lines changed: 92 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ defmodule ElixirScript.Translate.Forms.Test do
55
alias ESTree.Tools.Builder, as: J
66
use ExUnitProperties
77

8-
98
setup_all do
109
{:ok, pid} = ElixirScript.State.start_link(%{})
1110

@@ -17,13 +16,15 @@ defmodule ElixirScript.Translate.Forms.Test do
1716
[state: state]
1817
end
1918

20-
property "integers, floats, binaries, and booleans translates to a literal JavaScript AST node", %{state: state} do
21-
check all value <- StreamData.one_of([
22-
StreamData.integer(),
23-
StreamData.boolean(),
24-
StreamData.binary(),
25-
StreamData.uniform_float()
26-
]) do
19+
property "integers, floats, binaries, and booleans translates to a literal JavaScript AST node",
20+
%{state: state} do
21+
check all value <-
22+
StreamData.one_of([
23+
StreamData.integer(),
24+
StreamData.boolean(),
25+
StreamData.binary(),
26+
StreamData.uniform_float()
27+
]) do
2728
{js_ast, _} = Form.compile(value, state)
2829
assert js_ast == J.literal(value)
2930
end
@@ -32,29 +33,33 @@ defmodule ElixirScript.Translate.Forms.Test do
3233
property "atom translates to Symbol.for call", %{state: state} do
3334
check all atom <- StreamData.unquoted_atom() do
3435
{js_ast, _} = Form.compile(atom, state)
35-
assert js_ast == J.call_expression(
36-
J.member_expression(
37-
J.identifier("Symbol"),
38-
J.identifier("for")
39-
),
40-
[J.literal(atom)]
41-
)
36+
37+
assert js_ast ==
38+
J.call_expression(
39+
J.member_expression(
40+
J.identifier("Symbol"),
41+
J.identifier("for")
42+
),
43+
[J.literal(atom)]
44+
)
4245
end
4346
end
4447

4548
property "tuple translates to new Tuple object", %{state: state} do
4649
check all tuple <- StreamData.tuple({StreamData.integer(), StreamData.binary()}) do
4750
{js_ast, _} = Form.compile(tuple, state)
48-
assert js_ast == J.new_expression(
49-
J.member_expression(
50-
J.member_expression(
51-
J.identifier("ElixirScript"),
52-
J.identifier("Core")
53-
),
54-
J.identifier("Tuple")
55-
),
56-
[J.literal(elem(tuple, 0)), J.literal(elem(tuple, 1))]
57-
)
51+
52+
assert js_ast ==
53+
J.new_expression(
54+
J.member_expression(
55+
J.member_expression(
56+
J.identifier("ElixirScript"),
57+
J.identifier("Core")
58+
),
59+
J.identifier("Tuple")
60+
),
61+
[J.literal(elem(tuple, 0)), J.literal(elem(tuple, 1))]
62+
)
5863
end
5964
end
6065

@@ -72,16 +77,16 @@ defmodule ElixirScript.Translate.Forms.Test do
7277
end
7378

7479
property "local function call translates to local JavaScript function call", %{state: state} do
75-
check all func <- StreamData.filter(StreamData.unquoted_atom(), fn(x) -> not(x in [:fn]) end),
80+
check all func <- StreamData.filter(StreamData.unquoted_atom(), fn x -> x not in [:fn] end),
7681
params <- StreamData.list_of(StreamData.binary()) do
77-
7882
ast = {func, [], params}
7983

80-
str_func = if func in ElixirScript.Translate.Identifier.js_reserved_words() do
81-
"__#{to_string(func)}__"
82-
else
83-
to_string(func)
84-
end
84+
str_func =
85+
if func in ElixirScript.Translate.Identifier.js_reserved_words() do
86+
"__#{to_string(func)}__"
87+
else
88+
to_string(func)
89+
end
8590

8691
{js_ast, _} = Form.compile(ast, state)
8792
assert js_ast.type == "CallExpression"
@@ -99,15 +104,15 @@ defmodule ElixirScript.Translate.Forms.Test do
99104
property "super function call translates to local JavaScript function call" do
100105
check all func <- StreamData.unquoted_atom(),
101106
params <- StreamData.list_of(StreamData.binary()) do
102-
103107
ast = {:super, [], [{:def, func}] ++ params}
104108
state = %{function: {func, nil}, vars: %{}}
105109

106-
str_func = if func in ElixirScript.Translate.Identifier.js_reserved_words() do
107-
"__#{to_string(func)}__"
108-
else
109-
to_string(func)
110-
end
110+
str_func =
111+
if func in ElixirScript.Translate.Identifier.js_reserved_words() do
112+
"__#{to_string(func)}__"
113+
else
114+
to_string(func)
115+
end
111116

112117
{js_ast, _} = Form.compile(ast, state)
113118
assert js_ast.type == "CallExpression"
@@ -125,10 +130,24 @@ defmodule ElixirScript.Translate.Forms.Test do
125130
test "module", %{state: state} do
126131
ast = IO
127132

133+
ElixirScript.State.put_module(state.pid, IO, %{})
134+
128135
{js_ast, _} = Form.compile(ast, state)
129136
assert js_ast == %ESTree.Identifier{loc: nil, name: "$IO$", type: "Identifier"}
130137
end
131138

139+
test "unknown module", %{state: state} do
140+
ast = Enum
141+
142+
{js_ast, _} = Form.compile(ast, state)
143+
144+
assert js_ast == %ESTree.ObjectExpression{
145+
loc: nil,
146+
properties: [],
147+
type: "ObjectExpression"
148+
}
149+
end
150+
132151
test "function returning an array" do
133152
ast = {:fn, [], [{:foo, [], [], [1, 2, 3]}]}
134153
state = %{function: {:something, nil}}
@@ -137,37 +156,48 @@ defmodule ElixirScript.Translate.Forms.Test do
137156

138157
return_statement = Enum.at(Enum.at(hd(js_ast.body.body).body.body, 1).consequent.body, 1)
139158

140-
assert return_statement.argument == J.array_expression([
141-
J.literal(1),
142-
J.literal(2),
143-
J.literal(3)
144-
])
159+
assert return_statement.argument ==
160+
J.array_expression([
161+
J.literal(1),
162+
J.literal(2),
163+
J.literal(3)
164+
])
145165
end
146166

147167
test "calling field on field" do
148-
ast = {{:., [line: 16],
149-
[{{:., [line: 16], [{:map, [line: 16], nil}, :token_count]}, [line: 16],
150-
[]}, :toLocaleString]}, [line: 16], []}
168+
ast =
169+
{
170+
{:., [line: 16], [
171+
{{:., [line: 16], [{:map, [line: 16], nil}, :token_count]}, [line: 16], []},
172+
:toLocaleString
173+
]},
174+
[line: 16],
175+
[]
176+
}
151177

152178
state = %{function: {:something, nil}, vars: %{}}
153179

154180
{js_ast, _} = Form.compile(ast, state)
155181

156-
assert js_ast == Helpers.call(
157-
ElixirScript.Translate.Forms.JS.call_property(),
158-
[
159-
Helpers.call(
160-
ElixirScript.Translate.Forms.JS.call_property(),
161-
[J.identifier("map"), J.literal("token_count")]
162-
),
163-
J.literal("toLocaleString")
164-
]
165-
)
182+
assert js_ast ==
183+
Helpers.call(ElixirScript.Translate.Forms.JS.call_property(), [
184+
Helpers.call(ElixirScript.Translate.Forms.JS.call_property(), [
185+
J.identifier("map"),
186+
J.literal("token_count")
187+
]),
188+
J.literal("toLocaleString")
189+
])
166190
end
167191

168192
test "make sure counter used in guard", %{state: state} do
169-
state = Map.merge(state, %{anonymous_fn: false, function: {:filter_names_in_guards, nil}, in_guard: true,
170-
module: Integration, vars: %{"has__qmark__" => 0}})
193+
state =
194+
Map.merge(state, %{
195+
anonymous_fn: false,
196+
function: {:filter_names_in_guards, nil},
197+
in_guard: true,
198+
module: Integration,
199+
vars: %{"has__qmark__" => 0}
200+
})
171201

172202
ast = {{:., [], [:erlang, :==]}, [line: 29], [{:has?, [line: 29], nil}, 5]}
173203

@@ -177,9 +207,10 @@ defmodule ElixirScript.Translate.Forms.Test do
177207

178208
test "multi bind", %{state: state} do
179209
ast =
180-
{:=, [line: 35],
181-
[[{:|, [line: 35], [{:a, [line: 35], nil}, {:_, [line: 35], nil}]}],
182-
{:=, [line: 35], [{:b, [line: 35], nil}, [1, 2, 3, 4, 5]]}]}
210+
{:=, [line: 35], [
211+
[{:|, [line: 35], [{:a, [line: 35], nil}, {:_, [line: 35], nil}]}],
212+
{:=, [line: 35], [{:b, [line: 35], nil}, [1, 2, 3, 4, 5]]}
213+
]}
183214

184215
{js_ast, _} = Form.compile(ast, state)
185216

0 commit comments

Comments
 (0)