fix(compiler-core): fix self-closing tags with v-pre
This commit is contained in:
parent
7e75b4105a
commit
a21ca3dccc
@ -1644,6 +1644,54 @@ describe('compiler: parse', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('self-closing v-pre', () => {
|
||||||
|
const ast = baseParse(
|
||||||
|
`<div v-pre/>\n<div :id="foo"><Comp/>{{ bar }}</div>`
|
||||||
|
)
|
||||||
|
// should not affect siblings after it
|
||||||
|
const divWithoutPre = ast.children[1] as ElementNode
|
||||||
|
expect(divWithoutPre.props).toMatchObject([
|
||||||
|
{
|
||||||
|
type: NodeTypes.DIRECTIVE,
|
||||||
|
name: `bind`,
|
||||||
|
arg: {
|
||||||
|
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||||
|
isStatic: true,
|
||||||
|
content: `id`
|
||||||
|
},
|
||||||
|
exp: {
|
||||||
|
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||||
|
isStatic: false,
|
||||||
|
content: `foo`
|
||||||
|
},
|
||||||
|
loc: {
|
||||||
|
source: `:id="foo"`,
|
||||||
|
start: {
|
||||||
|
line: 2,
|
||||||
|
column: 6
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
line: 2,
|
||||||
|
column: 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
expect(divWithoutPre.children[0]).toMatchObject({
|
||||||
|
type: NodeTypes.ELEMENT,
|
||||||
|
tagType: ElementTypes.COMPONENT,
|
||||||
|
tag: `Comp`
|
||||||
|
})
|
||||||
|
expect(divWithoutPre.children[1]).toMatchObject({
|
||||||
|
type: NodeTypes.INTERPOLATION,
|
||||||
|
content: {
|
||||||
|
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||||
|
content: `bar`,
|
||||||
|
isStatic: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('end tags are case-insensitive.', () => {
|
test('end tags are case-insensitive.', () => {
|
||||||
const ast = baseParse('<div>hello</DIV>after')
|
const ast = baseParse('<div>hello</DIV>after')
|
||||||
const element = ast.children[0] as ElementNode
|
const element = ast.children[0] as ElementNode
|
||||||
@ -1884,6 +1932,15 @@ foo
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('self-closing pre tag', () => {
|
||||||
|
const ast = baseParse(`<pre/><span>\n foo bar</span>`, {
|
||||||
|
isPreTag: tag => tag === 'pre'
|
||||||
|
})
|
||||||
|
const elementAfterPre = ast.children[1] as ElementNode
|
||||||
|
// should not affect the <span> and condense its whitepsace inside
|
||||||
|
expect((elementAfterPre.children[0] as TextNode).content).toBe(` foo bar`)
|
||||||
|
})
|
||||||
|
|
||||||
it('should NOT condense whitespaces in RCDATA text mode', () => {
|
it('should NOT condense whitespaces in RCDATA text mode', () => {
|
||||||
const ast = baseParse(`<textarea>Text:\n foo</textarea>`, {
|
const ast = baseParse(`<textarea>Text:\n foo</textarea>`, {
|
||||||
getTextMode: ({ tag }) =>
|
getTextMode: ({ tag }) =>
|
||||||
|
@ -430,6 +430,9 @@ function parseElement(
|
|||||||
if (isPreBoundary) {
|
if (isPreBoundary) {
|
||||||
context.inPre = false
|
context.inPre = false
|
||||||
}
|
}
|
||||||
|
if (isVPreBoundary) {
|
||||||
|
context.inVPre = false
|
||||||
|
}
|
||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user