The object that never stays the same
Equivalent snapshots keep producing new references when a property contains undefined.
What’s going wrong
A state cache structurally shares unchanged containers between a previous tree and a next tree. Stdin is an array of {"before":tree,"after":tree} pairs. Trees contain JSON scalars, dense arrays and plain objects. The exact marker {"$undefined":true} represents a present undefined value in an object; the marker never occurs directly in an array or at the root. Object keys exclude __proto__, constructor and prototype. Equal containers must reuse their previous reference if they have the same kind, the same own keys and recursively equal children; object key insertion order is irrelevant, array order matters. Changed containers are rebuilt, but unchanged descendants are still reused. Print one {"value":encodedResult,"rootReused":boolean,"reusedPaths":[paths]} per pair. value must equal the complete after tree, including present undefined fields encoded back as markers. reusedPaths lists only reused object/array references at corresponding before/after paths in depth-first order, root first as [], using string object keys and numeric array indexes. Traversal follows the after tree key order. Missing properties and present undefined properties are distinct.
Read one JSON value from stdin and print the specified JSON result to stdout. No actual network or external package is used.
Expected behavior
Separate property presence, value equality and container identity while preserving unchanged subtrees.
Reproduction
[{"before":{"data":{"$undefined":true},"ready":true},"after":{"data":{"$undefined":true},"ready":true}}][{"value":{"data":{"$undefined":true},"ready":true},"rootReused":true,"reusedPaths":[[]]}][{"before":{"x":1},"after":{"x":1}}][{"value":{"x":1},"rootReused":true,"reusedPaths":[[]]}][{"before":{"x":1},"after":{"x":2}}][{"value":{"x":2},"rootReused":false,"reusedPaths":[]}]Before you begin
- Build on typed key identity: an absent key and a key holding undefined can read alike but describe different shapes.
- TypeScript unions, arrays, objects and functions
- Trace runtime behavior even when the program type-checks
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.