From ab96130f2277fa8a8571fb4bb4f210b6902acd5b Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Tue, 24 Nov 2026 19:29:42 +0800 Subject: [PATCH] refactor(web): remove the superseded single-query module matcher (#14319) --- src/domain/webModuleImports.test.ts | 25 +++++++------------------ src/domain/webModuleImports.ts | 7 ------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/domain/webModuleImports.test.ts b/src/domain/webModuleImports.test.ts index a78eaec285e..fce56bd4557 100644 --- a/src/domain/webModuleImports.test.ts +++ b/src/domain/webModuleImports.test.ts @@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest"; import { collectWebModuleImports, createCapturedModuleMatcher, - matchCapturedModules, } from "./webModuleImports.js"; import { exportedWebScriptSchema } from "./webScriptExport.js"; @@ -169,11 +168,12 @@ describe("captured module candidates", () => { script(url, "scenario-response", "b".repeat(64)), script("https://app.test/a.js?v=2", "scenario-response"), ]; - expect(matchCapturedModules(url, scripts)).toEqual([ + const match = createCapturedModuleMatcher(scripts); + expect(match(url)).toEqual([ { script_index: 2, match: "exact-reported-url", script: scripts[2] }, { script_index: 3, match: "exact-reported-url", script: scripts[3] }, ]); - expect(matchCapturedModules(`${url}#one`, scripts)).toEqual([ + expect(match(`${url}#one`)).toEqual([ { script_index: 0, match: "exact-reported-url", script: scripts[0] }, { script_index: 2, @@ -186,9 +186,7 @@ describe("captured module candidates", () => { script: scripts[3], }, ]); - expect(matchCapturedModules("https://app.test/lazy.js", scripts)).toEqual( - [], - ); + expect(match("https://app.test/lazy.js")).toEqual([]); }); it("retains exact non-URL identities without matching response fragments", () => { const scripts = [ @@ -196,8 +194,9 @@ describe("captured module candidates", () => { script("relative/module.js#part", "scenario-response"), script("relative/module.js", "scenario-response"), ]; + const match = createCapturedModuleMatcher(scripts); expect( - matchCapturedModules("relative/module.js#part", scripts).map((item) => [ + match("relative/module.js#part").map((item) => [ item.script_index, item.match, ]), @@ -340,17 +339,7 @@ describe("keyword-indexed traversal and indexed candidate matching", () => { script: scripts[2], }, ]; - expect(matchCapturedModules("https://app.test/a.js#one", scripts)).toEqual( - expected, - ); - expect( - matchCapturedModules( - "https://app.test/a.js#one", - Object.freeze([...scripts]), - ), - ).toEqual(expected); - - const matcher = createCapturedModuleMatcher(scripts); + const matcher = createCapturedModuleMatcher(Object.freeze(scripts)); // 1st call (linear) and 2nd+ calls (indexed) must return identical order. expect(matcher("https://app.test/a.js#one")).toEqual(expected); expect(matcher("https://app.test/a.js#one")).toEqual(expected); diff --git a/src/domain/webModuleImports.ts b/src/domain/webModuleImports.ts index 080366fae0c..9385d149f43 100644 --- a/src/domain/webModuleImports.ts +++ b/src/domain/webModuleImports.ts @@ -382,10 +382,3 @@ export const createCapturedModuleMatcher = ( return matchIndexed(url, scripts, index); }; }; - -/** Match reported URLs without collapsing query or module fragment identity. */ -export const matchCapturedModules = ( - url: string, - scripts: readonly ExportedWebScript[], -): CapturedModuleCandidate[] => - scripts.length === 0 ? [] : matchLinear(url, scripts);