MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / getLocator

Function getLocator

benchmark/data.js:190–212  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

188 return toString.call(thing) === '[object Object]';
189}
190function getLocator(source) {
191 const originalLines = source.split('\n');
192 const lineOffsets = [];
193 for (let i = 0, pos = 0; i < originalLines.length; i++) {
194 lineOffsets.push(pos);
195 pos += originalLines[i].length + 1;
196 }
197 return function locate(index) {
198 let i = 0;
199 let j = lineOffsets.length;
200 while (i < j) {
201 const m = (i + j) >> 1;
202 if (index < lineOffsets[m]) {
203 j = m;
204 } else {
205 i = m + 1;
206 }
207 }
208 const line = i - 1;
209 const column = index - lineOffsets[line];
210 return { line, column };
211 };
212}
213class Mappings {
214 constructor(hires) {
215 this.hires = hires;

Callers 3

generateDecodedMapMethod · 0.70
_splitChunkMethod · 0.70
generateDecodedMapMethod · 0.70

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected