mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(web): share indexed module match rows (#17330)
This commit is contained in:
@@ -284,6 +284,16 @@ const matchLinear = (
|
||||
return candidates;
|
||||
};
|
||||
|
||||
const indexedCandidate = (
|
||||
scripts: readonly ExportedWebScript[],
|
||||
script_index: number,
|
||||
match: CapturedModuleCandidate["match"],
|
||||
): CapturedModuleCandidate => ({
|
||||
script_index,
|
||||
match,
|
||||
script: scripts[script_index]!,
|
||||
});
|
||||
|
||||
const matchIndexed = (
|
||||
url: string,
|
||||
scripts: readonly ExportedWebScript[],
|
||||
@@ -298,17 +308,13 @@ const matchIndexed = (
|
||||
}
|
||||
if (exactIndices === undefined && responseIndices === undefined) return [];
|
||||
if (responseIndices === undefined)
|
||||
return exactIndices!.map((script_index) => ({
|
||||
script_index,
|
||||
match: "exact-reported-url",
|
||||
script: scripts[script_index]!,
|
||||
}));
|
||||
return exactIndices!.map((script_index) =>
|
||||
indexedCandidate(scripts, script_index, "exact-reported-url"),
|
||||
);
|
||||
if (exactIndices === undefined)
|
||||
return responseIndices.map((script_index) => ({
|
||||
script_index,
|
||||
match: "response-url-without-fragment",
|
||||
script: scripts[script_index]!,
|
||||
}));
|
||||
return responseIndices.map((script_index) =>
|
||||
indexedCandidate(scripts, script_index, "response-url-without-fragment"),
|
||||
);
|
||||
const candidates: CapturedModuleCandidate[] = [];
|
||||
let ei = 0;
|
||||
let ri = 0;
|
||||
@@ -316,36 +322,26 @@ const matchIndexed = (
|
||||
const eIdx = exactIndices[ei]!;
|
||||
const rIdx = responseIndices[ri]!;
|
||||
if (eIdx < rIdx) {
|
||||
candidates.push({
|
||||
script_index: eIdx,
|
||||
match: "exact-reported-url",
|
||||
script: scripts[eIdx]!,
|
||||
});
|
||||
candidates.push(indexedCandidate(scripts, eIdx, "exact-reported-url"));
|
||||
ei += 1;
|
||||
} else {
|
||||
candidates.push({
|
||||
script_index: rIdx,
|
||||
match: "response-url-without-fragment",
|
||||
script: scripts[rIdx]!,
|
||||
});
|
||||
candidates.push(
|
||||
indexedCandidate(scripts, rIdx, "response-url-without-fragment"),
|
||||
);
|
||||
ri += 1;
|
||||
}
|
||||
}
|
||||
while (ei < exactIndices.length) {
|
||||
const script_index = exactIndices[ei++]!;
|
||||
candidates.push({
|
||||
script_index,
|
||||
match: "exact-reported-url",
|
||||
script: scripts[script_index]!,
|
||||
});
|
||||
candidates.push(
|
||||
indexedCandidate(scripts, script_index, "exact-reported-url"),
|
||||
);
|
||||
}
|
||||
while (ri < responseIndices.length) {
|
||||
const script_index = responseIndices[ri++]!;
|
||||
candidates.push({
|
||||
script_index,
|
||||
match: "response-url-without-fragment",
|
||||
script: scripts[script_index]!,
|
||||
});
|
||||
candidates.push(
|
||||
indexedCandidate(scripts, script_index, "response-url-without-fragment"),
|
||||
);
|
||||
}
|
||||
return candidates;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user