You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
serialize(-0) returns "0" - negative zero is lost on round-trip #234
serialize-javascript goes out of its way to preserve the numeric values JSON can't represent - NaN, Infinity, and -Infinity are all emitted as placeholders so they round-trip correctly. -0 falls through the same JSON.stringify path and comes back as plain 0, so a serialized-then-evaluated value is no longer Object.is-equal to the original.
For comparison, the sibling edge cases do round-trip:
Object.is(eval(serialize(NaN)),NaN)// ...evaluates NaN via placeholdereval(serialize(Infinity))// Infinityeval(serialize(-Infinity))// -Infinity
Why it matters:-0 is a real, observable value in JS (Object.is(-0, 0) === false, 1 / -0 === -Infinity). Code that round-trips state through serialize-javascript (worker messaging, SSR state injection, template embedding - the library's main use cases) silently loses the sign. A consumer computing 1 / value after deserialization gets Infinity instead of -Infinity.
Possible fix: in the number branch, detect Object.is(obj, -0) (or obj === 0 && 1 / obj === -Infinity) and emit a placeholder alongside the existing NaN/Infinity/-Infinity ones.
Activity