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 && (
|
{!!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]);
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user