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

Method isPastErrorsTest

ark/aot/usage.ts:516–569  ·  view source on GitHub ↗
(read: Node, binding: Binding)

Source from the content-addressed store, hash-verified

514 // e.g. `data` in `out instanceof type.errors ? out.issues : { data }`, or
515 // anywhere after `if (out instanceof type.errors) return out.issues`
516 private isPastErrorsTest(read: Node, binding: Binding): boolean {
517 const tests = (test: Node): boolean => {
518 const expression = unwrapExpression(test) as Node
519 return (
520 expression.type === "BinaryExpression" &&
521 this.isErrorsTest(expression, unwrapExpression(expression.left)) &&
522 binding.references.some(
523 ({ id }) => id === unwrapExpression(expression.left)
524 )
525 )
526 }
527 const refutes = (test: Node): boolean => {
528 const expression = unwrapExpression(test) as Node
529 return (
530 expression.type === "UnaryExpression" &&
531 expression.operator === "!" &&
532 tests(expression.argument)
533 )
534 }
535 let node = read
536 for (
537 let parent = node.parent;
538 parent;
539 node = parent, parent = node.parent
540 ) {
541 // hoisted, so it may run before any test
542 if (parent.type === "FunctionDeclaration") return false
543 if (
544 parent.type === "ConditionalExpression" ||
545 parent.type === "IfStatement"
546 ) {
547 if (node === parent.alternate && tests(parent.test)) return true
548 if (node === parent.consequent && refutes(parent.test)) return true
549 } else if (
550 parent.type === "BlockStatement" ||
551 parent.type === "Program"
552 ) {
553 const body = parent.body as Node[]
554 if (
555 body
556 .slice(0, body.indexOf(node))
557 .some(
558 statement =>
559 statement.type === "IfStatement" &&
560 !statement.alternate &&
561 tests(statement.test) &&
562 leaves(statement.consequent)
563 )
564 )
565 return true
566 }
567 }
568 return false
569 }
570
571 // a validator, or an object literal holding one at path, as a value
572 private readValue(

Callers 1

readResultMethod · 0.95

Calls 1

leavesFunction · 0.70

Tested by

no test coverage detected