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

Method valueIn

ark/aot/graph.ts:4720–4779  ·  view source on GitHub ↗
(
		literal: Located,
		name: unknown,
		seen = new Set<Node>()
	)

Source from the content-addressed store, hash-verified

4718
4719 // null where the literal holds nothing at the key, undefined if unknown
4720 private valueIn(
4721 literal: Located,
4722 name: unknown,
4723 seen = new Set<Node>()
4724 ): Located | null | undefined {
4725 const { node } = literal
4726 if (node.type === "ArrayExpression") {
4727 const index =
4728 typeof name === "number" ? name
4729 : typeof name === "string" && /^(?:0|[1-9]\d*)$/.test(name) ?
4730 Number(name)
4731 : undefined
4732 // e.g. `length` or `map`, which no element can replace
4733 if (index === undefined) return null
4734 const elements = node.elements.slice(0, index + 1)
4735 if (elements.some(element => element?.type === "SpreadElement")) return
4736 const element = node.elements[index]
4737 return element ? { ...literal, node: element } : null
4738 }
4739 const properties = membersOf(node)
4740 const key = name === undefined ? undefined : String(name)
4741 for (let i = properties.length - 1; i >= 0; i--) {
4742 const property = properties[i]
4743 if (property.type === "SpreadElement") {
4744 const spread = this.literalOf(
4745 property.argument,
4746 literal.module,
4747 literal.kindOfKey,
4748 seen
4749 )
4750 const value = spread && this.valueIn(spread, name, seen)
4751 if (value !== null) return value
4752 continue
4753 }
4754 if (!("key" in property)) continue
4755 const propertyKey = keyNameOf(property)
4756 if (propertyKey === undefined || key === undefined) return
4757 if (String(propertyKey) !== key) continue
4758 const value = memberValueOf(property)
4759 if (accessorKindOf(property) === "get") {
4760 const returned = onlyReturnOf(value as FunctionNode)
4761 return returned && { ...literal, node: returned }
4762 }
4763 if (accessorKindOf(property) === "set") return
4764 return value ? { ...literal, node: value } : null
4765 }
4766 if (
4767 (node.type === "ClassDeclaration" || node.type === "ClassExpression") &&
4768 node.superClass
4769 ) {
4770 const parent = this.literalOf(
4771 node.superClass,
4772 literal.module,
4773 literal.kindOfKey,
4774 seen
4775 )
4776 return parent && this.valueIn(parent, name, seen)
4777 }

Callers 10

queryKindOfMethod · 0.95
jsxComponentOfMethod · 0.95
patternKindOfMethod · 0.95
destructuredValueOfMethod · 0.95
memberKindInMethod · 0.95
exposedKindOfMethod · 0.95
passedMemberKindInMethod · 0.95
literalOfMethod · 0.95
readsPrimitiveMethod · 0.95
methodOfMethod · 0.95

Calls 8

literalOfMethod · 0.95
StringInterface · 0.85
memberValueOfFunction · 0.85
accessorKindOfFunction · 0.85
onlyReturnOfFunction · 0.85
testMethod · 0.80
membersOfFunction · 0.70
keyNameOfFunction · 0.70

Tested by

no test coverage detected