Fix Webpack modules that are not arrow funcs

This commit is contained in:
Vendicated 2022-11-01 14:27:13 +01:00
parent 1944f3957f
commit 64aed87de4
No known key found for this signature in database
GPG Key ID: EC781ADFB93EFFA3
2 changed files with 6 additions and 1 deletions

View File

@ -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]);

View File

@ -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();