(node: Node, module: SourceModule)
| 6683 | // e.g. `issue` inside `if (typeof issue === "object" && ...)`, which cannot |
| 6684 | // hold a Type or standalone validator since both are callable functions |
| 6685 | const isProvenNotFunction = (node: Node, module: SourceModule): boolean => { |
| 6686 | const id = unwrapChain(node) |
| 6687 | if (id.type !== "Identifier") return false |
| 6688 | const binding = module.scopes.byId.get(id)?.binding |
| 6689 | if (!binding || binding.writes.length) return false |
| 6690 | let child: Node = id |
| 6691 | for (let parent = id.parent; parent; child = parent, parent = parent.parent) { |
| 6692 | if (isFunctionNode(parent) || parent.type === "ClassBody") break |
| 6693 | if (parent.type === "LogicalExpression" && parent.right === child) { |
| 6694 | if ( |
| 6695 | parent.operator === "&&" && |
| 6696 | testProvesNotFunction(parent.left, true, binding, module) |
| 6697 | ) |
| 6698 | return true |
| 6699 | if ( |
| 6700 | parent.operator === "||" && |
| 6701 | testProvesNotFunction(parent.left, false, binding, module) |
| 6702 | ) |
| 6703 | return true |
| 6704 | } else if (parent.type === "ConditionalExpression") { |
| 6705 | if ( |
| 6706 | parent.consequent === child && |
| 6707 | testProvesNotFunction(parent.test, true, binding, module) |
| 6708 | ) |
| 6709 | return true |
| 6710 | if ( |
| 6711 | parent.alternate === child && |
| 6712 | testProvesNotFunction(parent.test, false, binding, module) |
| 6713 | ) |
| 6714 | return true |
| 6715 | } else if (parent.type === "IfStatement") { |
| 6716 | if ( |
| 6717 | parent.consequent === child && |
| 6718 | testProvesNotFunction(parent.test, true, binding, module) |
| 6719 | ) |
| 6720 | return true |
| 6721 | if ( |
| 6722 | parent.alternate === child && |
| 6723 | testProvesNotFunction(parent.test, false, binding, module) |
| 6724 | ) |
| 6725 | return true |
| 6726 | } else if ( |
| 6727 | parent.type === "BlockStatement" || |
| 6728 | parent.type === "SwitchCase" || |
| 6729 | parent.type === "Program" |
| 6730 | ) { |
| 6731 | const list = |
| 6732 | parent.type === "SwitchCase" ? parent.consequent : parent.body |
| 6733 | const index = list.indexOf(child as never) |
| 6734 | for (let i = index - 1; i >= 0; i--) { |
| 6735 | const stmt = list[i] |
| 6736 | if (stmt.type !== "IfStatement") continue |
| 6737 | const cExits = alwaysExits(stmt.consequent) |
| 6738 | const aExits = stmt.alternate ? alwaysExits(stmt.alternate) : false |
| 6739 | if ( |
| 6740 | cExits && |
| 6741 | !aExits && |
| 6742 | testProvesNotFunction(stmt.test, false, binding, module) |
no test coverage detected