diff --git a/package.json b/package.json index 7730783..7323cd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yieldable-json", - "version": "2.0.0", + "version": "2.0.1", "main": "index.js", "description": "An asynchronous yieldable version of JSON.stringify and JSON.parse", "author": "Gireesh Punathil ", diff --git a/test/test-stringify-same-object-twice.js b/test/test-stringify-same-object-twice.js new file mode 100644 index 0000000..2832100 --- /dev/null +++ b/test/test-stringify-same-object-twice.js @@ -0,0 +1,23 @@ +'use strict'; + +const yj = require('../index'); +const tap = require('tap'); + +const obj = { + name: 'Jacqueline Poole', + gender: 'female', + age: 40, +}; + +const master = {arr: [ { a: obj }, { b: obj} ] }; + +// Make sure presence of obj twice in the master +// object does not cause revisit issues while +// stringifying it - such as circular dependency + +yj.stringifyAsync(obj, (err, str) => { + if (!err) { + tap.ok(true, 'Repeated object presence cause no issues'); + } else + tap.fail(err); +}); diff --git a/yieldable-stringify.js b/yieldable-stringify.js index 0965854..b3814f6 100755 --- a/yieldable-stringify.js +++ b/yieldable-stringify.js @@ -224,7 +224,9 @@ function * stringifyYield(field, container, replacer, space, intensity) { ? ': ' : ':') + val); } + objStack = objStack.filter((v, i, a) => { return v !== value[key] }); } + objStack = objStack.filter((v, i, a) => { return v !== value }); } return getResult(true); default: