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

Function thisReadsOf

ark/aot/usage.ts:1689–1740  ·  view source on GitHub ↗
(
	modules: Iterable<SourceModule>,
	options?: ThisReadsOptions
)

Source from the content-addressed store, hash-verified

1687}
1688
1689export const thisReadsOf = (
1690 modules: Iterable<SourceModule>,
1691 options?: ThisReadsOptions
1692): ThisReads => {
1693 const moduleList = [...modules]
1694 const ctx = buildThisReadsContext(moduleList, options)
1695 const reads: ThisReads = {
1696 escaped: { keys: new Set(), any: false },
1697 byLiteral: new Map(),
1698 patchesBuiltins: ctx.patchesBuiltins
1699 }
1700 const addLiteralTarget = (literal: Node, targets: KeyReads[]) => {
1701 let own = reads.byLiteral.get(literal)
1702 if (!own) {
1703 own = { keys: new Set(), any: false }
1704 ;(reads.byLiteral as Map<Node, KeyReads>).set(literal, own)
1705 }
1706 targets.push(own)
1707 }
1708 for (const module of moduleList) {
1709 walk(module.program, node => {
1710 if (node.type !== "ThisExpression") return true
1711 const fn = enclosingThisFunctionOf(node)
1712 if (!fn || isSkippedFunction(fn, module, ctx)) return true
1713 const read = namesReadOf(node, module, ctx)
1714 if (read !== "any" && !read.size) return true
1715 const bound = boundLiteralsOf(fn, module)
1716 const ownLiteral =
1717 (
1718 fn.parent?.type === "Property" &&
1719 fn.parent.value === fn &&
1720 fn.parent.parent?.type === "ObjectExpression"
1721 ) ?
1722 fn.parent.parent
1723 : undefined
1724 const targets: KeyReads[] = []
1725 if (bound === "escapes") {
1726 targets.push(reads.escaped)
1727 // keep own literal's reads indexed even when its method escapes, so
1728 // isolated-receiver checks on that literal still see its own methods
1729 if (ownLiteral) addLiteralTarget(ownLiteral, targets)
1730 } else for (const literal of bound) addLiteralTarget(literal, targets)
1731
1732 for (const target of targets) {
1733 if (read === "any") target.any = true
1734 else for (const key of read) target.keys.add(key)
1735 }
1736 return true
1737 })
1738 }
1739 return reads
1740}
1741
1742const classMemberParentOf = (fn: Node): ClassMemberNode | undefined => {
1743 const [operand, parent] = operatorOf(fn)

Callers 2

thisReadsMethod · 0.90
thisReadsMethod · 0.85

Calls 9

walkFunction · 0.90
buildThisReadsContextFunction · 0.85
enclosingThisFunctionOfFunction · 0.85
isSkippedFunctionFunction · 0.85
namesReadOfFunction · 0.85
boundLiteralsOfFunction · 0.85
addLiteralTargetFunction · 0.85
pushMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected