From 4389a396ac63d8068a7a2f288b98300e736a4dfb Mon Sep 17 00:00:00 2001 From: Teages Date: Wed, 7 May 2025 09:07:53 +0800 Subject: [PATCH 1/2] fix: avoid scientific notation in handling snippet --- src/utils/template.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/template.ts b/src/utils/template.ts index 33ad984..8a12b2a 100644 --- a/src/utils/template.ts +++ b/src/utils/template.ts @@ -341,6 +341,12 @@ function getKey(expression: Expression) { } } +function generateSnippetSplitter() { + const identify = Math.floor(Math.random() * 900_000_000) + 100_000_000 + + return `\nsplitter(${identify % 10 === 0 ? identify + 1 : identify});\n` +} + async function transformJsSnippets(expressions: Expression[], transform: (code: string) => Promise): Promise> { const transformMap = new Map() @@ -368,9 +374,7 @@ async function transformJsSnippets(expressions: Expression[], transform: (code: try { // transform all snippets in a single file - const batchInputSplitter = `\nsplitter(${ - Math.floor(Math.random() * 900_000_000) + 100_000_000 - });\n` + const batchInputSplitter = generateSnippetSplitter() const batchInput = batch .map(({ nodes, handler }) => handler.prepare(nodes[0], id)) .join(batchInputSplitter) From ebd6d5aab2212111f6285e0a20ffbb39e2613d4e Mon Sep 17 00:00:00 2001 From: Teages Date: Wed, 7 May 2025 23:33:23 +0800 Subject: [PATCH 2/2] fix: use random string as batch snippet splitter --- src/utils/template.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/utils/template.ts b/src/utils/template.ts index 8a12b2a..d6ba2ee 100644 --- a/src/utils/template.ts +++ b/src/utils/template.ts @@ -342,9 +342,8 @@ function getKey(expression: Expression) { } function generateSnippetSplitter() { - const identify = Math.floor(Math.random() * 900_000_000) + 100_000_000 - - return `\nsplitter(${identify % 10 === 0 ? identify + 1 : identify});\n` + const identify = Math.random().toString(36).substring(2, 15) + return `\nsplitter(${JSON.stringify(identify)});\n` } async function transformJsSnippets(expressions: Expression[], transform: (code: string) => Promise): Promise> {