Skip to content

Commit e6df73d

Browse files
committed
Fix field access
1 parent 95c7513 commit e6df73d

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

lib/elixir_script/passes/translate/form.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ defmodule ElixirScript.Translate.Form do
323323
{ast, state}
324324
end
325325

326-
def compile({{:., _, [{_, _, atom} = var, func_or_prop]}, _, []}, state) when is_atom(atom) do
326+
def compile({{:., _, [var, func_or_prop]}, _, []}, state) when not is_atom(var) do
327327
ast = Helpers.call(
328328
ElixirScript.Translate.Forms.JS.call_property(),
329329
[compile!(var, state), J.literal(to_string(func_or_prop))]

test/integration/integration_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ defmodule ElixirScript.Integration.Test do
1919
[:option, %{value: "[email protected]"}, "[email protected]"]
2020
]
2121
end
22+
23+
test "multi-remote call" do
24+
val = call_compiled_function Integration, :multi_field_call, []
25+
assert val == "5,000,000"
26+
end
2227
end

test/passes/translate/form_test.exs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule ElixirScript.Translate.Forms.Test do
22
use ExUnit.Case
33
alias ElixirScript.Translate.Form
44
alias ElixirScript.Translate.Identifier
5+
alias ElixirScript.Translate.Helpers
56
alias ESTree.Tools.Builder, as: J
67
require StreamData
78
import PropertyTest
@@ -146,4 +147,25 @@ defmodule ElixirScript.Translate.Forms.Test do
146147
J.literal(3)
147148
])
148149
end
150+
151+
test "calling field on field" do
152+
ast = {{:., [line: 16],
153+
[{{:., [line: 16], [{:map, [line: 16], nil}, :token_count]}, [line: 16],
154+
[]}, :toLocaleString]}, [line: 16], []}
155+
156+
state = %{function: {:something, nil}, vars: %{}}
157+
158+
{js_ast, _} = Form.compile(ast, state)
159+
160+
assert js_ast == Helpers.call(
161+
ElixirScript.Translate.Forms.JS.call_property(),
162+
[
163+
Helpers.call(
164+
ElixirScript.Translate.Forms.JS.call_property(),
165+
[J.identifier("map"), J.literal("token_count")]
166+
),
167+
J.literal("toLocaleString")
168+
]
169+
)
170+
end
149171
end

test/support/integration.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ defmodule Integration do
1010
options = Enum.reduce(orders, [],
1111
&(&2 ++ [ [:option, %{value: &1.email}, &1.email] ]))
1212
end
13+
14+
def multi_field_call do
15+
map = %{token_count: 5000000}
16+
map.token_count.toLocaleString()
17+
end
1318
end

0 commit comments

Comments
 (0)