Skip to content

Commit d4e283b

Browse files
committed
fix: use complex splitter for batch processing
1 parent e072e53 commit d4e283b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/utils/template.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ async function transformJsSnippets(codes: string[], transform: (code: string) =>
214214
}
215215

216216
// transform all snippets in a single file
217-
const batchInput = Array.from(keyMap.entries()).map(([wrapperName, raw]) => `${wrapperName}(${raw});`).join('\n')
217+
const batchInputSplitter = `\nsplitter(${Math.random()});\n`
218+
const batchInput = Array.from(keyMap.entries()).map(([wrapperName, raw]) => `${wrapperName}(${raw});`).join(batchInputSplitter)
218219

219220
try {
220221
const batchOutput = await transform(batchInput)
221222

222-
const lines = batchOutput.split('\n')
223-
const wrapperRegex = /^(wrapper_\d+)\((.*)\);$/
223+
const lines = batchOutput.trim().split(batchInputSplitter)
224+
const wrapperRegex = /^(wrapper_\d+)\(([\s\S]*?)\);$/
224225
for (const line of lines) {
225226
const [_, wrapperName, res] = line.match(wrapperRegex) ?? []
226227
if (!wrapperName || !res) {

test/template.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ describe('transform typescript template', () => {
4242
`<div @click="(e: unknown) => handleClick(e as MouseEvent)" />`,
4343
),
4444
).toEqual(`<div @click="(e) => handleClick(e)" />`)
45+
expect(
46+
await fixture(
47+
`<div @click="(e: unknown) => { handleClick(e as MouseEvent); ping() }" />`,
48+
),
49+
).toMatchInlineSnapshot(`
50+
"<div @click="(e) => {
51+
handleClick(e);
52+
ping();
53+
}" />"
54+
`)
4555
})
4656

4757
it('destructuring', async () => {

0 commit comments

Comments
 (0)