expect(parse(`<custom/>`).descriptor.customBlocks.length).toBe(0)
})
+ test('handle empty nodes with src attribute', () => {
+ const { descriptor } = parse(`<script src="com"/>`)
+ expect(descriptor.script).toBeTruthy()
+ expect(descriptor.script!.content).toBeFalsy()
+ expect(descriptor.script!.attrs['src']).toBe('com')
+ })
+
test('nested templates', () => {
const content = `
<template v-if="ok">ok</template>
if (node.type !== NodeTypes.ELEMENT) {
return
}
- if (!node.children.length) {
+ if (!node.children.length && !hasSrc(node)) {
return
}
switch (node.tag) {
pad: SFCParseOptions['pad']
): SFCBlock {
const type = node.tag
- const start = node.children[0].loc.start
- const end = node.children[node.children.length - 1].loc.end
- const content = source.slice(start.offset, end.offset)
+ let { start, end } = node.loc
+ let content = ''
+ if (node.children.length) {
+ start = node.children[0].loc.start
+ end = node.children[node.children.length - 1].loc.end
+ content = source.slice(start.offset, end.offset)
+ }
const loc = {
source: content,
start,
return Array(offset).join(padChar)
}
}
+
+function hasSrc(node: ElementNode) {
+ return node.props.some(p => {
+ if (p.type !== NodeTypes.ATTRIBUTE) {
+ return false
+ }
+ return p.name === 'src'
+ })
+}