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

Function exportedFunctionsOf

ark/aot/usage.ts:1048–1073  ·  view source on GitHub ↗
(
	program: Program
)

Source from the content-addressed store, hash-verified

1046 parseCode("validators.js", code, {}).program
1047
1048const exportedFunctionsOf = (
1049 program: Program
1050): Map<string, Node | undefined> => {
1051 const declared = new Map<string, Node>()
1052 const result = new Map<string, Node | undefined>()
1053 for (const statement of program.body) {
1054 if (statement.type === "FunctionDeclaration" && statement.id)
1055 declared.set(statement.id.name, statement)
1056 else if (statement.type === "VariableDeclaration") {
1057 for (const { id, init } of statement.declarations) {
1058 if (id.type === "Identifier" && init)
1059 declared.set(id.name, unwrapParentheses(init))
1060 }
1061 } else if (statement.type === "ExportNamedDeclaration") {
1062 for (const specifier of statement.specifiers) {
1063 result.set(
1064 exportNameOf(specifier.exported),
1065 specifier.local.type === "Identifier" ?
1066 declared.get(specifier.local.name)
1067 : undefined
1068 )
1069 }
1070 }
1071 }
1072 return result
1073}
1074
1075const unwrapParentheses = (node: Node): Node =>
1076 node.type === "ParenthesizedExpression" ?

Callers 1

passedReaderOfFunction · 0.85

Calls 4

exportNameOfFunction · 0.90
unwrapParenthesesFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected