( node: Node, module: SourceModule, lacked: ReadonlySet<string> )
| 4861 | |
| 4862 | // e.g. `or` and `T` for `T.or`, or `json` or `assert` where members drops it |
| 4863 | unavailableReadOf( |
| 4864 | node: Node, |
| 4865 | module: SourceModule, |
| 4866 | lacked: ReadonlySet<string> |
| 4867 | ): [read: string | undefined, object: Node, isUnsure?: true] | undefined { |
| 4868 | let read: unknown |
| 4869 | let objects: Node[] = [] |
| 4870 | let kindOf = (object: Node) => this.kindOf(object, module) |
| 4871 | if (node.type === "MemberExpression") { |
| 4872 | read = memberNameOf(node) |
| 4873 | objects = [node.object] |
| 4874 | } else if ( |
| 4875 | (node.type === "Property" || node.type === "RestElement") && |
| 4876 | node.parent?.type === "ObjectPattern" |
| 4877 | ) { |
| 4878 | if (node.type === "Property") read = keyNameOf(node) |
| 4879 | const pattern = node.parent |
| 4880 | let root: Node = pattern |
| 4881 | while (root.parent && isPatternPart(root.parent)) root = root.parent |
| 4882 | const parent = root.parent |
| 4883 | const source = |
| 4884 | parent?.type === "VariableDeclarator" && parent.id === root ? |
| 4885 | parent.init |
| 4886 | : parent?.type === "AssignmentExpression" && parent.left === root ? |
| 4887 | parent.right |
| 4888 | : root.type === "AssignmentPattern" ? root.right |
| 4889 | : undefined |
| 4890 | if (source) { |
| 4891 | objects = [source] |
| 4892 | kindOf = source => |
| 4893 | this.patternKindOf( |
| 4894 | pattern, |
| 4895 | root, |
| 4896 | this.kindOf(source, module), |
| 4897 | module, |
| 4898 | this.finalKindOfKey |
| 4899 | ) |
| 4900 | } |
| 4901 | } else [read, objects] = this.reflectionOf(node, module) ?? [undefined, []] |
| 4902 | // e.g. `User.infer`, which only types a value: a Type reads undefined |
| 4903 | // for it, as a validator does |
| 4904 | if (typeof read === "string" && read in inferenceMembers) return |
| 4905 | // a validator prints its expression as its string |
| 4906 | if (read === "toString" && !lacked.has(read)) read = "expression" |
| 4907 | // every Type and standalone validator is callable (`typeof === "function"`) |
| 4908 | const candidates = objects.filter( |
| 4909 | object => !isProvenNotFunction(object, module) |
| 4910 | ) |
| 4911 | const object = candidates.find(object => isOnlyType(kindOf(object))) |
| 4912 | // e.g. `t.or`, `${t}` or `Object.keys(t)`, where `t` may be a Type |
| 4913 | const unsure = |
| 4914 | !object && |
| 4915 | (node.type === "MemberExpression" || typeof read === "string" ? |
| 4916 | candidates.find(object => isUnsureRead(read, kindOf(object), lacked)) |
| 4917 | : candidates.find(object => kindOf(object) & kinds.type)) |
| 4918 | if (unsure) return [read as string, unsure, true] |
| 4919 | return ( |
| 4920 | object && |
no test coverage detected