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

Function isPureExpression

ark/aot/flat.ts:903–931  ·  view source on GitHub ↗
(node: Node, source: string)

Source from the content-addressed store, hash-verified

901}
902
903const isPureExpression = (node: Node, source: string): boolean => {
904 node = unwrapExpression(node)
905 switch (node.type) {
906 case "Literal":
907 case "Identifier":
908 case "ArrowFunctionExpression":
909 case "FunctionExpression":
910 return true
911 case "TemplateLiteral":
912 return node.expressions.every(e => isPureExpression(e, source))
913 case "ArrayExpression":
914 return node.elements.every(
915 e => !e || (e.type !== "SpreadElement" && isPureExpression(e, source))
916 )
917 // e.g. `schemas = { user: User }`, which a bundler drops with the
918 // validators only it reads. A computed key other than a literal may call toString
919 case "ObjectExpression":
920 return node.properties.every(
921 p =>
922 p.type === "Property" &&
923 (!p.computed || p.key.type === "Literal") &&
924 isPureExpression(p.value, source)
925 )
926 case "CallExpression":
927 case "NewExpression":
928 return pureAnnotationOf(source, node) !== undefined
929 }
930 return false
931}
932
933// each after those it reads, or undefined where one can't be written into a function
934const unitsOf = (

Callers 5

keepReadMethod · 0.85
isPureFunction · 0.85
writtenWhereReadFunction · 0.85
callsBeforeFunction · 0.85
dropUnreadFunction · 0.85

Calls 2

unwrapExpressionFunction · 0.90
pureAnnotationOfFunction · 0.90

Tested by

no test coverage detected