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

Function readPartsDirectly

ark/aot/flat.ts:1958–1990  ·  view source on GitHub ↗
({ code, program }, s)

Source from the content-addressed store, hash-verified

1956// from a function called where it's declared is that value, since what its
1957// annotation told a bundler has been decided
1958const readPartsDirectly: UnitsPass = ({ code, program }, s) => {
1959 walk(program, node => {
1960 if (
1961 node.type !== "MemberExpression" ||
1962 !node.computed ||
1963 node.object.type !== "ArrayExpression" ||
1964 node.property.type !== "Literal" ||
1965 typeof node.property.value !== "number" ||
1966 !node.object.elements.every(element => element?.type === "Identifier")
1967 )
1968 return true
1969 const element = node.object.elements[node.property.value] as {
1970 name: string
1971 }
1972 s.overwrite(node.start, node.end, element.name)
1973 return false
1974 })
1975 for (const statement of program.body as Node[]) {
1976 if (statement.type !== "VariableDeclaration") continue
1977 for (const { init } of statement.declarations) {
1978 if (
1979 init?.type !== "CallExpression" ||
1980 init.arguments.length ||
1981 init.callee.type !== "ArrowFunctionExpression" ||
1982 init.callee.params.length ||
1983 init.callee.body.type === "BlockStatement"
1984 )
1985 continue
1986 const { body } = init.callee
1987 s.overwrite(init.start, init.end, code.slice(body.start, body.end))
1988 }
1989 }
1990}
1991
1992// V8 parses a function declared for a sixth less than a constant holding it, and
1993// a call reads it without checking it's been initialized

Callers

nothing calls this directly

Calls 1

walkFunction · 0.90

Tested by

no test coverage detected