Skip to content

Commit

Permalink
fix: handle complex Map keys;
Browse files Browse the repository at this point in the history
- See #9
  • Loading branch information
lukeed committed Jan 11, 2020
1 parent 4bc29f0 commit eabd71f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function klona(x) {
if (str === '[object Map]') {
tmp = new Map();
x.forEach(function (val, key) {
tmp.set(key, klona(val));
tmp.set(klona(key), klona(val));
});
return tmp;
}
Expand Down
17 changes: 17 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ test('map :: nested', t => {
});


test('map :: nested :: keys', t => {
const input = new Map([
[{ foo:1 }, { a: 1 }]
]);

const output = klona(input);
t.deepEqual(input, output);

[...output.keys()][0].bar = 2;

t.deepEqual([...input.keys()][0], { foo:1 });
t.deepEqual([...output.keys()][0], { foo:1, bar:2 });

t.end();
});


test('null', t => {
let input = null;
let output = klona(input);
Expand Down

0 comments on commit eabd71f

Please sign in to comment.