-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Introduce trace flag to mark circular reference keys (#1) #3
Conversation
Can you add a test where the trace refers to a nested property? |
@@ -23,6 +23,9 @@ console.log(safeStringify(foo)); | |||
|
|||
console.log(JSON.stringify(foo)); | |||
//=> TypeError: Converting circular structure to JSON | |||
|
|||
console.log(safeStringify(foo, {trace: true})); | |||
//=> '{ "a": true, "b": "[Circular *]" }' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the example should be moved to the trace
option docs.
@@ -23,6 +23,9 @@ console.log(safeStringify(foo)); | |||
|
|||
console.log(JSON.stringify(foo)); | |||
//=> TypeError: Converting circular structure to JSON | |||
|
|||
console.log(safeStringify(foo, {trace: true})); | |||
//=> '{ "a": true, "b": "[Circular *]" }' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//=> '{ "a": true, "b": "[Circular *]" }' | |
//=> '{"a":true,"b":"[Circular *]"}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use an example that shows a named pointer *c
.
@@ -51,6 +54,14 @@ By default, the JSON is not indented. | |||
|
|||
Set it to `'\t'` for tab indentation or the number of spaces you want. | |||
|
|||
##### trace | |||
|
|||
Type: `boolean` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type: `boolean` | |
Type: `boolean`\ | |
Default: `false` |
/** | ||
Enable key tracing for circular references. | ||
|
||
By default, this option is set to false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the default notation: https://github.com/sindresorhus/typescript-definition-style-guide#documentation
@@ -7,6 +7,13 @@ export type Options = { | |||
Set it to `'\t'` for tab indentation or the number of spaces you want. | |||
*/ | |||
readonly indentation?: string | number; | |||
|
|||
/** | |||
Enable key tracing for circular references. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect indentation.
|
||
Type: `boolean` | ||
|
||
Enable key tracing for circular references. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the description should be clearer about what it does.
@GeorgeGkas Still interested in finishing this? :) |
Hey @sindresorhus. I'm looking into this a bit more and I believe we still have not covered all the cases. The current implementation has a bug. Consider the following example: const foo = {a: true};
foo.b = {};
foo.c = foo.b; If we run {
"a": true,
"b": {},
"c": "[Circular *b]"
} where the correct output should be: {
"a": true,
"b": {},
"c": {}
} Even if there is no circular dependency, the algorithm thinks otherwise. This results from the way we check for circular dependencies. Unfortunately, I don't have time to look into this in more depth now. Should I close this PR and come back again with a better |
I'm aware of that issue and intend to look into it, but I think that issue needs to block this pull request. |
Closing for lack of activity. |
Fixes #1