Skip to content

Commit cc32253

Browse files
committed
Fix some lints. Fixed implementations of some map functions
1 parent 634cc05 commit cc32253

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

lib/elixir_script/passes/translate/forms/pattern.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ defmodule ElixirScript.Translate.Forms.Pattern do
44
alias ElixirScript.Translate.Form
55
alias ElixirScript.Translate.Forms.Bitstring
66

7-
@moduledoc """
7+
@moduledoc false
8+
9+
@doc """
810
Handles all pattern matching translations
911
"""
10-
12+
@spec compile(list(), map()) :: { list(), list(), map() }
1113
def compile(patterns, state) do
1214
patterns
1315
|> do_compile(state)
@@ -40,6 +42,7 @@ defmodule ElixirScript.Translate.Forms.Pattern do
4042
{ patterns, params, state }
4143
end
4244

45+
@spec get_variable_name(atom(), map()) :: atom()
4346
def get_variable_name(function, state) do
4447
number = Map.get(state.vars, function)
4548
String.to_atom("#{function}#{number}")

src/javascript/lib/core/erlang_compat/maps.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function find(key, map) {
2424
function fold(fun, init, map) {
2525
let acc = init;
2626

27-
for (const [key, value] of Object.entries(map)) {
27+
for (const [key, value] of to_list(map)) {
2828
acc = fun(key, value, acc);
2929
}
3030

@@ -48,9 +48,13 @@ function to_list(map) {
4848
return new ErlangTypes.Tuple(BADMAP, map);
4949
}
5050

51-
return Object.entries(map).map(entry => {
52-
return ErlangTypes.Tuple(...entry);
53-
});
51+
const list = [];
52+
53+
for (const key of keys(map)) {
54+
list.push(new ErlangTypes.Tuple(key, map[key]));
55+
}
56+
57+
return list;
5458
}
5559

5660
function from_list(list) {
@@ -67,15 +71,31 @@ function keys(map) {
6771
return new ErlangTypes.Tuple(BADMAP, map);
6872
}
6973

70-
return Object.keys(map);
74+
const keys = [];
75+
76+
for (const key of Object.getOwnPropertySymbols(map)) {
77+
keys.push(key);
78+
}
79+
80+
for (const key of Object.getOwnPropertyNames(map)) {
81+
keys.push(key);
82+
}
83+
84+
return keys;
7185
}
7286

7387
function values(map) {
7488
if (erlang.is_map(map) === false) {
7589
return new ErlangTypes.Tuple(BADMAP, map);
7690
}
7791

78-
return Object.values(map);
92+
const theValues = [];
93+
94+
for (const key of keys(map)) {
95+
theValues.push(map[key]);
96+
}
97+
98+
return theValues;
7999
}
80100

81101
function is_key(key, map) {
@@ -164,5 +184,5 @@ export default {
164184
merge,
165185
update,
166186
get,
167-
take,
187+
take
168188
};

test/support/main.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ defmodule Main do
22
def start(:normal, [callback]) do
33
callback.("started")
44

5-
JS.console.log String.valid?("a")
6-
JS.console.log String.valid?(1)
5+
Enum.each(1..3, fn x -> JS.console.log(x) end)
76
end
87
end

0 commit comments

Comments
 (0)