diff --git a/src/stringify.js b/src/stringify.js index df291fd..288449d 100644 --- a/src/stringify.js +++ b/src/stringify.js @@ -48,14 +48,14 @@ export function stringify(value, reducers) { throw new DevalueError(`Cannot stringify a function`, keys); } - if (indexes.has(thing)) return indexes.get(thing); - if (thing === undefined) return UNDEFINED; if (Number.isNaN(thing)) return NAN; if (thing === Infinity) return POSITIVE_INFINITY; if (thing === -Infinity) return NEGATIVE_INFINITY; if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO; + if (indexes.has(thing)) return indexes.get(thing); + const index = p++; indexes.set(thing, index); diff --git a/test/test.js b/test/test.js index ebd4147..a1aa7c8 100644 --- a/test/test.js +++ b/test/test.js @@ -124,6 +124,12 @@ const fixtures = { js: '["a","b","c"]', json: '[[1,2,3],"a","b","c"]' }, + { + name: 'Array where negative zero appears after normal zero', + value: [0, -0], + js: '[0,-0]', + json: '[[1,-6],0]' + }, { name: 'Array (empty)', value: [],