Skip to content

Commit 8a41b01

Browse files
committed
fix: handle complex slot
1 parent 83ae454 commit 8a41b01

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/utils/parseTemplate.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ export function parseTemplate (id: string, descriptor: SFCDescriptor) {
1818

1919
const findSlots = (nodes: any[]) => {
2020
if (!nodes.length) { return [] }
21-
const slots = nodes.filter(n => n.tag === 'slot').map(s => ({
22-
name: JSON.parse(s.codegenNode.arguments[1])
23-
}))
21+
const slots = nodes.filter(n => n.tag === 'slot').map((s) => {
22+
const name = s.codegenNode.arguments[1]
23+
if (typeof name === 'string') {
24+
return { name: name.replace(/['"`]/g, '') }
25+
}
26+
return {
27+
name: name?.loc?.source?.replace(/['"`]/g, '')
28+
}
29+
})
2430
return [
2531
...slots,
2632
...findSlots(nodes.flatMap(n => n.children || []))

0 commit comments

Comments
 (0)