Skip to content

Commit 049d1b4

Browse files
committed
Remove mutate/2
Fix broken tests
1 parent 2afdfb8 commit 049d1b4

File tree

4 files changed

+52
-79
lines changed

4 files changed

+52
-79
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
### Added
1010
- ElixirScript now has an FFI layer for interoperability with JavaScript. For more details, see documentation at `ElixirScript.FFI`
11-
- ElixirScript.JS.mutate/2
1211
- ElixirScript.JS.mutate/3
1312

1413
### Changed

lib/elixir_script/lib/js.ex

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,10 @@ defmodule ElixirScript.JS do
3838
"""
3939
defmacro this()
4040

41-
@doc """
42-
Mutates an existing JavaScript object.
43-
ex:
44-
ElixirScript.JS.mutate elem, %{"width" => 100}
45-
"""
46-
defmacro update(object, map)
47-
4841
@doc """
4942
Mutates an existing JavaScript object.
5043
ex:
5144
ElixirScript.JS.mutate elem, "width", 100
5245
"""
53-
defmacro update(object, key, value)
46+
defmacro mutate(object, key, value)
5447
end

test/passes/translate/forms/js_test.exs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,48 +65,18 @@ defmodule ElixirScript.Translate.Forms.JS.Test do
6565
)
6666
end
6767

68-
test "mutate/2" do
69-
properties = [{"a", 1}]
70-
map_ast = {:%{}, [], properties}
71-
72-
ast = {{:., [], [ElixirScript.JS, :mutate]}, [], [{:%{}, [], []}, map_ast]}
73-
state = %{function: {:each, nil}, module: Enum, vars: %{:_ => 0, "entry" => 0, "enumerable" => 0, "fun" => 0}}
74-
75-
{js_ast, _} = Form.compile(ast, state)
76-
assert js_ast == J.call_expression(
77-
J.member_expression(
78-
J.identifier("Object"),
79-
J.identifier("assign")
80-
),
81-
[
82-
J.object_expression([]),
83-
J.object_expression([
84-
J.property(
85-
J.identifier("a"),
86-
J.literal(1)
87-
)
88-
])
89-
]
90-
)
91-
end
92-
9368
test "mutate/3" do
9469
properties = [{"a", 1}]
9570
map_ast = {:%{}, [], properties}
9671

97-
ast = {{:., [], [ElixirScript.JS, :mutate]}, [], [map_ast, "a", 2]}
72+
ast = {{:., [], [ElixirScript.JS, :mutate]}, [], [{:entry, [], nil}, "a", 2]}
9873
state = %{function: {:each, nil}, module: Enum, vars: %{:_ => 0, "entry" => 0, "enumerable" => 0, "fun" => 0}}
9974

10075
{js_ast, _} = Form.compile(ast, state)
10176
assert js_ast == J.assignment_expression(
10277
:=,
10378
J.member_expression(
104-
J.object_expression([
105-
J.property(
106-
J.identifier("a"),
107-
J.literal(1)
108-
)
109-
]),
79+
J.identifier("entry0"),
11080
J.literal("a"),
11181
true
11282
),

test/passes/translate/forms/map_test.exs

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@ defmodule ElixirScript.Translate.Forms.Map.Test do
99
state = %{}
1010

1111
{js_ast, _} = Form.compile(ast, state)
12-
assert js_ast == J.object_expression([
13-
J.property(
14-
J.call_expression(
15-
J.member_expression(
16-
J.identifier("Symbol"),
17-
J.identifier("for")
18-
),
19-
[J.literal(:a)]
20-
),
21-
J.literal(1),
22-
:init, false, false, true
23-
)
24-
])
12+
assert js_ast == J.new_expression(
13+
J.identifier("Map"),
14+
[
15+
J.array_expression([
16+
J.array_expression([
17+
J.call_expression(
18+
J.member_expression(
19+
J.identifier("Symbol"),
20+
J.identifier("for")
21+
),
22+
[J.literal(:a)]
23+
),
24+
J.literal(1),
25+
])
26+
])
27+
]
28+
)
2529
end
2630

2731
test "map with string key" do
@@ -30,12 +34,17 @@ defmodule ElixirScript.Translate.Forms.Map.Test do
3034
state = %{}
3135

3236
{js_ast, _} = Form.compile(ast, state)
33-
assert js_ast == J.object_expression([
34-
J.property(
35-
J.identifier("a"),
36-
J.literal(1)
37-
)
38-
])
37+
assert js_ast == J.new_expression(
38+
J.identifier("Map"),
39+
[
40+
J.array_expression([
41+
J.array_expression([
42+
J.literal("a"),
43+
J.literal(1),
44+
])
45+
])
46+
]
47+
)
3948
end
4049

4150

@@ -47,28 +56,30 @@ defmodule ElixirScript.Translate.Forms.Map.Test do
4756

4857
ast = {:%{}, [], [{:|, [], [map_ast, new_values]}]}
4958

59+
map_ast = J.new_expression(
60+
J.identifier("Map"),
61+
[
62+
J.array_expression([
63+
J.array_expression([
64+
J.literal("a"),
65+
J.literal(1),
66+
])
67+
])
68+
]
69+
)
70+
5071
{js_ast, _} = Form.compile(ast, state)
51-
assert js_ast == J.call_expression(
52-
J.member_expression(
53-
J.identifier("Object"),
54-
J.identifier("assign")
55-
),
72+
assert js_ast == J.new_expression(
73+
J.identifier("Map"),
5674
[
57-
J.object_expression([]),
58-
J.object_expression([
59-
J.property(
60-
J.identifier("a"),
61-
J.literal(1)
62-
)
63-
]),
64-
J.object_expression([
65-
J.property(
66-
J.identifier("a"),
67-
J.literal(2)
68-
)
69-
])
75+
J.array_expression(
76+
[J.spread_element(map_ast)] ++ [J.array_expression([
77+
J.literal("a"),
78+
J.literal(2)
79+
])]
80+
)
7081
]
7182
)
7283
end
7384

74-
end
85+
end

0 commit comments

Comments
 (0)