Skip to content

Commit b9c96d3

Browse files
authored
fix: use random string as batch snippet splitter (#46)
1 parent 4543bf2 commit b9c96d3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/utils/template.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ function getKey(expression: Expression) {
341341
}
342342
}
343343

344+
function generateSnippetSplitter() {
345+
const identify = Math.random().toString(36).substring(2, 15)
346+
return `\nsplitter(${JSON.stringify(identify)});\n`
347+
}
348+
344349
async function transformJsSnippets(expressions: Expression[], transform: (code: string) => Promise<string>): Promise<WeakMap<Expression, string>> {
345350
const transformMap = new Map<string, { id: number, nodes: [Expression, ...Expression[]], handler: SnippetHandler }>()
346351

@@ -368,9 +373,7 @@ async function transformJsSnippets(expressions: Expression[], transform: (code:
368373

369374
try {
370375
// transform all snippets in a single file
371-
const batchInputSplitter = `\nsplitter(${
372-
Math.floor(Math.random() * 900_000_000) + 100_000_000
373-
});\n`
376+
const batchInputSplitter = generateSnippetSplitter()
374377
const batchInput = batch
375378
.map(({ nodes, handler }) => handler.prepare(nodes[0], id))
376379
.join(batchInputSplitter)

0 commit comments

Comments
 (0)