Skip to content

Commit 0b28190

Browse files
danielroeTeages
andauthored
fix: regex error on v-slot snippet handler (#14)
Co-authored-by: Teages <[email protected]>
1 parent 834cf4f commit 0b28190

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/utils/template.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ const vSlotSnippetHandler: SnippetHandler = {
259259
},
260260
prepare: (node, id) => `const ${node.src} = wrapper_${id}();`,
261261
parse: (code) => {
262-
const regex = /^(const\s+)(\w+)\s*=\s*wrapper_\d+\(\);$/
262+
const regex = /^const([\s\S]*?)=\s+wrapper_\d+\(\);$/
263263
const [_, res] = code.match(regex) ?? []
264264
if (!res) {
265265
return undefined
266266
}
267-
return res
267+
return res.trim()
268268
},
269269
}
270270

test/template.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ describe('transform typescript template', () => {
142142
)
143143
})
144144

145+
it('equals', async () => {
146+
expect(
147+
await fixture(`<MyComponent #template="{ item, index, level = 0 as 0 | 1 }" />`),
148+
).toMatchInlineSnapshot(`"<MyComponent #template="{ item, index, level = 0 }" />"`)
149+
})
150+
145151
async function fixture(src: string) {
146152
const requireFromVue = createRequire(resolveModulePath('vue'))
147153
const { parse } = requireFromVue('@vue/compiler-dom') as typeof import('@vue/compiler-dom')

0 commit comments

Comments
 (0)