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

Function collectNamed

ark/aot/unwrite.ts:332–355  ·  view source on GitHub ↗
(
	node: NamedNode,
	code: string,
	named: (Token | Span)[]
)

Source from the content-addressed store, hash-verified

330}
331
332const collectNamed = (
333 node: NamedNode,
334 code: string,
335 named: (Token | Span)[]
336): void => {
337 const { start, end } = node
338 if (node.type === "Literal" && typeof node.value === "string") {
339 // by its value, as one transform quotes it otherwise than another
340 named.push({ start, end, text: JSON.stringify(node.value) })
341 } else if (
342 (node.type === "Literal" && node.regex) ||
343 node.type === "TemplateElement" ||
344 node.type === "JSXText"
345 )
346 named.push({ start, end, text: code.slice(start, end) })
347 for (const key in node) {
348 if (key === "parent") continue
349 const child = (node as never as Record<string, unknown>)[key]
350 if (Array.isArray(child)) {
351 for (const item of child)
352 if (isNode(item)) collectNamed(item, code, named)
353 } else if (isNode(child)) collectNamed(child, code, named)
354 }
355}
356
357const isNode = (value: unknown): value is NamedNode =>
358 typeof value === "object" &&

Callers 1

tokensOfFunction · 0.85

Calls 2

isNodeFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected