Versions 174 to 175
Lines 1–20 at 175 (were 1–3 at 174)
1+/** Internal values may expose an exact streaming representation without changing public toJSON. */ 2+const streamingValues = new WeakMap<object, () => unknown>(); 3+export function registerJsonChunkValue(value: object, representation: () => unknown): void { 4+ streamingValues.set(value, representation); 7+/** A JSON string backed by bounded, replayable UTF-16 chunks. */ 8+export class JsonStringChunks { 9+ readonly chunks: () => Iterable<string>; 10+ constructor(chunks: () => Iterable<string>) { 11+ this.chunks = chunks; 14+ return [...this.chunks()].join(""); 118/** JSON.stringify-compatible chunks for canonical data, without a whole-value string. 219 * Individual input strings and object key lists still belong to the caller. Lines 33–42 at 175 (were 16–22 at 174)
1835 const normalize = (value: unknown, key: string): unknown => { 36+ if (value instanceof JsonStringChunks) return value; 1937 if (value !== null && typeof value === "object") { 38+ const streaming = streamingValues.get(value); 39+ if (streaming) return streaming(); 2040 const toJSON = (value as { toJSON?: unknown }).toJSON; 2141 if (typeof toJSON === "function") return toJSON.call(value, key); Lines 44–64 at 175 (were 24–30 at 174)
2545 const omitted = (value: unknown) => value === undefined || typeof value === "function" || typeof value === "symbol"; 2646 function* encode(value: unknown): IterableIterator<string> { 27− if (typeof value === "string") yield* string(value);
47+ if (value instanceof JsonStringChunks) { 50+ for (const chunk of value.chunks()) { 51+ if (typeof chunk !== "string" || chunk.length > 16384) throw Error("JSON string chunk exceeds bound"); 52+ const text = pending + chunk; 53+ let end = text.length; 54+ const last = text.charCodeAt(end - 1); 55+ if (last >= 0xd800 && last <= 0xdbff) end--; 56+ pending = text.slice(end); 57+ if (end) yield JSON.stringify(text.slice(0, end)).slice(1, -1); 59+ if (pending) yield JSON.stringify(pending).slice(1, -1); 61+ } else if (typeof value === "string") yield* string(value); 2862 else if (value === null || typeof value === "boolean" || typeof value === "number") yield JSON.stringify(value); 2963 else if (typeof value !== "object" || value === null) throw Error("unsupported canonical JSON value");