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

Function isDirectOwnThisRead

ark/aot/usage.ts:2706–2754  ·  view source on GitHub ↗
(
	node: Node,
	ownKeys: ReadonlySet<string>,
	inlineFnKeys: ReadonlySet<string>,
	allowedCallKey: string | undefined,
	module: SourceModule,
	seen = new Set<Binding>()
)

Source from the content-addressed store, hash-verified

2704}
2705
2706const isDirectOwnThisRead = (
2707 node: Node,
2708 ownKeys: ReadonlySet<string>,
2709 inlineFnKeys: ReadonlySet<string>,
2710 allowedCallKey: string | undefined,
2711 module: SourceModule,
2712 seen = new Set<Binding>()
2713): boolean => {
2714 const [operand, parent] = operatorOf(node)
2715 if (
2716 parent?.type === "MemberExpression" &&
2717 parent.object === operand &&
2718 !isWriteTarget(parent)
2719 ) {
2720 const name = memberNameOf(parent)
2721 if (typeof name !== "string" || !ownKeys.has(name)) return false
2722 if (isDirectCallMember(parent))
2723 return inlineFnKeys.has(name) || name === allowedCallKey
2724 return true
2725 }
2726 if (parent?.type === "VariableDeclarator" && parent.init === operand) {
2727 if (parent.id.type === "ObjectPattern") {
2728 return parent.id.properties.every(property => {
2729 if (property.type !== "Property") return false
2730 const key = propertyKeyOf(property)
2731 return key !== undefined && ownKeys.has(key)
2732 })
2733 }
2734 const binding =
2735 parent.id.type === "Identifier" ?
2736 module.scopes.bindingsById.get(parent.id)
2737 : undefined
2738 if (!binding || binding.writes.length || seen.has(binding)) return false
2739 seen.add(binding)
2740 return binding.references.every(
2741 reference =>
2742 !reference.isWrite &&
2743 isDirectOwnThisRead(
2744 reference.id,
2745 ownKeys,
2746 inlineFnKeys,
2747 allowedCallKey,
2748 module,
2749 seen
2750 )
2751 )
2752 }
2753 return false
2754}
2755
2756// the object literals a function may be bound to as their member, "escapes"
2757// where it may be bound to any other object

Callers 1

receivesNoEscapedThisFunction · 0.85

Calls 8

operatorOfFunction · 0.90
isWriteTargetFunction · 0.90
memberNameOfFunction · 0.90
propertyKeyOfFunction · 0.90
isDirectCallMemberFunction · 0.85
getMethod · 0.65
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected