MCPcopy Index your code
hub / github.com/TanStack/devtools / createLocMapper

Function createLocMapper

packages/devtools-vite/src/offset-to-loc.ts:15–39  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

13 * Lookup: O(log n) binary search.
14 */
15export function createLocMapper(source: string): (offset: number) => Loc {
16 const lineStarts: Array<number> = [0]
17 for (let i = 0; i < source.length; i++) {
18 if (source.charCodeAt(i) === 10 /* \n */) {
19 lineStarts.push(i + 1)
20 }
21 }
22
23 return (offset: number): Loc => {
24 let lo = 0
25 let hi = lineStarts.length - 1
26 while (lo < hi) {
27 const mid = (lo + hi + 1) >> 1
28 if (lineStarts[mid]! <= offset) {
29 lo = mid
30 } else {
31 hi = mid - 1
32 }
33 }
34 return {
35 line: lo + 1,
36 column: offset - lineStarts[lo]!,
37 }
38 }
39}

Callers 3

addSourceToJsxFunction · 0.90
enhanceConsoleLogFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected