aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/PatchHelper.tsx2
-rw-r--r--src/webpack/patchWebpack.ts5
2 files changed, 6 insertions, 1 deletions
diff --git a/src/components/PatchHelper.tsx b/src/components/PatchHelper.tsx
index b490051..853febc 100644
--- a/src/components/PatchHelper.tsx
+++ b/src/components/PatchHelper.tsx
@@ -119,7 +119,7 @@ function ReplacementComponent({ module, match, replacement, setReplacementError
{!!diff?.length && (
<Button className={Margins.marginTop20} onClick={() => {
try {
- Function(patchedCode);
+ Function(patchedCode.replace(/^function\(/, "function patchedModule("));
setCompileResult([true, "Compiled successfully"]);
} catch (err) {
setCompileResult([false, (err as Error).message]);
diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts
index b3cfd70..fa6767c 100644
--- a/src/webpack/patchWebpack.ts
+++ b/src/webpack/patchWebpack.ts
@@ -57,6 +57,11 @@ function patchPush() {
// ever targets newer browsers, the minifier could potentially use this trick and
// cause issues.
let code: string = mod.toString().replaceAll("\n", "");
+ // a very small minority of modules use function() instead of arrow functions,
+ // but, unnamed toplevel functions aren't valid. Thus, give those a name
+ if (code.startsWith("function(")) {
+ code = "function patchedModule" + code.slice("function".length);
+ }
const originalMod = mod;
const patchedBy = new Set();