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

Function getBytesPerFileUsingSourceMap

plugin/sourcemap.ts:12–45  ·  view source on GitHub ↗
(
  bundleId: string,
  code: string,
  map: SourceMapConsumer,
  dir: string,
)

Source from the content-addressed store, hash-verified

10}
11
12const getBytesPerFileUsingSourceMap = (
13 bundleId: string,
14 code: string,
15 map: SourceMapConsumer,
16 dir: string,
17) => {
18 const modules: Record<string, SourceMapModuleRenderInfo> = {};
19
20 let line = 1;
21 let column = 0;
22 const codeChars = [...code];
23 for (let i = 0; i < codeChars.length; i++, column++) {
24 const { source } = map.originalPositionFor({
25 line,
26 column,
27 });
28 if (source != null) {
29 const id = path.resolve(path.dirname(path.join(dir, bundleId)), source);
30
31 const char = codeChars[i];
32
33 modules[id] = modules[id] || { id, renderedLength: 0, code: [] };
34 modules[id].renderedLength += Buffer.byteLength(char);
35 modules[id].code.push(char);
36 }
37
38 if (code[i] === "\n") {
39 line += 1;
40 column = -1;
41 }
42 }
43
44 return modules;
45};
46
47export const getSourcemapModules = (
48 id: string,

Callers 1

getSourcemapModulesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected