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

Function findMostSpecificNodeInRange

ark/attest/cli/trace.ts:814–832  ·  view source on GitHub ↗
(
	file: ts.SourceFile,
	start: number,
	end: number
)

Source from the content-addressed store, hash-verified

812}
813
814const findMostSpecificNodeInRange = (
815 file: ts.SourceFile,
816 start: number,
817 end: number
818): ts.Node | undefined => {
819 const allNodes = getDescendants(file)
820 const nodesInRange = allNodes.filter(
821 node => node.pos >= start && node.end <= end
822 )
823 if (nodesInRange.length === 0) return undefined
824 const leafNodes = nodesInRange.filter(
825 node =>
826 !nodesInRange.some(
827 other =>
828 other !== node && other.pos >= node.pos && other.end <= node.end
829 )
830 )
831 return findNodeByPreference(leafNodes.length > 0 ? leafNodes : nodesInRange)
832}
833
834const findNodeByPreference = (nodes: ts.Node[]): ts.Node | undefined => {
835 if (nodes.length === 0) return undefined

Callers 1

processDurationEntryFunction · 0.85

Calls 3

getDescendantsFunction · 0.90
findNodeByPreferenceFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected