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 && ( {!!diff?.length && (
<Button className={Margins.marginTop20} onClick={() => { <Button className={Margins.marginTop20} onClick={() => {
try { try {
Function(patchedCode); Function(patchedCode.replace(/^function\(/, "function patchedModule("));
setCompileResult([true, "Compiled successfully"]); setCompileResult([true, "Compiled successfully"]);
} catch (err) { } catch (err) {
setCompileResult([false, (err as Error).message]); 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 // ever targets newer browsers, the minifier could potentially use this trick and
// cause issues. // cause issues.
let code: string = mod.toString().replaceAll("\n", ""); 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 originalMod = mod;
const patchedBy = new Set(); const patchedBy = new Set();