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

Function getTextPosition

ark/attest/cli/trace.ts:82–90  ·  view source on GitHub ↗
(path: string, position: number)

Source from the content-addressed store, hash-verified

80
81// tsgo's trace positions are UTF-8 byte offsets rather than UTF-16 indices
82const getTextPosition = (path: string, position: number): number => {
83 if (!isTs7) return position
84 const text = getSourceFile(path).getFullText()
85 let utf8 = utf8ByPath.get(path)
86 if (!utf8) utf8ByPath.set(path, (utf8 = Buffer.from(text)))
87 return utf8.length === text.length ?
88 position
89 : utf8.subarray(0, position).toString().length
90}
91
92const getDescendants = (node: ts.Node): ts.Node[] =>
93 isTs7 ? (getDescendantsTs7(node as never) as never) : getDescendantsTs5(node)

Callers 1

processDurationEntryFunction · 0.85

Calls 5

getSourceFileFunction · 0.85
getMethod · 0.65
fromMethod · 0.65
toStringMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected