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

Doesn't correctly handle repeated references #15

Closed
chocolateboy opened this issue May 2, 2015 · 1 comment
Closed

Doesn't correctly handle repeated references #15

chocolateboy opened this issue May 2, 2015 · 1 comment

Comments

@chocolateboy
Copy link

test.js

var pp = require('stringify-object');

var value = { value: 42 };
var object = { foo: value, bar: value };

console.log(pp(object));

output

{
    foo: {
        value: 42
    },
    bar: null
}

object.bar is not a circular reference. It's just a reference that has already been seen in object, which is not the same thing.

Also, I expected "handles circular references" to mean they're flagged e.g. with [Circular] like util.inspect, rather than null, which, IMO, is misleading (even though it's documented). I just spent a fair bit of time trying to track down what I assumed was a bug in my code that was causing a value to be set to null only to find that it's not actually null...

@chocolateboy chocolateboy changed the title Doesn't correctly handle "circular" references Doesn't correctly handle repeated references May 2, 2015
@sindresorhus
Copy link
Member

I agree with returning [Circular]. In hindsight returning null was a mistake. Fixed now.

I've also fixed the false positive on the circular reference thingy. Turns out I forgot to remove it from seen after recursing.

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

2 participants