Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.uneval() does not handle nested maps properly #54

Open
BigAB opened this issue Jan 8, 2023 · 0 comments
Open

.uneval() does not handle nested maps properly #54

BigAB opened this issue Jan 8, 2023 · 0 comments

Comments

@BigAB
Copy link

BigAB commented Jan 8, 2023

Though devalue.stringify() appears to work on nested Maps correctly, devalue.uneval() does not handle the references correctly.

From a setup like this:

import * as devalue from 'devalue';

const node1 = { id: 1 };
const node2 = { id: 2 };
const node3 = { id: 3 };

const map = new Map([
  [node1, new Map([
    [node2, 1],
    [node3, 1]
  ])],
  [node2, new Map([
    [node1, 1],
    [node3, 1]
  ])],
  [node3, new Map([
    [node1, 1],
    [node2, 1]
  ])]
]);

const result = devalue.uneval(map);

I would expect a result like (extrapolated from how arrays are handled):

(function(a, b, c){
  a.id=1;
  b.id=2;
  c.id=3;
  return new Map([
    [a, new Map([
      [b, 1],
      [c, 1]
    ])],
    [b, new Map([
      [a, 1],
      [c, 1]
    ])],
    [c, new Map([
      [a, 1],
      [b, 1]
    ])]
  ]);
})({}, {}, {}))

...but instead the result is

new Map([
  [{id:1}, new Map([
    [{id:2},1],
    [{id:3},1]
  ])],
  [{id:2}, new Map([
    [{id:1}, 1],
    [{id:3}, 1]
  ])],
  [{id:3}, new Map([
    [{id:1}, 1],
    [{id:2}, 1]
  ])]
])

Demonstration: https://svelte.dev/repl/771c6728b27240c486c8c6a3fbc9e280?version=3.49.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant