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

Function es5ProtoMethodOf

ark/aot/usage.ts:1755–1787  ·  view source on GitHub ↗
(
	fn: Node,
	module: SourceModule
)

Source from the content-addressed store, hash-verified

1753
1754// e.g. `Component.prototype.forceUpdate = function () { ... }` in compiled dependencies
1755const es5ProtoMethodOf = (
1756 fn: Node,
1757 module: SourceModule
1758): Es5ProtoMethod | undefined => {
1759 if (fn.type !== "FunctionExpression") return
1760 const [rhs, assign] = operatorOf(fn)
1761 if (
1762 assign?.type !== "AssignmentExpression" ||
1763 assign.operator !== "=" ||
1764 assign.right !== rhs ||
1765 !isDiscardedAssignment(assign)
1766 )
1767 return
1768 const left = unwrapExpression(assign.left)
1769 if (left.type !== "MemberExpression") return
1770 const methodKey = staticMemberKeyOf(left, module)
1771 if (methodKey === undefined) return
1772 const proto = unwrapExpression(left.object)
1773 if (proto.type !== "MemberExpression" || memberNameOf(proto) !== "prototype")
1774 return
1775 const ctorNode = unwrapExpression(proto.object)
1776 if (ctorNode.type !== "Identifier") return
1777 const ctorBinding = module.scopes.byId.get(ctorNode)?.binding
1778 if (!ctorBinding || ctorBinding.writes.length > 0) return
1779 const isCtorFn =
1780 ctorBinding.kind === "function" ||
1781 (ctorBinding.declaration.type === "VariableDeclarator" &&
1782 ctorBinding.declaration.id === ctorBinding.id &&
1783 !!ctorBinding.declaration.init &&
1784 unwrapExpression(ctorBinding.declaration.init).type ===
1785 "FunctionExpression")
1786 return isCtorFn ? { ctorBinding, methodKey } : undefined
1787}
1788
1789// whether `fn`'s `this` reads cannot reach any object literal and are skipped by
1790// `thisReadsOf`: class constructors, non-detached class/ES5-prototype methods,

Callers 1

computeSkippedFunctionFunction · 0.85

Calls 6

operatorOfFunction · 0.90
unwrapExpressionFunction · 0.90
memberNameOfFunction · 0.90
isDiscardedAssignmentFunction · 0.85
staticMemberKeyOfFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected