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

Function forwardedOf

ark/aot/flat.ts:1620–1635  ·  view source on GitHub ↗
(fn: Node, scopes: ModuleScopes)

Source from the content-addressed store, hash-verified

1618 node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression"
1619
1620const forwardedOf = (fn: Node, scopes: ModuleScopes): Binding | undefined => {
1621 if (!isFunctionExpression(fn) || fn.async) return
1622 const [only] = fn.body.type === "BlockStatement" ? fn.body.body : []
1623 const call =
1624 fn.body.type !== "BlockStatement" ? fn.body
1625 : fn.body.body.length === 1 && only.type === "ReturnStatement" ?
1626 only.argument
1627 : undefined
1628 if (
1629 call?.type !== "CallExpression" ||
1630 call.callee.type !== "Identifier" ||
1631 !passesParams(call, fn)
1632 )
1633 return
1634 return scopes.byId.get(call.callee)?.binding
1635}
1636
1637// a function read once, as a call passing its own parameters, is its body where it's called
1638const inlineCalls: UnitsPass = ({ code, program, scopes }, s, body) => {

Callers 1

skipAliasesFunction · 0.70

Calls 3

isFunctionExpressionFunction · 0.85
passesParamsFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected