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

Function constantKeyOf

ark/aot/usage.ts:1368–1393  ·  view source on GitHub ↗
(
	node: Node,
	module: SourceModule,
	seen = new Set<Binding>()
)

Source from the content-addressed store, hash-verified

1366const emptyStringSet: ReadonlySet<string> = new Set()
1367
1368const constantKeyOf = (
1369 node: Node,
1370 module: SourceModule,
1371 seen = new Set<Binding>()
1372): string | undefined => {
1373 node = unwrapExpression(node)
1374 if (node.type === "Literal") {
1375 return typeof node.value === "string" || typeof node.value === "number" ?
1376 String(node.value)
1377 : undefined
1378 }
1379 if (node.type === "TemplateLiteral" && !node.expressions.length)
1380 return node.quasis[0].value.cooked ?? undefined
1381 if (node.type !== "Identifier") return
1382 const binding = module.scopes.byId.get(node)?.binding
1383 if (!binding || binding.kind !== "const" || seen.has(binding)) return
1384 seen.add(binding)
1385 const { declaration } = binding
1386 return (
1387 declaration.type === "VariableDeclarator" &&
1388 declaration.id === binding.id &&
1389 declaration.init
1390 ) ?
1391 constantKeyOf(declaration.init, module, seen)
1392 : undefined
1393}
1394
1395const staticMemberKeyOf = (
1396 member: Extract<Node, { type: "MemberExpression" }>,

Callers 4

staticMemberKeyOfFunction · 0.85
classMemberKeyOfFunction · 0.85
buildThisReadsContextFunction · 0.85
receivesNoEscapedThisFunction · 0.85

Calls 5

unwrapExpressionFunction · 0.90
StringInterface · 0.85
getMethod · 0.65
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected