Open
Conversation
|
This seems to introduce a regression in the following case. import superjson from 'superjson';
const circularSet = new Set();
circularSet.add(circularSet);
const json = superjson.stringify(circularSet);
const result = superjson.parse(json);
if (result.has(result)) {
console.log("✅ Reference preserved");
} else {
console.error("❌ Reference broken: Set does not contain itself");
console.log(result);
} |
|
Also found this case that seems to regress import superjson from 'superjson';
const sharedRegex = /\s+/;
const root = {
a: sharedRegex,
b: sharedRegex
};
const json = superjson.stringify(root);
const result = superjson.parse(json);
if (result.a === result.b) {
console.log("✅ Shared reference preserved");
} else {
console.error("❌ Shared reference lost: result.a !== result.b");
} |
Collaborator
Author
|
Thanks! I found a fix for the shared regex, will take a look at the circular set after the weekend. If you find a solution i'm all ears! |
Collaborator
Author
|
Managed to fix the circular set, but the diff is becoming more and more unwieldly the more I fix stuff. I'm less convinced of this approach now, but going through the motions seems to be a good way of expanding our test coverage. @JeremyMoeglich if you could try to find some more breakages, that'd be wonderful! |
|
Found this case. import superjson from 'superjson';
const outer = new Set();
const inner = new Set();
// outer -> inner
outer.add(inner);
// inner -> outer
inner.add(outer);
const json = superjson.stringify(outer);
const result = superjson.parse(json);
const resultInner = result.values().next().value;
if (resultInner instanceof Set && resultInner.has(result)) {
console.log("✅ Success: Nested circular Set reference preserved");
} else {
console.error("❌ Mismatch: Reference broken.");
} |
|
Another case import superjson from 'superjson';
const inner = [/a/];
const root = [inner, inner];
try {
const json = superjson.stringify(root);
const _ = superjson.parse(json);
} catch (e) {
console.error(`❌ threw: ${e}`);
} |
|
Another case: import superjson from "superjson";
const ta = new Uint8Array(0);
const inner = [ta, ta];
const root = [inner, inner];
const s1 = superjson.stringify(root);
const roundtripped = superjson.parse(s1);
const s2 = superjson.stringify(roundtripped);
if (s1 !== s2) {
console.error("❌ mismatch: restringified !== stringified");
console.log(s1);
console.log(s2);
} else {
console.log("✅ ok: restringified === stringified");
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #346