Implement "node:module"'s findSourceMap and SourceMap class (#20863)

Co-authored-by: Claude <claude@anthropic.ai>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2025-07-07 23:08:12 -07:00
committed by GitHub
parent d4a52f77c7
commit 454316ffc3
22 changed files with 1089 additions and 105 deletions

View File

@@ -0,0 +1,28 @@
import { SourceMap } from "node:module";
import { readFileSync } from "node:fs";
import { bench, run } from "../runner.mjs";
const json = JSON.parse(readFileSync(process.argv.at(-1), "utf-8"));
bench("new SourceMap(json)", () => {
return new SourceMap(json);
});
const map = new SourceMap(json);
const toRotate = [];
for (let j = 0; j < 10000; j++) {
if (map.findEntry(0, j).generatedColumn) {
toRotate.push(j);
if (toRotate.length > 5) break;
}
}
let i = 0;
bench("findEntry (match)", () => {
return map.findEntry(0, toRotate[i++ % 3]).generatedColumn;
});
bench("findEntry (no match)", () => {
return map.findEntry(0, 9999).generatedColumn;
});
await run();