Fix Webpack modules that are not arrow funcs
This commit is contained in:
parent
1944f3957f
commit
64aed87de4
@ -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]);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user