( s: ContentNamingState, node: BaseNode )
| 1043 | } |
| 1044 | |
| 1045 | const compileContent = ( |
| 1046 | s: ContentNamingState, |
| 1047 | node: BaseNode |
| 1048 | ): ContentReference => { |
| 1049 | const occurrence = s.occurrencesById[node.id] |
| 1050 | const cached = |
| 1051 | occurrence === undefined ? s.written.contents.get(node) : undefined |
| 1052 | if (cached) { |
| 1053 | return { |
| 1054 | node, |
| 1055 | content: cached.content, |
| 1056 | holdsIdentity: false, |
| 1057 | callees: cached.callees, |
| 1058 | index: s.reached.length, |
| 1059 | lowLink: s.reached.length, |
| 1060 | written: cached |
| 1061 | } |
| 1062 | } |
| 1063 | const calleeIds: NodeId[] = [] |
| 1064 | const positionsById: Record<NodeId, number> = {} |
| 1065 | const positionOf = (id: NodeId) => |
| 1066 | id === node.id ? "$" : `$${(positionsById[id] ??= calleeIds.push(id) - 1)}` |
| 1067 | const link = createLinkage(positionOf, s.opts) |
| 1068 | declareTraversals(link, node) |
| 1069 | // vb and mb on a failSite cache compiled error builders on first failure, not content |
| 1070 | const failSites = new Set<object>() |
| 1071 | for (const id in node.byId) { |
| 1072 | const site = node.byId[id].c.failSite |
| 1073 | if (site) failSites.add(site) |
| 1074 | } |
| 1075 | for (const id in link.byId) { |
| 1076 | const site = link.byId[id].c.failSite |
| 1077 | if (site) failSites.add(site) |
| 1078 | } |
| 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 | ) { |
no test coverage detected