Skip to content

Commit 1cc80ac

Browse files
committed
Fix merge conflicts
2 parents 6082d01 + 9aa5349 commit 1cc80ac

File tree

6 files changed

+69
-10
lines changed

6 files changed

+69
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"erlang-types": "^1.0.1",
2727
"grapheme-splitter": "^1.0.2",
2828
"rollup-plugin-commonjs": "^8.2.1",
29-
"tailored": "^2.7.2"
29+
"tailored": "^2.7.4"
3030
},
3131
"devDependencies": {
3232
"@std/esm": "^0.8.3",

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ function is_non_primitive(key) {
1818
);
1919
}
2020

21+
function __put(map, key, value) {
22+
const map2 = new Map(map);
23+
24+
if (is_non_primitive(key)) {
25+
for (const map_key of map.keys()) {
26+
if (erlang.equals(map_key, key)) {
27+
map2.set(map_key, value);
28+
return map2;
29+
}
30+
}
31+
}
32+
33+
map2.set(key, value);
34+
return map2;
35+
}
36+
2137
function __has(map, key) {
2238
if (is_non_primitive(key)) {
2339
for (const map_key of map.keys()) {
@@ -142,10 +158,7 @@ function put(key, value, map1) {
142158
return new ErlangTypes.Tuple(BADMAP, map1);
143159
}
144160

145-
const map2 = new Map(map1);
146-
map2.set(key, value);
147-
148-
return map2;
161+
return __put(map1, key, value);
149162
}
150163

151164
function merge(map1, map2) {
@@ -180,7 +193,7 @@ function get(...args) {
180193
return new ErlangTypes.Tuple(BADMAP, map);
181194
}
182195

183-
if (is_key(key)) {
196+
if (is_key(key, map)) {
184197
return __get(map, key);
185198
}
186199

@@ -196,7 +209,7 @@ function take(key, map1) {
196209
return new ErlangTypes.Tuple(BADMAP, map1);
197210
}
198211

199-
if (!is_key(key)) {
212+
if (!is_key(key, map1)) {
200213
return ERROR;
201214
}
202215

src/javascript/tests/core/erlang_compat/maps_spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,42 @@ test('is_key', (t) => {
3838
t.is(result, false);
3939
});
4040

41+
test('get/2', (t) => {
42+
const myMap = new Map([['a', 1], ['b', 2]]);
43+
const result = Core.maps.get('a', myMap);
44+
t.is(result, 1);
45+
});
46+
47+
test('get/3', (t) => {
48+
let myMap = new Map([['a', 1], ['b', 2]]);
49+
let result = Core.maps.get('a', myMap);
50+
t.is(result, 1);
51+
52+
myMap = new Map([['a', 1], ['b', 2]]);
53+
result = Core.maps.get('c', myMap, 'undefined');
54+
t.is(result, 'undefined');
55+
});
56+
57+
test('put/3', (t) => {
58+
const keyMap = new Map([['a', 5]]);
59+
60+
let myMap = new Map([]);
61+
myMap = Core.maps.put(keyMap, 5, myMap);
62+
myMap = Core.maps.put(new Map([['a', 5]]), 6, myMap);
63+
64+
const result = Core.maps.get(new Map([['a', 5]]), myMap);
65+
t.is(result, 6);
66+
});
67+
68+
test('take/2', (t) => {
69+
const myMap = new Map([['a', 1], ['b', 2]]);
70+
let a;
71+
let result;
72+
[a, result] = Core.maps.take('a', myMap);
73+
t.is(a, 1);
74+
t.is(result.has('a'), false);
75+
});
76+
4177
test('remove', (t) => {
4278
let myMap = new Map([['a', 1], ['b', 2]]);
4379
let result = Core.maps.remove('a', myMap);

test/integration/integration_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ defmodule ElixirScript.Integration.Test do
3434
val = call_compiled_function Integration, :filter_names_in_guards, []
3535
assert val == true
3636
end
37+
38+
test "tuple_get" do
39+
val = call_compiled_function Integration, :tuple_get, []
40+
assert val == 5
41+
end
3742
end

test/support/integration.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ defmodule Integration do
3434
def multi_bind do
3535
[a | _] = b = [1, 2, 3, 4, 5]
3636
end
37+
38+
def tuple_get do
39+
map = %{{1} => 5}
40+
Map.get(map, {1})
41+
end
3742
end

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,9 +3846,9 @@ table@^4.0.1:
38463846
slice-ansi "0.0.4"
38473847
string-width "^2.0.0"
38483848

3849-
tailored@^2.7.2:
3850-
version "2.7.2"
3851-
resolved "https://registry.yarnpkg.com/tailored/-/tailored-2.7.2.tgz#01ab31b9bcacdb33f44da7aaa54fd7beffa1bd0e"
3849+
tailored@^2.7.4:
3850+
version "2.7.4"
3851+
resolved "https://registry.yarnpkg.com/tailored/-/tailored-2.7.4.tgz#473c6c91fcaeb2c8e4ddd5c2bddb33190ac21780"
38523852
dependencies:
38533853
erlang-types "^1.0.1"
38543854

0 commit comments

Comments
 (0)