From 9cada9ad137b3b4953dfe32f12c0ced791feb850 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 18 Aug 2024 00:47:16 -0300 Subject: [PATCH] fix(Webpack): Not canonicalizing regex in some places --- src/webpack/webpack.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index fcd4adb8..19519d64 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -38,15 +38,15 @@ export let cache: WebpackInstance["c"]; export type FilterFn = (mod: any) => boolean; -type PropsFilter = Array; -type CodeFilter = Array; -type StoreNameFilter = string; +export type PropsFilter = Array; +export type CodeFilter = Array; +export type StoreNameFilter = string; -const stringMatches = (s: string, filter: CodeFilter) => +export const stringMatches = (s: string, filter: CodeFilter) => filter.every(f => typeof f === "string" ? s.includes(f) - : f.test(s) + : (f.global && (f.lastIndex = 0), f.test(s)) ); export const filters = { @@ -258,6 +258,8 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns * @returns string or null */ export const findModuleId = traceFunction("findModuleId", function findModuleId(...code: CodeFilter) { + code = code.map(canonicalizeMatch); + for (const id in wreq.m) { if (stringMatches(wreq.m[id].toString(), code)) return id; } @@ -452,12 +454,9 @@ export function findExportedComponentLazy(...props: Prop * }) */ export const mapMangledModule = traceFunction("mapMangledModule", function mapMangledModule(code: string | RegExp | CodeFilter, mappers: Record): Record { - if (!Array.isArray(code)) code = [code]; - code = code.map(canonicalizeMatch); - const exports = {} as Record; - const id = findModuleId(...code); + const id = findModuleId(...Array.isArray(code) ? code : [code]); if (id === null) return exports; @@ -606,6 +605,8 @@ export function waitFor(filter: string | PropsFilter | FilterFn, callback: Callb * @returns Mapping of found modules */ export function search(...code: CodeFilter) { + code = code.map(canonicalizeMatch); + const results = {} as Record; const factories = wreq.m;