MCPcopy Create free account
hub / github.com/btd/rollup-plugin-visualizer / referenceSizes

Function referenceSizes

test/sourcemap.test.ts:27–46  ·  view source on GitHub ↗
(code: string, rawMap: RawSourceMap)

Source from the content-addressed store, hash-verified

25// Independent oracle for the actual bundler output: walk code points, advance
26// columns in UTF-16, and count UTF-8 bytes using the public consumer lookup.
27const referenceSizes = (code: string, rawMap: RawSourceMap) =>
28 SourceMapConsumer.with(rawMap, null, (map) => {
29 const result: Record<string, number> = {};
30 let line = 1;
31 let column = 0;
32 for (const char of code) {
33 const { source } = map.originalPositionFor({ line, column });
34 if (source != null) {
35 const id = toReportId(path.resolve(dir, source));
36 result[id] = (result[id] ?? 0) + Buffer.byteLength(char);
37 }
38 if (char === "\n") {
39 line++;
40 column = 0;
41 } else {
42 column += char.length;
43 }
44 }
45 return result;
46 });
47
48const files: Record<string, string> = {
49 "/src/index.js":

Callers 1

sourcemap.test.tsFile · 0.85

Calls 1

toReportIdFunction · 0.85

Tested by

no test coverage detected