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

Function findNodeByPreference

ark/attest/cli/trace.ts:834–863  ·  view source on GitHub ↗
(nodes: ts.Node[])

Source from the content-addressed store, hash-verified

832}
833
834const findNodeByPreference = (nodes: ts.Node[]): ts.Node | undefined => {
835 if (nodes.length === 0) return undefined
836 const typeReference = nodes.find(
837 node => syntax.isTypeReferenceNode(node) || syntax.isTypeQueryNode(node)
838 )
839 if (typeReference) return typeReference
840 const declaration = nodes.find(
841 node =>
842 syntax.isVariableDeclaration(node) ||
843 syntax.isFunctionDeclaration(node) ||
844 syntax.isClassDeclaration(node) ||
845 syntax.isInterfaceDeclaration(node)
846 )
847 if (declaration) return declaration
848 const propertyAccess = nodes.find(node =>
849 syntax.isPropertyAccessExpression(node)
850 )
851 if (propertyAccess) return propertyAccess
852 const assignment = nodes.find(
853 node =>
854 syntax.isBinaryExpression(node) &&
855 node.operatorToken.kind === syntax.SyntaxKind.EqualsToken
856 )
857 if (assignment) return assignment
858 const expression = nodes.find(
859 node => syntax.isExpressionStatement(node) || syntax.isExpression(node)
860 )
861 if (expression) return expression
862 return nodes.sort((a, b) => a.end - a.pos - (b.end - b.pos))[0]
863}
864
865const writeToCsv = (
866 filePath: string,

Callers 1

Calls 2

findMethod · 0.80
sortMethod · 0.80

Tested by

no test coverage detected