Skip to content

Commit 283c650

Browse files
committed
Move concatenation to functions in order to eventually handle overflow cases
1 parent f56e799 commit 283c650

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

lib/elixir_script/passes/translate/clause.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule ElixirScript.Translate.Clause do
1717

1818
body = body
1919
|> return_last_statement
20+
|> Function.update_last_call(state)
2021

2122
ast = Helpers.call(
2223
J.member_expression(

lib/elixir_script/passes/translate/form.ex

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,17 @@ defmodule ElixirScript.Translate.Form do
5656
{ J.literal(form), state }
5757
end
5858

59-
def compile([{:|, _, [head, tail]}], state) do
60-
ast = Helpers.call(
61-
J.member_expression(
62-
J.array_expression([compile!(head, state)]),
63-
J.identifier("concat")
64-
),
65-
[compile!(tail, state)]
66-
)
67-
68-
{ ast, state }
59+
def compile([{:|, _, [_head, _tail]} = ast], state) do
60+
compile(ast, state)
6961
end
7062

7163
def compile({:|, _, [head, tail]}, state) do
7264
ast = Helpers.call(
7365
J.member_expression(
74-
J.array_expression([compile!(head, state)]),
66+
Helpers.functions(),
7567
J.identifier("concat")
7668
),
77-
[compile!(tail, state)]
69+
[compile!(head, state), compile!(tail, state)]
7870
)
7971

8072
{ ast, state }

lib/elixir_script/passes/translate/function.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ defmodule ElixirScript.Translate.Function do
168168
{ast, state}
169169
end
170170

171-
defp update_last_call(clause_body, %{function: {name, _}, anonymous_fn: anonymous?}) do
171+
def update_last_call(clause_body, %{function: {name, _}, anonymous_fn: anonymous?}) do
172172
last_item = List.last(clause_body)
173173
function_name = ElixirScript.Translate.Identifier.make_function_name(name)
174174

src/javascript/lib/core/functions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ function graphemes(str) {
198198
return splitter.splitGraphemes(str);
199199
}
200200

201+
function concat(head, tail) {
202+
return [head].concat(tail);
203+
}
204+
201205
export default {
202206
call_property,
203207
defprotocol,
@@ -209,4 +213,5 @@ export default {
209213
Recurse,
210214
split_at,
211215
graphemes,
216+
concat,
212217
};

0 commit comments

Comments
 (0)