encodeMappings
tcmts.core.program.encodeMappings · #5qcf736m · term · runs anywhere
import { B64 } from "#codebase/tcmts/core/program";
export function encodeMappings(lines: number[][][]): string {
const vlq = (n: number) => {
let v = n < 0 ? (-n << 1) | 1 : n << 1;
let out = "";
do {
let d = v & 31;
v >>>= 5;
if (v) d |= 32;
out += B64[d];
} while (v);
return out;
};
const prev = [0, 0, 0, 0];
return lines
.map((segs) => {
prev[0] = 0;
return segs
.map((seg) => {
const out = seg.map((v, k) => vlq(v - prev[k]!)).join("");
seg.forEach((v, k) => (prev[k] = v));
return out;
})
.join(",");
})
.join(";");
}
uses
used by