Skip to content

Commit 3b06dcd

Browse files
committed
only deduplicate non-primitives
1 parent 9537f49 commit 3b06dcd

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/uneval.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ export function uneval(value) {
3030
throw new DevalueError(`Cannot stringify a function`, keys);
3131
}
3232

33-
if (counts.has(thing)) {
34-
counts.set(thing, counts.get(thing) + 1);
35-
return;
36-
}
33+
if (!is_primitive(thing)) {
34+
if (counts.has(thing)) {
35+
counts.set(thing, counts.get(thing) + 1);
36+
return;
37+
}
3738

38-
counts.set(thing, 1);
39+
counts.set(thing, 1);
3940

40-
if (!is_primitive(thing)) {
4141
const type = get_type(thing);
4242

4343
switch (type) {

test/test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,25 @@ const fixtures = {
299299
{
300300
name: 'String (repetition)',
301301
value: ['a string', 'a string'],
302-
js: '(function(a){return [a,a]}("a string"))',
302+
js: '["a string","a string"]',
303303
json: '[[1,1],"a string"]'
304-
}
304+
},
305+
306+
{
307+
name: 'null (repetition)',
308+
value: [null, null],
309+
js: '[null,null]',
310+
json: '[[1,1],null]'
311+
},
312+
313+
((object) => {
314+
return {
315+
name: 'Object (repetition)',
316+
value: [object, object],
317+
js: '(function(a){return [a,a]}({}))',
318+
json: '[[1,1],{}]'
319+
};
320+
})({})
305321
],
306322

307323
XSS: [

0 commit comments

Comments
 (0)