feat(compiler-sfc): add ignoreEmpty option for sfc parse method

This commit is contained in:
Evan You
2021-07-19 19:02:46 -04:00
parent ec6abe8d5e
commit 8dbecfcbb3
2 changed files with 30 additions and 1 deletions

View File

@@ -167,6 +167,28 @@ h1 { color: red }
expect(descriptor.script!.attrs['src']).toBe('com')
})
test('ignoreEmpty: false', () => {
const { descriptor } = parse(
`<script></script>\n<script setup>\n</script>`,
{
ignoreEmpty: false
}
)
expect(descriptor.script).toBeTruthy()
expect(descriptor.script!.loc).toMatchObject({
source: '',
start: { line: 1, column: 9, offset: 8 },
end: { line: 1, column: 9, offset: 8 }
})
expect(descriptor.scriptSetup).toBeTruthy()
expect(descriptor.scriptSetup!.loc).toMatchObject({
source: '\n',
start: { line: 2, column: 15, offset: 32 },
end: { line: 3, column: 1, offset: 33 }
})
})
test('nested templates', () => {
const content = `
<template v-if="ok">ok</template>