File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
packages/vue-inbrowser-compiler/src Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -44,14 +44,18 @@ describe('isCodeVueSfc', () => {
44
44
it ( 'should return false if there is templates in the moustache' , ( ) => {
45
45
expect (
46
46
isCodeVueSfc ( `
47
- <div :class="isTrue?'firstC':'secondC'" >
47
+ <div>
48
48
<template #icon>
49
49
<img class="text-gray-500 w-4 h-4 mr-2" src="~@/assets/svg/info.svg">
50
50
</template>
51
+ </div>
52
+ <div>
51
53
<template slot="otherIcon">
52
54
<img class="text-gray-500 w-4 h-4 mr-2" src="~@/assets/svg/info.svg">
53
55
</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>
55
59
</div>
56
60
` )
57
61
) . toBeFalsy ( )
Original file line number Diff line number Diff line change
1
+ import { parseComponent } from 'vue-template-compiler'
2
+
1
3
export default function isCodeVueSfc ( code : string ) {
2
- if ( / \n \W * < s c r i p t / . test ( code ) ) {
3
- return true
4
- }
5
- const temp = / \n \W * < t e m p l a t e ( .* ) > / . exec ( code )
6
- if ( temp ) {
7
- return ! / s l o t = " .* " / . test ( temp [ 1 ] ) && ! / # / . test ( temp [ 1 ] )
8
- }
9
- return false
4
+ const parts = parseComponent ( code )
5
+ return ! ! parts . script || ! ! parts . template
10
6
}
You can’t perform that action at this time.
0 commit comments