From 406569e1d7931be9800e7a6809669ea68d4499fb Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:12:24 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20#1246=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/service/content/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/service/content/utils.ts b/src/app/service/content/utils.ts index dbfe0397a..8d73af6a0 100644 --- a/src/app/service/content/utils.ts +++ b/src/app/service/content/utils.ts @@ -86,7 +86,7 @@ export function compileScriptCode(scriptRes: ScriptRunResource, scriptCode?: str const addTryCatch = (code: string) => ` try { - {{functionBody}} + __FUNCTION_BODY__ } catch (e) { if (e.message && e.stack) { console.error("ERROR: Execution of script '" + arguments[1] + "' failed! " + e.message); @@ -99,7 +99,7 @@ const addTryCatch = (code: string) => .trim() .replace(/[\r\n]/g, "") .replace(/\s+/g, " ") - .replace("{{functionBody}}", code); + .replace(/\s+__FUNCTION_BODY__\s+/, `\n${code}\n`); export function compileScriptCodeByResource(resource: CompileScriptCodeResource): string { const requireCode = resource.require.map((r) => r.content).join("\n;"); From 0ea9a057ac415b31d43ee7b0d8a9f572994f2d2d Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:16:04 +0900 Subject: [PATCH 2/5] . --- src/app/service/content/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/service/content/utils.ts b/src/app/service/content/utils.ts index 8d73af6a0..cb46aaf80 100644 --- a/src/app/service/content/utils.ts +++ b/src/app/service/content/utils.ts @@ -99,7 +99,7 @@ const addTryCatch = (code: string) => .trim() .replace(/[\r\n]/g, "") .replace(/\s+/g, " ") - .replace(/\s+__FUNCTION_BODY__\s+/, `\n${code}\n`); + .replace(/\s*__FUNCTION_BODY__\s*/, `\n${code}\n`); export function compileScriptCodeByResource(resource: CompileScriptCodeResource): string { const requireCode = resource.require.map((r) => r.content).join("\n;"); From bfd0c42072fc9063017d14e7856e2cff245c8539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Sun, 15 Feb 2026 15:19:23 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=AE=A9replace=E4=B8=8D=E8=AF=86=E5=88=AB?= =?UTF-8?q?$?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/service/content/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/service/content/utils.ts b/src/app/service/content/utils.ts index cb46aaf80..c4f995d91 100644 --- a/src/app/service/content/utils.ts +++ b/src/app/service/content/utils.ts @@ -86,7 +86,7 @@ export function compileScriptCode(scriptRes: ScriptRunResource, scriptCode?: str const addTryCatch = (code: string) => ` try { - __FUNCTION_BODY__ + {{functionBody}} } catch (e) { if (e.message && e.stack) { console.error("ERROR: Execution of script '" + arguments[1] + "' failed! " + e.message); @@ -99,7 +99,7 @@ const addTryCatch = (code: string) => .trim() .replace(/[\r\n]/g, "") .replace(/\s+/g, " ") - .replace(/\s*__FUNCTION_BODY__\s*/, `\n${code}\n`); + .replace("{{functionBody}}", () => code); export function compileScriptCodeByResource(resource: CompileScriptCodeResource): string { const requireCode = resource.require.map((r) => r.content).join("\n;"); From 23706090f9cb19c1b1c0195707a8dbd12be140d6 Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:20:24 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E8=AE=A9replace=E4=B8=8D=E8=AF=86=E5=88=AB?= =?UTF-8?q?$?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/service/content/utils.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/service/content/utils.ts b/src/app/service/content/utils.ts index c4f995d91..e2a8dd2e3 100644 --- a/src/app/service/content/utils.ts +++ b/src/app/service/content/utils.ts @@ -83,10 +83,10 @@ export function compileScriptCode(scriptRes: ScriptRunResource, scriptCode?: str }); } -const addTryCatch = (code: string) => - ` +const addTryCatch = (code: string) => { + const templateText = ` try { - {{functionBody}} + __FUNCTION_BODY__ } catch (e) { if (e.message && e.stack) { console.error("ERROR: Execution of script '" + arguments[1] + "' failed! " + e.message); @@ -95,11 +95,15 @@ const addTryCatch = (code: string) => console.error(e); } } - ` + `; + const text = templateText .trim() .replace(/[\r\n]/g, "") - .replace(/\s+/g, " ") - .replace("{{functionBody}}", () => code); + .replace(/\s+/g, " "); + // 用 function replacer 让replace不识别$ + const output = text.replace(/\s*__FUNCTION_BODY__\s*/, () => "\n" + code + "\n"); + return output; +}; export function compileScriptCodeByResource(resource: CompileScriptCodeResource): string { const requireCode = resource.require.map((r) => r.content).join("\n;"); From bf3c252b34247ed48d1b151f7c16fc748efab8c1 Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:32:19 +0900 Subject: [PATCH 5/5] =?UTF-8?q?Revert=20"=E8=AE=A9replace=E4=B8=8D?= =?UTF-8?q?=E8=AF=86=E5=88=AB$"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 23706090f9cb19c1b1c0195707a8dbd12be140d6. --- src/app/service/content/utils.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/app/service/content/utils.ts b/src/app/service/content/utils.ts index e2a8dd2e3..c4f995d91 100644 --- a/src/app/service/content/utils.ts +++ b/src/app/service/content/utils.ts @@ -83,10 +83,10 @@ export function compileScriptCode(scriptRes: ScriptRunResource, scriptCode?: str }); } -const addTryCatch = (code: string) => { - const templateText = ` +const addTryCatch = (code: string) => + ` try { - __FUNCTION_BODY__ + {{functionBody}} } catch (e) { if (e.message && e.stack) { console.error("ERROR: Execution of script '" + arguments[1] + "' failed! " + e.message); @@ -95,15 +95,11 @@ const addTryCatch = (code: string) => { console.error(e); } } - `; - const text = templateText + ` .trim() .replace(/[\r\n]/g, "") - .replace(/\s+/g, " "); - // 用 function replacer 让replace不识别$ - const output = text.replace(/\s*__FUNCTION_BODY__\s*/, () => "\n" + code + "\n"); - return output; -}; + .replace(/\s+/g, " ") + .replace("{{functionBody}}", () => code); export function compileScriptCodeByResource(resource: CompileScriptCodeResource): string { const requireCode = resource.require.map((r) => r.content).join("\n;");