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

Function writePredicate

ark/type/standalone/combinators.ts:1280–1304  ·  view source on GitHub ↗
(
	js: CombinatorCompiler,
	node: nodeOfKind<"predicate">
)

Source from the content-addressed store, hash-verified

1278
1279// a callback is read where it's called, as it may be set once this has loaded
1280const writePredicate = (
1281 js: CombinatorCompiler,
1282 node: nodeOfKind<"predicate">
1283): string => {
1284 const fn = js.ref(node.predicate)
1285 if (isKeyword(node.predicate)) {
1286 return writeCall(
1287 "check",
1288 '"predicate"',
1289 JSON.stringify(predicateSiteOf(node)!.description),
1290 fn
1291 )
1292 }
1293 return writeCall(
1294 // passed a ctx of its own, which reports at a site as a check does
1295 testsOrRejects.has(node.predicate) ? "narrowedRejecting"
1296 : returnsReports.has(node.predicate) ? "narrowedWithCtx"
1297 : raisesNothing(node.predicate) ? "narrowedBy"
1298 : "narrowedInCtx",
1299 `() => ${fn}`,
1300 isNamedByItsFunction(node) ? undefined : (
1301 JSON.stringify(predicateSiteOf(node)!.description)
1302 )
1303 )
1304}
1305
1306const caseMember = (node: UnionNode, k: string): BaseRoot | undefined =>
1307 (node.discriminant!.members as Record<string, BaseRoot> | undefined)?.[k]

Callers 1

Calls 7

isKeywordFunction · 0.90
raisesNothingFunction · 0.90
writeCallFunction · 0.85
predicateSiteOfFunction · 0.85
isNamedByItsFunctionFunction · 0.85
refMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected