fix(browser): ignore duplicate frame navigations and read block-form source map directives (#546)

This commit is contained in:
morluto authored and GitHub committed 2026-10-05 17:25:16 +08:00
1 parent 84e4361c09
commit 828395d510
6 files changed
+149 -4

No files matched your search

@@ -0,0 +1,42 @@
import { describe, expect, it } from "vitest";
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
const sourceMapUrls = (source: string): readonly string[] =>
analyzeJavaScriptStaticSource(source).source_map_urls.map(
({ declared_url: declaredUrl }) => declaredUrl,
);
describe("source map directives", () => {
it.each([
["line comment", "//# sourceMappingURL=app.js.map", "app.js.map"],
["legacy line comment", "//@ sourceMappingURL=app.js.map", "app.js.map"],
// Minifiers commonly emit the block form; it previously matched nothing.
["block comment", "/*# sourceMappingURL=app.js.map */", "app.js.map"],
[
"block comment after code",
"code();\n/*# sourceMappingURL=vendor.abc.map */",
"vendor.abc.map",
],
])("reads the %s form", (_label, source, expected) => {
expect(sourceMapUrls(source)).toEqual([expected]);
});
it("keeps the comment terminator out of the declared url", () => {
expect(sourceMapUrls("/*# sourceMappingURL=app.js.map */")).toEqual([
"app.js.map",
]);
});
it("retains every directive in a source", () => {
expect(
sourceMapUrls(
"//# sourceMappingURL=first.map\n/*# sourceMappingURL=second.map */",
),
).toEqual(["first.map", "second.map"]);
});
it("reports nothing when no directive is present", () => {
expect(sourceMapUrls("const value = 1;")).toEqual([]);
});
});