wip: compiler-sfc should not attach ast on template with src import

This commit is contained in:
Evan You 2023-11-21 22:09:38 +08:00
parent e41cf8dc59
commit 37f9d3da8f
3 changed files with 12 additions and 4 deletions

View File

@ -139,7 +139,7 @@ test('should work w/ AST from descriptor', () => {
sourceMap: true
}).descriptor.template!
expect(template.ast.source).toBe(source)
expect(template.ast!.source).toBe(source)
const { code, map } = compile({
filename: 'example.vue',

View File

@ -164,6 +164,11 @@ h1 { color: red }
expect(descriptor.script!.attrs['src']).toBe('com')
})
test('should not expose ast on template node if has src import', () => {
const { descriptor } = parse(`<template src="./foo.html"/>`)
expect(descriptor.template!.ast).toBeUndefined()
})
test('ignoreEmpty: false', () => {
const { descriptor } = parse(
`<script></script>\n<script setup>\n</script>`,
@ -211,7 +216,7 @@ h1 { color: red }
expect(errors.length).toBe(0)
expect(descriptor.template!.content).toBe(content)
// should not attempt to parse the content
expect(descriptor.template!.ast.children.length).toBe(1)
expect(descriptor.template!.ast!.children.length).toBe(1)
})
//#2566

View File

@ -38,7 +38,7 @@ export interface SFCBlock {
export interface SFCTemplateBlock extends SFCBlock {
type: 'template'
ast: RootNode
ast?: RootNode
}
export interface SFCScriptBlock extends SFCBlock {
@ -156,7 +156,10 @@ export function parse(
source,
false
) as SFCTemplateBlock)
templateBlock.ast = createRoot(node.children, source)
if (!templateBlock.attrs.src) {
templateBlock.ast = createRoot(node.children, source)
}
// warn against 2.x <template functional>
if (templateBlock.attrs.functional) {