File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,28 @@ h1 { color: red }
167
167
expect ( descriptor . script ! . attrs [ 'src' ] ) . toBe ( 'com' )
168
168
} )
169
169
170
+ test ( 'ignoreEmpty: false' , ( ) => {
171
+ const { descriptor } = parse (
172
+ `<script></script>\n<script setup>\n</script>` ,
173
+ {
174
+ ignoreEmpty : false
175
+ }
176
+ )
177
+ expect ( descriptor . script ) . toBeTruthy ( )
178
+ expect ( descriptor . script ! . loc ) . toMatchObject ( {
179
+ source : '' ,
180
+ start : { line : 1 , column : 9 , offset : 8 } ,
181
+ end : { line : 1 , column : 9 , offset : 8 }
182
+ } )
183
+
184
+ expect ( descriptor . scriptSetup ) . toBeTruthy ( )
185
+ expect ( descriptor . scriptSetup ! . loc ) . toMatchObject ( {
186
+ source : '\n' ,
187
+ start : { line : 2 , column : 15 , offset : 32 } ,
188
+ end : { line : 3 , column : 1 , offset : 33 }
189
+ } )
190
+ } )
191
+
170
192
test ( 'nested templates' , ( ) => {
171
193
const content = `
172
194
<template v-if="ok">ok</template>
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export interface SFCParseOptions {
18
18
sourceMap ?: boolean
19
19
sourceRoot ?: string
20
20
pad ?: boolean | 'line' | 'space'
21
+ ignoreEmpty ?: boolean
21
22
compiler ?: TemplateCompiler
22
23
}
23
24
@@ -104,6 +105,7 @@ export function parse(
104
105
filename = 'anonymous.vue' ,
105
106
sourceRoot = '' ,
106
107
pad = false ,
108
+ ignoreEmpty = true ,
107
109
compiler = CompilerDOM
108
110
} : SFCParseOptions = { }
109
111
) : SFCParseResult {
@@ -163,7 +165,12 @@ export function parse(
163
165
return
164
166
}
165
167
// we only want to keep the nodes that are not empty (when the tag is not a template)
166
- if ( node . tag !== 'template' && isEmpty ( node ) && ! hasSrc ( node ) ) {
168
+ if (
169
+ ignoreEmpty &&
170
+ node . tag !== 'template' &&
171
+ isEmpty ( node ) &&
172
+ ! hasSrc ( node )
173
+ ) {
167
174
return
168
175
}
169
176
switch ( node . tag ) {
You can’t perform that action at this time.
0 commit comments