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

Function testProvesNotFunction

ark/aot/graph.ts:6800–6886  ·  view source on GitHub ↗
(
	node: Node,
	expectTruthy: boolean,
	binding: Binding,
	module: SourceModule
)

Source from the content-addressed store, hash-verified

6798}
6799
6800const testProvesNotFunction = (
6801 node: Node,
6802 expectTruthy: boolean,
6803 binding: Binding,
6804 module: SourceModule
6805): boolean => {
6806 const test = unwrapExpression(node)
6807 if (test.type === "UnaryExpression" && test.operator === "!")
6808 return testProvesNotFunction(test.argument, !expectTruthy, binding, module)
6809 if (test.type === "LogicalExpression") {
6810 if (test.operator === "&&") {
6811 return expectTruthy ?
6812 testProvesNotFunction(test.left, true, binding, module) ||
6813 testProvesNotFunction(test.right, true, binding, module)
6814 : testProvesNotFunction(test.left, false, binding, module) &&
6815 testProvesNotFunction(test.right, false, binding, module)
6816 }
6817 if (test.operator === "||") {
6818 return expectTruthy ?
6819 testProvesNotFunction(test.left, true, binding, module) &&
6820 testProvesNotFunction(test.right, true, binding, module)
6821 : testProvesNotFunction(test.left, false, binding, module) ||
6822 testProvesNotFunction(test.right, false, binding, module)
6823 }
6824 }
6825 if (!expectTruthy && isBoundId(test, binding, module)) return true
6826 if (
6827 test.type === "BinaryExpression" &&
6828 (test.operator === "===" ||
6829 test.operator === "==" ||
6830 test.operator === "!==" ||
6831 test.operator === "!=")
6832 ) {
6833 const isEq = test.operator === "===" || test.operator === "=="
6834 const holdsEq = expectTruthy ? isEq : !isEq
6835 const checkTypeof = (a: Node, b: Node): boolean => {
6836 const ua = unwrapExpression(a)
6837 const ub = unwrapExpression(b)
6838 if (
6839 ua.type === "UnaryExpression" &&
6840 ua.operator === "typeof" &&
6841 isBoundId(ua.argument, binding, module) &&
6842 ub.type === "Literal" &&
6843 typeof ub.value === "string"
6844 ) {
6845 return holdsEq ?
6846 ub.value in nonFunctionTypeofs
6847 : ub.value === "function"
6848 }
6849 return false
6850 }
6851 if (
6852 checkTypeof(test.left, test.right) ||
6853 checkTypeof(test.right, test.left)
6854 )
6855 return true
6856 if (
6857 holdsEq &&

Callers 1

isProvenNotFunctionFunction · 0.85

Calls 7

unwrapExpressionFunction · 0.90
unwrapChainFunction · 0.90
isBoundIdFunction · 0.85
checkTypeofFunction · 0.85
isNullishLiteralFunction · 0.85
memberNameOfFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected