Skip to content

Commit e9ab6d5

Browse files
committed
fix(docgen): make sure v-slot templates are understood too
1 parent d5bb798 commit e9ab6d5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

packages/vue-inbrowser-compiler/src/__tests__/isCodevueSfc.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ describe('isCodeVueSfc', () => {
4444
it('should return false if there is templates in the moustache', () => {
4545
expect(
4646
isCodeVueSfc(`
47-
<div :class="isTrue?'firstC':'secondC'">
47+
<div>
4848
<template #icon>
4949
<img class="text-gray-500 w-4 h-4 mr-2" src="~@/assets/svg/info.svg">
5050
</template>
51+
</div>
52+
<div>
5153
<template slot="otherIcon">
5254
<img class="text-gray-500 w-4 h-4 mr-2" src="~@/assets/svg/info.svg">
5355
</template>
54-
{hello}
56+
<template v-slot:colonIcon>
57+
<img class="text-gray-500 w-4 h-4 mr-2" src="~@/assets/svg/info.svg">
58+
</template>
5559
</div>
5660
`)
5761
).toBeFalsy()
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1+
import { parseComponent } from 'vue-template-compiler'
2+
13
export default function isCodeVueSfc(code: string) {
2-
if (/\n\W*<script/.test(code)) {
3-
return true
4-
}
5-
const temp = /\n\W*<template(.*)>/.exec(code)
6-
if (temp) {
7-
return !/slot=".*"/.test(temp[1]) && !/#/.test(temp[1])
8-
}
9-
return false
4+
const parts = parseComponent(code)
5+
return !!parts.script || !!parts.template
106
}

0 commit comments

Comments
 (0)