(value: unknown)
| 1079 | const serializing = new Set<object>() |
| 1080 | let holdsIdentity = false |
| 1081 | const serialize = (value: unknown): string => { |
| 1082 | if (isNode(value)) { |
| 1083 | link.byId[value.id] ??= value |
| 1084 | return positionOf(value.id) |
| 1085 | } |
| 1086 | if (typeof value === "string") |
| 1087 | return s.opts.keyOf?.(value) ?? serializePrimitive(value) |
| 1088 | if (!hasDomain(value, "object") && typeof value !== "symbol") |
| 1089 | return Object.is(value, -0) ? "-0" : serializePrimitive(value as never) |
| 1090 | const key = |
| 1091 | s.opts.keyOf?.(value) ?? |
| 1092 | // arktype's own pattern instance is keyed by its source |
| 1093 | (value instanceof RegExp && isPatternInstanceIn(node, value) ? |
| 1094 | `${value}` |
| 1095 | : undefined) |
| 1096 | if (key !== undefined) return key |
| 1097 | const prototype = typeof value === "object" && Object.getPrototypeOf(value) |
| 1098 | // a value containing itself is keyed by identity |
| 1099 | if ( |
| 1100 | serializing.has(value as object) || |
| 1101 | (!isArray(value) && prototype !== Object.prototype && prototype !== null) |
| 1102 | ) { |
| 1103 | let i = s.valueIndices.get(value) |
| 1104 | if (i === undefined) s.valueIndices.set(value, (i = s.valueIndices.size)) |
| 1105 | holdsIdentity = true |
| 1106 | return `v${i}` |
| 1107 | } |
| 1108 | serializing.add(value as object) |
| 1109 | const isFailSite = failSites.has(value as object) |
| 1110 | const content = |
| 1111 | isArray(value) ? |
| 1112 | `[${value.map(serialize)}]` |
| 1113 | : `{${Object.entries(value) |
| 1114 | .filter(([k]) => !isFailSite || (k !== "vb" && k !== "mb")) |
| 1115 | .map(([k, v]) => `${JSON.stringify(k)}: ${serialize(v)}`)}}` |
| 1116 | serializing.delete(value as object) |
| 1117 | return content |
| 1118 | } |
| 1119 | const content = [ |
| 1120 | node.kind, |
| 1121 | // a program's nodes stay apart from another scope's |
no test coverage detected