MCPcopy Create free account
hub / github.com/arktypeio/arktype / nameReference

Function nameReference

ark/schema/units.ts:1009–1043  ·  view source on GitHub ↗
(
	s: ContentNamingState,
	node: BaseNode
)

Source from the content-addressed store, hash-verified

1007
1008// Tarjan's algorithm
1009const nameReference = (
1010 s: ContentNamingState,
1011 node: BaseNode
1012): ContentReference => {
1013 const reference = compileContent(s, node)
1014 s.byId[node.id] = reference
1015 s.reached.push(node)
1016 s.stack.push(reference)
1017 for (const callee of reference.callees) {
1018 const calleeReference = s.byId[callee.id]
1019 if (!calleeReference) {
1020 reference.lowLink = Math.min(
1021 reference.lowLink,
1022 nameReference(s, callee).lowLink
1023 )
1024 } else if (s.names[callee.id] === undefined) {
1025 // a reached node is unnamed only while its component is on the stack
1026 reference.lowLink = Math.min(reference.lowLink, calleeReference.index)
1027 }
1028 }
1029 if (reference.lowLink === reference.index) {
1030 const members = s.stack.splice(s.stack.lastIndexOf(reference))
1031 nameComponent(s, members)
1032 if (
1033 members.some(
1034 member =>
1035 member.holdsIdentity ||
1036 member.callees.some(callee => s.identityNamed.has(callee.id))
1037 )
1038 )
1039 for (const member of members) s.identityNamed.add(member.node.id)
1040 s.components.push(members.map(member => member.node))
1041 }
1042 return reference
1043}
1044
1045const compileContent = (
1046 s: ContentNamingState,

Callers 1

nameReferencesFunction · 0.85

Calls 6

compileContentFunction · 0.85
nameComponentFunction · 0.85
mapMethod · 0.65
pushMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected