-
Notifications
You must be signed in to change notification settings - Fork 116
fix: insert "symbols" instead of null for deduped objects
#251
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1158,7 +1158,7 @@ test('regression #245: superjson referential equalities only use the top-most pa | |
| expect(parsed).toEqual(input); | ||
| }); | ||
|
|
||
| test('dedupe=true', () => { | ||
| test('dedupe=true, pruned', () => { | ||
| const instance = new SuperJSON({ | ||
| dedupe: true, | ||
| }); | ||
|
|
@@ -1180,14 +1180,48 @@ test('dedupe=true', () => { | |
| expect(json.a); | ||
|
|
||
| // This has already been seen and should be deduped | ||
| expect(json.b).toBeNull(); | ||
| expect(json.b).toEqual('[Pruned *]'); | ||
|
|
||
| expect(json).toMatchInlineSnapshot(` | ||
| Object { | ||
| "a": Object { | ||
| "children": Array [], | ||
| }, | ||
| "b": null, | ||
| "b": "[Pruned *]", | ||
| } | ||
| `); | ||
|
|
||
| expect(instance.deserialize(output)).toEqual(input); | ||
| }); | ||
|
|
||
| test.only('dedupe=true, circular', () => { | ||
| const instance = new SuperJSON({ | ||
| dedupe: true, | ||
| }); | ||
|
|
||
| type Node = { | ||
| children: Node[]; | ||
| }; | ||
| const root: Node = { | ||
| children: [], | ||
| }; | ||
| root.children.push(root); | ||
| const input = { | ||
| a: root, | ||
| b: root, | ||
| }; | ||
| const output = instance.serialize(input); | ||
|
|
||
| const json = output.json as any; | ||
|
|
||
| expect(json).toMatchInlineSnapshot(` | ||
| Object { | ||
| "a": Object { | ||
| "children": Array [ | ||
| "[Circular *]", | ||
| ], | ||
| }, | ||
| "b": "[Pruned *]", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this say
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're adding this for the output to be more human-readable, I think we should take a string that's searchable + self-explanatory. I don't think |
||
| } | ||
| `); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,7 +169,7 @@ export const walker = ( | |
| // short-circuit result if we've seen this object before | ||
| return dedupe | ||
| ? { | ||
| transformedValue: null, | ||
| transformedValue: '[Pruned *]', | ||
| } | ||
| : seen; | ||
| } | ||
|
|
@@ -195,7 +195,7 @@ export const walker = ( | |
| if (includes(objectsInThisPath, object)) { | ||
| // prevent circular references | ||
| return { | ||
| transformedValue: null, | ||
| transformedValue: '[Circular *]', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also put the path to the object that's circular into here. |
||
| }; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.